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
e3045eda
Commit
e3045eda
authored
Jan 25, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add the 'local_step' variable
parent
0a563252
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
0 deletions
+44
-0
tensorpack/callbacks/summary.py
tensorpack/callbacks/summary.py
+44
-0
No files found.
tensorpack/callbacks/summary.py
0 → 100644
View file @
e3045eda
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: summary.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import
tensorflow
as
tf
import
re
from
..utils.naming
import
MOVING_SUMMARY_VARS_KEY
from
..tfutils.common
import
get_global_step_var
from
.base
import
Callback
__all__
=
[
'SummaryMovingAverage'
]
class
SummaryMovingAverage
(
Callback
):
""" Maintain the moving average of the tensors
in every step, and summarize them. Enabled by default.
"""
def
__init__
(
self
,
collection
=
MOVING_SUMMARY_VARS_KEY
,
decay
=
0.95
):
"""
Args:
collection(str): the collection of tensors to summarize. The
default would work with :func:`add_moving_summary`.
decay(float): the decay of the moving average.
"""
self
.
_collection
=
collection
self
.
_decay
=
decay
def
_setup_graph
(
self
):
tensors
=
set
(
tf
.
get_collection
(
self
.
_collection
))
# TODO will produce tower0/xxx. not elegant
with
tf
.
name_scope
(
None
):
averager
=
tf
.
train
.
ExponentialMovingAverage
(
self
.
_decay
,
num_updates
=
get_global_step_var
(),
name
=
'EMA'
)
avg_maintain_op
=
averager
.
apply
(
tensors
)
for
idx
,
c
in
enumerate
(
tensors
):
name
=
re
.
sub
(
'tower[p0-9]+/'
,
''
,
c
.
op
.
name
)
tf
.
summary
.
scalar
(
name
+
'-summary'
,
averager
.
average
(
c
))
self
.
ema_op
=
avg_maintain_op
def
_extra_fetches
(
self
):
return
[
self
.
ema_op
]
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