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
3ed43ab4
Commit
3ed43ab4
authored
Aug 30, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix use of InputDesc across graphs (fix #398)
parent
8591e253
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
9 deletions
+10
-9
docs/tutorial/callback.md
docs/tutorial/callback.md
+7
-5
tensorpack/graph_builder/model_desc.py
tensorpack/graph_builder/model_desc.py
+3
-4
No files found.
docs/tutorial/callback.md
View file @
3ed43ab4
...
...
@@ -15,10 +15,12 @@ There are several places where you might want to do something else:
*
After the training (e.g. send the model somewhere, send a message to your phone)
We found people traditionally tend to write the training loop together with these extra features.
This makes the loop lengthy, and the code for the same feature probably get separated.
This makes the loop lengthy, and the code for the same feature probably get separated (imagine a
feature which needs initialization in the beginning and then some actual work between iterations).
By writing callbacks to implement what to do at each place, tensorpack trainers
will call the callbacks at the proper time.
Therefore the
code
can be reused with one single line, as long as you are using tensorpack trainers.
Therefore the
se features
can be reused with one single line, as long as you are using tensorpack trainers.
For example, these are the callbacks I used when training a ResNet:
...
...
@@ -30,7 +32,7 @@ TrainConfig(
ModelSaver
(),
# backup the model with best validation error
MinSaver
(
'val-error-top1'
),
# run inference on another Dataflow every epoch, compute
top1/top5 classification error and save them in log
# run inference on another Dataflow every epoch, compute
classification error and log to monitors
InferenceRunner
(
dataset_val
,
[
ClassificationError
(
'wrong-top1'
,
'val-error-top1'
),
ClassificationError
(
'wrong-top5'
,
'val-error-top5'
)]),
...
...
@@ -50,11 +52,11 @@ TrainConfig(
InjectShell
(
shell
=
'ipython'
)
],
extra_callbacks
=
[
# these callbacks are enabled by default already
# maintain
and summarize moving average of some tensors
defined in the model (e.g. training loss, training error)
# maintain
those moving average summaries already
defined in the model (e.g. training loss, training error)
MovingAverageSummary
(),
# draw a nice progress bar
ProgressBar
(),
# run `tf.summary.merge_all` every epoch and
send results
to monitors
# run `tf.summary.merge_all` every epoch and
log
to monitors
MergeAllSummaries
(),
# run ops in GraphKeys.UPDATE_OPS collection along with training, if any
RunUpdateOps
(),
...
...
tensorpack/graph_builder/model_desc.py
View file @
3ed43ab4
...
...
@@ -25,8 +25,6 @@ class InputDesc(
input source.
"""
_cached_placeholder
=
None
def
__new__
(
cls
,
type
,
shape
,
name
):
"""
Args:
...
...
@@ -36,6 +34,7 @@ class InputDesc(
"""
shape
=
tuple
(
shape
)
# has to be tuple for self to be hashable
self
=
super
(
InputDesc
,
cls
)
.
__new__
(
cls
,
type
,
shape
,
name
)
self
.
_cached_placeholder
=
None
return
self
# TODO in serialization, skip _cached_placeholder
...
...
@@ -72,10 +71,10 @@ class InputDesc(
self
.
type
,
shape
=
self
.
shape
,
name
=
prefix
+
self
.
name
)
if
prefix
==
''
and
self
.
_cached_placeholder
is
None
:
self
.
_cached_placeholder
=
ret
self
.
_cached_placeholder
=
ret
# cached_placeholder only caches the prefix='' case
return
ret
@
memoized
# cannot memoize here, because InputDesc is hashed by its fields.
def
build_placeholder_reuse
(
self
):
"""
Build a tf.placeholder from the metadata, or return an old one.
...
...
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