Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
seminar-breakout
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
seminar-breakout
Commits
dcf55733
Commit
dcf55733
authored
Feb 05, 2016
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add image dump callback
parent
96255c9a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
4 deletions
+59
-4
tensorpack/callbacks/base.py
tensorpack/callbacks/base.py
+3
-0
tensorpack/callbacks/common.py
tensorpack/callbacks/common.py
+1
-1
tensorpack/callbacks/dump.py
tensorpack/callbacks/dump.py
+52
-0
tensorpack/callbacks/group.py
tensorpack/callbacks/group.py
+3
-3
No files found.
tensorpack/callbacks/base.py
View file @
dcf55733
...
@@ -32,6 +32,9 @@ class Callback(object):
...
@@ -32,6 +32,9 @@ class Callback(object):
"""
"""
def
after_train
(
self
):
def
after_train
(
self
):
self
.
_after_train
()
def
_after_train
(
self
):
"""
"""
Called after training
Called after training
"""
"""
...
...
tensorpack/callbacks/common.py
View file @
dcf55733
...
@@ -56,6 +56,6 @@ class SummaryWriter(Callback):
...
@@ -56,6 +56,6 @@ class SummaryWriter(Callback):
logger
.
info
(
'{}: {:.4f}'
.
format
(
val
.
tag
,
val
.
simple_value
))
logger
.
info
(
'{}: {:.4f}'
.
format
(
val
.
tag
,
val
.
simple_value
))
self
.
writer
.
add_summary
(
summary
,
get_global_step
())
self
.
writer
.
add_summary
(
summary
,
get_global_step
())
def
after_train
(
self
):
def
_
after_train
(
self
):
self
.
writer
.
close
()
self
.
writer
.
close
()
tensorpack/callbacks/dump.py
0 → 100644
View file @
dcf55733
#!/usr/bin/env python2
# -*- coding: UTF-8 -*-
# File: dump.py
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
from
.base
import
Callback
import
cv2
import
os
from
..utils
import
logger
__all__
=
[
'DumpParamAsImage'
]
class
DumpParamAsImage
(
Callback
):
def
__init__
(
self
,
var_name
,
prefix
=
None
,
map_func
=
None
,
scale
=
255
):
"""
map_func: map the value of the variable to an image or list of images, default to identity
images should have shape [h, w] or [h, w, c].
scale: a scaling parameter on pixels
"""
self
.
var_name
=
var_name
self
.
func
=
map_func
if
prefix
is
None
:
self
.
prefix
=
self
.
var_name
else
:
self
.
prefix
=
prefix
self
.
log_dir
=
logger
.
LOG_DIR
self
.
scale
=
scale
def
_before_train
(
self
):
self
.
var
=
self
.
graph
.
get_tensor_by_name
(
self
.
var_name
)
self
.
epoch_num
=
0
def
trigger_epoch
(
self
):
self
.
epoch_num
+=
1
val
=
self
.
sess
.
run
(
self
.
var
)
if
self
.
func
is
not
None
:
val
=
self
.
func
(
val
)
if
isinstance
(
val
,
list
):
for
idx
,
im
in
enumerate
(
val
):
assert
im
.
ndim
in
[
2
,
3
],
str
(
im
.
ndim
)
fname
=
os
.
path
.
join
(
self
.
log_dir
,
self
.
prefix
+
'-ep{}-{}.png'
.
format
(
self
.
epoch_num
,
idx
))
cv2
.
imwrite
(
fname
,
im
*
self
.
scale
)
else
:
im
=
val
assert
im
.
ndim
in
[
2
,
3
]
fname
=
os
.
path
.
join
(
self
.
log_dir
,
self
.
prefix
+
'-ep{}.png'
.
format
(
self
.
epoch_num
))
cv2
.
imwrite
(
fname
,
im
*
self
.
scale
)
tensorpack/callbacks/group.py
View file @
dcf55733
...
@@ -78,7 +78,7 @@ class TrainCallbacks(Callback):
...
@@ -78,7 +78,7 @@ class TrainCallbacks(Callback):
cb
.
before_train
()
cb
.
before_train
()
self
.
writer
=
tf
.
get_collection
(
SUMMARY_WRITER_COLLECTION_KEY
)[
0
]
self
.
writer
=
tf
.
get_collection
(
SUMMARY_WRITER_COLLECTION_KEY
)[
0
]
def
after_train
(
self
):
def
_
after_train
(
self
):
for
cb
in
self
.
cbs
:
for
cb
in
self
.
cbs
:
cb
.
after_train
()
cb
.
after_train
()
...
@@ -115,7 +115,7 @@ class TestCallbacks(Callback):
...
@@ -115,7 +115,7 @@ class TestCallbacks(Callback):
for
cb
in
self
.
cbs
:
for
cb
in
self
.
cbs
:
cb
.
before_train
()
cb
.
before_train
()
def
after_train
(
self
):
def
_
after_train
(
self
):
for
cb
in
self
.
cbs
:
for
cb
in
self
.
cbs
:
cb
.
after_train
()
cb
.
after_train
()
...
@@ -161,7 +161,7 @@ class Callbacks(Callback):
...
@@ -161,7 +161,7 @@ class Callbacks(Callback):
self
.
train
.
before_train
()
self
.
train
.
before_train
()
self
.
test
.
before_train
()
self
.
test
.
before_train
()
def
after_train
(
self
):
def
_
after_train
(
self
):
self
.
train
.
after_train
()
self
.
train
.
after_train
()
self
.
test
.
after_train
()
self
.
test
.
after_train
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment