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
b693fe25
Commit
b693fe25
authored
Apr 10, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow period in mergeallsummaries
parent
54dc36ba
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
6 deletions
+23
-6
tensorpack/callbacks/summary.py
tensorpack/callbacks/summary.py
+23
-6
No files found.
tensorpack/callbacks/summary.py
View file @
b693fe25
...
...
@@ -33,12 +33,18 @@ class MovingAverageSummary(Callback):
class
MergeAllSummaries_RunAlone
(
Callback
):
def
__init__
(
self
,
key
):
def
__init__
(
self
,
period
,
key
):
self
.
_period
=
period
self
.
_key
=
key
def
_setup_graph
(
self
):
self
.
summary_op
=
tf
.
summary
.
merge_all
(
self
.
_key
)
def
_trigger_step
(
self
):
if
self
.
_period
:
if
(
self
.
local_step
+
1
)
%
self
.
_period
==
0
:
self
.
_trigger
()
def
_trigger
(
self
):
if
self
.
summary_op
:
summary
=
self
.
summary_op
.
eval
()
...
...
@@ -46,7 +52,8 @@ class MergeAllSummaries_RunAlone(Callback):
class
MergeAllSummaries_RunWithOp
(
Callback
):
def
__init__
(
self
,
key
):
def
__init__
(
self
,
period
,
key
):
self
.
_period
=
period
self
.
_key
=
key
def
_setup_graph
(
self
):
...
...
@@ -57,8 +64,15 @@ class MergeAllSummaries_RunWithOp(Callback):
self
.
_fetches
=
None
self
.
_total
=
self
.
trainer
.
config
.
steps_per_epoch
def
_
before_run
(
self
,
ctx
):
def
_
need_run
(
self
):
if
self
.
local_step
==
self
.
_total
-
1
:
return
True
if
self
.
_period
>
0
and
(
self
.
local_step
+
1
)
%
self
.
_period
==
0
:
return
True
return
False
def
_before_run
(
self
,
ctx
):
if
self
.
_need_run
():
return
self
.
_fetches
return
None
...
...
@@ -69,11 +83,13 @@ class MergeAllSummaries_RunWithOp(Callback):
self
.
trainer
.
monitors
.
put_summary
(
summary
)
def
MergeAllSummaries
(
run_alone
=
False
,
key
=
tf
.
GraphKeys
.
SUMMARIES
):
def
MergeAllSummaries
(
period
=
0
,
run_alone
=
False
,
key
=
tf
.
GraphKeys
.
SUMMARIES
):
"""
Evaluate all summaries by `tf.summary.merge_all`, and write to logs.
Args:
period (int): by default the callback summarizes once every epoch.
This option (if not set to 0) makes it additionally summarize every ``period`` steps.
run_alone (bool): whether to evaluate the summaries alone.
If True, summaries will be evaluated after each epoch alone.
If False, summaries will be evaluated together with other
...
...
@@ -85,7 +101,8 @@ def MergeAllSummaries(run_alone=False, key=tf.GraphKeys.SUMMARIES):
Returns:
a Callback.
"""
period
=
int
(
period
)
if
run_alone
:
return
MergeAllSummaries_RunAlone
(
key
)
return
MergeAllSummaries_RunAlone
(
period
,
key
)
else
:
return
MergeAllSummaries_RunWithOp
(
key
)
return
MergeAllSummaries_RunWithOp
(
period
,
key
)
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