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
2bec1d62
Commit
2bec1d62
authored
Jan 15, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove Trainer._process_summary and use a general Trainer.add_summary
parent
6d67faf9
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
23 additions
and
19 deletions
+23
-19
examples/DeepQNetwork/common.py
examples/DeepQNetwork/common.py
+2
-2
examples/PennTreebank/PTB-LSTM.py
examples/PennTreebank/PTB-LSTM.py
+1
-1
tensorpack/RL/expreplay.py
tensorpack/RL/expreplay.py
+2
-2
tensorpack/callbacks/inference_runner.py
tensorpack/callbacks/inference_runner.py
+1
-1
tensorpack/tfutils/summary.py
tensorpack/tfutils/summary.py
+2
-2
tensorpack/train/base.py
tensorpack/train/base.py
+12
-8
tensorpack/train/feedfree.py
tensorpack/train/feedfree.py
+1
-1
tensorpack/train/multigpu.py
tensorpack/train/multigpu.py
+1
-1
tensorpack/train/trainer.py
tensorpack/train/trainer.py
+1
-1
No files found.
examples/DeepQNetwork/common.py
View file @
2bec1d62
...
...
@@ -114,5 +114,5 @@ class Evaluator(Callback):
t
=
time
.
time
()
-
t
if
t
>
10
*
60
:
# eval takes too long
self
.
eval_episode
=
int
(
self
.
eval_episode
*
0.94
)
self
.
trainer
.
write
_scalar_summary
(
'mean_score'
,
mean
)
self
.
trainer
.
write
_scalar_summary
(
'max_score'
,
max
)
self
.
trainer
.
add
_scalar_summary
(
'mean_score'
,
mean
)
self
.
trainer
.
add
_scalar_summary
(
'max_score'
,
max
)
examples/PennTreebank/PTB-LSTM.py
View file @
2bec1d62
...
...
@@ -135,7 +135,7 @@ def get_config():
FeedfreeInferenceRunner
(
val_data
,
[
ScalarStats
([
'cost'
])]),
CallbackFactory
(
trigger_epoch
=
lambda
self
:
self
.
trainer
.
write
_scalar_summary
(
self
.
trainer
.
add
_scalar_summary
(
'validation_perplexity'
,
np
.
exp
(
self
.
trainer
.
stat_holder
.
get_stat_now
(
'validation_cost'
)
/
SEQ_LEN
))),
RunOp
(
lambda
:
M
.
reset_lstm_state
()),
...
...
tensorpack/RL/expreplay.py
View file @
2bec1d62
...
...
@@ -207,8 +207,8 @@ class ExpReplay(DataFlow, Callback):
for
k
,
v
in
six
.
iteritems
(
stats
):
try
:
mean
,
max
=
np
.
mean
(
v
),
np
.
max
(
v
)
self
.
trainer
.
write
_scalar_summary
(
'expreplay/mean_'
+
k
,
mean
)
self
.
trainer
.
write
_scalar_summary
(
'expreplay/max_'
+
k
,
max
)
self
.
trainer
.
add
_scalar_summary
(
'expreplay/mean_'
+
k
,
mean
)
self
.
trainer
.
add
_scalar_summary
(
'expreplay/max_'
+
k
,
max
)
except
:
pass
self
.
player
.
reset_stat
()
...
...
tensorpack/callbacks/inference_runner.py
View file @
2bec1d62
...
...
@@ -58,7 +58,7 @@ def summary_inferencer(trainer, infs):
except
:
logger
.
warn
(
"{} returns a non-scalar statistics!"
.
format
(
type
(
inf
)
.
__name__
))
continue
trainer
.
write
_scalar_summary
(
k
,
v
)
trainer
.
add
_scalar_summary
(
k
,
v
)
class
InferenceRunner
(
Callback
):
...
...
tensorpack/tfutils/summary.py
View file @
2bec1d62
...
...
@@ -13,11 +13,11 @@ from .tower import get_current_tower_context
from
.
import
get_global_step_var
from
.symbolic_functions
import
rms
__all__
=
[
'create_summary'
,
'add_param_summary'
,
'add_activation_summary'
,
__all__
=
[
'create_s
calar_s
ummary'
,
'add_param_summary'
,
'add_activation_summary'
,
'add_moving_summary'
,
'summary_moving_average'
]
def
create_summary
(
name
,
v
):
def
create_s
calar_s
ummary
(
name
,
v
):
"""
Returns:
tf.Summary: a tf.Summary object with name and simple scalar value v.
...
...
tensorpack/train/base.py
View file @
2bec1d62
...
...
@@ -16,7 +16,7 @@ from ..utils.timer import timed_operation
from
..callbacks
import
StatHolder
from
..tfutils
import
get_global_step
,
get_global_step_var
from
..tfutils.modelutils
import
describe_model
from
..tfutils.summary
import
create_summary
from
..tfutils.summary
import
create_s
calar_s
ummary
__all__
=
[
'Trainer'
,
'StopTraining'
]
...
...
@@ -96,8 +96,14 @@ class Trainer(object):
def
_trigger_epoch
(
self
):
pass
def
_process_summary
(
self
,
summary_str
):
summary
=
tf
.
Summary
.
FromString
(
summary_str
)
def
add_summary
(
self
,
summary
):
"""
Add summary to ``self.summary_writer``, and also
add scalar summary to ``self.stat_holder``.
Args:
summary (tf.Summary): a summary object.
"""
for
val
in
summary
.
value
:
if
val
.
WhichOneof
(
'value'
)
==
'simple_value'
:
val
.
tag
=
re
.
sub
(
'tower[p0-9]+/'
,
''
,
val
.
tag
)
# TODO move to subclasses
...
...
@@ -107,17 +113,15 @@ class Trainer(object):
self
.
stat_holder
.
add_stat
(
val
.
tag
,
val
.
simple_value
)
self
.
summary_writer
.
add_summary
(
summary
,
get_global_step
())
def
write
_scalar_summary
(
self
,
name
,
val
):
def
add
_scalar_summary
(
self
,
name
,
val
):
"""
Write
a scalar sumary to both TF events file and StatHolder.
Add
a scalar sumary to both TF events file and StatHolder.
Args:
name(str)
val(float)
"""
self
.
summary_writer
.
add_summary
(
create_summary
(
name
,
val
),
get_global_step
())
self
.
stat_holder
.
add_stat
(
name
,
val
)
self
.
add_summary
(
create_scalar_summary
(
name
,
val
))
def
setup
(
self
):
"""
...
...
tensorpack/train/feedfree.py
View file @
2bec1d62
...
...
@@ -29,7 +29,7 @@ class FeedfreeTrainerBase(Trainer):
# note that summary_op will take a data from the queue
if
self
.
summary_op
is
not
None
:
summary_str
=
self
.
summary_op
.
eval
()
self
.
_process_summary
(
summary_str
)
self
.
add_summary
(
tf
.
Summary
.
FromString
(
summary_str
)
)
def
_get_input_tensors
(
self
):
return
self
.
_input_method
.
get_input_tensors
()
...
...
tensorpack/train/multigpu.py
View file @
2bec1d62
...
...
@@ -209,7 +209,7 @@ class AsyncMultiGPUTrainer(MultiGPUTrainer,
if
self
.
config
.
tower
>
1
:
async_step_total_cnt
=
int
(
re
.
findall
(
'[0-9]+'
,
self
.
async_step_counter
.
__str__
())[
0
])
self
.
write
_scalar_summary
(
self
.
add
_scalar_summary
(
'async_global_step'
,
async_step_total_cnt
)
except
:
logger
.
exception
(
"Cannot log async_global_step"
)
...
...
tensorpack/train/trainer.py
View file @
2bec1d62
...
...
@@ -95,7 +95,7 @@ class SimpleTrainer(Trainer):
if
self
.
summary_op
is
not
None
:
feed
=
self
.
_input_method
.
next_feed
()
summary_str
=
self
.
summary_op
.
eval
(
feed_dict
=
feed
)
self
.
_process_summary
(
summary_str
)
self
.
add_summary
(
tf
.
Summary
.
FromString
(
summary_str
)
)
def
get_predict_func
(
self
,
input_names
,
output_names
):
return
self
.
_predictor_factory
.
get_predictor
(
input_names
,
output_names
,
0
)
...
...
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