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
bbf41d9e
Commit
bbf41d9e
authored
Jan 06, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use positional args instead of list for add_param_summary
parent
8f797c63
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
33 additions
and
23 deletions
+33
-23
examples/Atari2600/DQN.py
examples/Atari2600/DQN.py
+2
-2
examples/DoReFa-Net/alexnet-dorefa.py
examples/DoReFa-Net/alexnet-dorefa.py
+1
-1
examples/DoReFa-Net/svhn-digit-dorefa.py
examples/DoReFa-Net/svhn-digit-dorefa.py
+1
-1
examples/HED/hed.py
examples/HED/hed.py
+1
-1
examples/Inception/inception-bn.py
examples/Inception/inception-bn.py
+1
-1
examples/ResNet/cifar10-resnet.py
examples/ResNet/cifar10-resnet.py
+1
-1
examples/char-rnn/char-rnn.py
examples/char-rnn/char-rnn.py
+1
-1
examples/cifar-convnet.py
examples/cifar-convnet.py
+1
-1
examples/mnist-convnet.py
examples/mnist-convnet.py
+3
-3
examples/svhn-digit-convnet.py
examples/svhn-digit-convnet.py
+1
-1
tensorpack/tfutils/modelutils.py
tensorpack/tfutils/modelutils.py
+5
-3
tensorpack/tfutils/summary.py
tensorpack/tfutils/summary.py
+15
-7
No files found.
examples/Atari2600/DQN.py
View file @
bbf41d9e
...
...
@@ -134,8 +134,8 @@ class Model(ModelDesc):
self
.
cost
=
tf
.
truediv
(
symbf
.
huber_loss
(
target
-
pred_action_value
),
tf
.
cast
(
BATCH_SIZE
,
tf
.
float32
),
name
=
'cost'
)
summary
.
add_param_summary
(
[
(
'conv.*/W'
,
[
'histogram'
,
'rms'
]),
(
'fc.*/W'
,
[
'histogram'
,
'rms'
])]
)
# monitor all W
summary
.
add_param_summary
((
'conv.*/W'
,
[
'histogram'
,
'rms'
]),
(
'fc.*/W'
,
[
'histogram'
,
'rms'
])
)
# monitor all W
add_moving_summary
(
self
.
cost
)
def
update_target_param
(
self
):
...
...
examples/DoReFa-Net/alexnet-dorefa.py
View file @
bbf41d9e
...
...
@@ -157,7 +157,7 @@ class Model(ModelDesc):
# weight decay on all W of fc layers
wd_cost
=
regularize_cost
(
'fc.*/W'
,
l2_regularizer
(
5e-6
))
add_param_summary
(
[(
'.*/W'
,
[
'histogram'
,
'rms'
])]
)
add_param_summary
(
(
'.*/W'
,
[
'histogram'
,
'rms'
])
)
self
.
cost
=
tf
.
add_n
([
cost
,
wd_cost
],
name
=
'cost'
)
add_moving_summary
(
cost
,
wd_cost
,
self
.
cost
)
...
...
examples/DoReFa-Net/svhn-digit-dorefa.py
View file @
bbf41d9e
...
...
@@ -122,7 +122,7 @@ class Model(ModelDesc):
# weight decay on all W of fc layers
wd_cost
=
regularize_cost
(
'fc.*/W'
,
l2_regularizer
(
1e-7
))
add_param_summary
(
[(
'.*/W'
,
[
'histogram'
,
'rms'
])]
)
add_param_summary
(
(
'.*/W'
,
[
'histogram'
,
'rms'
])
)
self
.
cost
=
tf
.
add_n
([
cost
,
wd_cost
],
name
=
'cost'
)
add_moving_summary
(
cost
,
wd_cost
,
self
.
cost
)
...
...
examples/HED/hed.py
View file @
bbf41d9e
...
...
@@ -89,7 +89,7 @@ class Model(ModelDesc):
wd_cost
=
tf
.
mul
(
wd_w
,
regularize_cost
(
'.*/W'
,
tf
.
nn
.
l2_loss
),
name
=
'wd_cost'
)
costs
.
append
(
wd_cost
)
add_param_summary
(
[(
'.*/W'
,
[
'histogram'
])]
)
# monitor W
add_param_summary
(
(
'.*/W'
,
[
'histogram'
])
)
# monitor W
self
.
cost
=
tf
.
add_n
(
costs
,
name
=
'cost'
)
add_moving_summary
(
costs
+
[
wrong
,
self
.
cost
])
...
...
examples/Inception/inception-bn.py
View file @
bbf41d9e
...
...
@@ -115,7 +115,7 @@ class Model(ModelDesc):
80000
,
0.7
,
True
)
wd_cost
=
tf
.
mul
(
wd_w
,
regularize_cost
(
'.*/W'
,
tf
.
nn
.
l2_loss
),
name
=
'l2_regularize_loss'
)
add_param_summary
(
[(
'.*/W'
,
[
'histogram'
])]
)
# monitor W
add_param_summary
(
(
'.*/W'
,
[
'histogram'
])
)
# monitor W
self
.
cost
=
tf
.
add_n
([
cost
,
wd_cost
],
name
=
'cost'
)
add_moving_summary
(
wd_cost
,
self
.
cost
)
...
...
examples/ResNet/cifar10-resnet.py
View file @
bbf41d9e
...
...
@@ -103,7 +103,7 @@ class Model(ModelDesc):
wd_cost
=
tf
.
mul
(
wd_w
,
regularize_cost
(
'.*/W'
,
tf
.
nn
.
l2_loss
),
name
=
'wd_cost'
)
add_moving_summary
(
cost
,
wd_cost
)
add_param_summary
(
[(
'.*/W'
,
[
'histogram'
])]
)
# monitor W
add_param_summary
(
(
'.*/W'
,
[
'histogram'
])
)
# monitor W
self
.
cost
=
tf
.
add_n
([
cost
,
wd_cost
],
name
=
'cost'
)
...
...
examples/char-rnn/char-rnn.py
View file @
bbf41d9e
...
...
@@ -91,7 +91,7 @@ class Model(ModelDesc):
xent_loss
=
tf
.
nn
.
sparse_softmax_cross_entropy_with_logits
(
logits
,
symbolic_functions
.
flatten
(
nextinput
))
self
.
cost
=
tf
.
reduce_mean
(
xent_loss
,
name
=
'cost'
)
summary
.
add_param_summary
(
[(
'.*/W'
,
[
'histogram'
])]
)
# monitor histogram of all W
summary
.
add_param_summary
(
(
'.*/W'
,
[
'histogram'
])
)
# monitor histogram of all W
summary
.
add_moving_summary
(
self
.
cost
)
def
get_gradient_processor
(
self
):
...
...
examples/cifar-convnet.py
View file @
bbf41d9e
...
...
@@ -71,7 +71,7 @@ class Model(ModelDesc):
name
=
'regularize_loss'
)
add_moving_summary
(
cost
,
wd_cost
)
add_param_summary
(
[(
'.*/W'
,
[
'histogram'
])]
)
# monitor W
add_param_summary
(
(
'.*/W'
,
[
'histogram'
])
)
# monitor W
self
.
cost
=
tf
.
add_n
([
cost
,
wd_cost
],
name
=
'cost'
)
...
...
examples/mnist-convnet.py
View file @
bbf41d9e
...
...
@@ -107,9 +107,9 @@ class Model(ModelDesc):
summary
.
add_moving_summary
(
cost
)
# monitor histogram of all weight (of conv and fc layers) in tensorboard
summary
.
add_param_summary
(
[
(
'.*/W'
,
[
'histogram'
,
'rms'
]),
(
'.*/weights'
,
[
'histogram'
,
'rms'
])
# to also work with slim
]
)
summary
.
add_param_summary
((
'.*/W'
,
[
'histogram'
,
'rms'
]),
(
'.*/weights'
,
[
'histogram'
,
'rms'
])
# to also work with slim
)
def
get_data
():
...
...
examples/svhn-digit-convnet.py
View file @
bbf41d9e
...
...
@@ -57,7 +57,7 @@ class Model(ModelDesc):
wd_cost
=
regularize_cost
(
'fc.*/W'
,
l2_regularizer
(
0.00001
))
add_moving_summary
(
cost
,
wd_cost
)
add_param_summary
(
[(
'.*/W'
,
[
'histogram'
,
'rms'
])]
)
# monitor W
add_param_summary
(
(
'.*/W'
,
[
'histogram'
,
'rms'
])
)
# monitor W
self
.
cost
=
tf
.
add_n
([
cost
,
wd_cost
],
name
=
'cost'
)
...
...
tensorpack/tfutils/modelutils.py
View file @
bbf41d9e
...
...
@@ -11,7 +11,7 @@ __all__ = ['describe_model', 'get_shape_str']
def
describe_model
():
"""
p
rint a description of the current model parameters """
"""
P
rint a description of the current model parameters """
train_vars
=
tf
.
get_collection
(
tf
.
GraphKeys
.
TRAINABLE_VARIABLES
)
msg
=
[
""
]
total
=
0
...
...
@@ -29,8 +29,10 @@ def describe_model():
def
get_shape_str
(
tensors
):
"""
:param tensors: a tensor or a list of tensors
:returns: a string to describe the shape
Args:
tensors (list or tf.Tensor): a tensor or a list of tensors
Returns:
str: a string to describe the shape
"""
if
isinstance
(
tensors
,
(
list
,
tuple
)):
for
v
in
tensors
:
...
...
tensorpack/tfutils/summary.py
View file @
bbf41d9e
...
...
@@ -7,6 +7,7 @@ import tensorflow as tf
import
re
from
..utils.argtools
import
memoized
from
..utils
import
logger
from
..utils.naming
import
MOVING_SUMMARY_VARS_KEY
from
.tower
import
get_current_tower_context
from
.
import
get_global_step_var
...
...
@@ -18,7 +19,8 @@ __all__ = ['create_summary', 'add_param_summary', 'add_activation_summary',
def
create_summary
(
name
,
v
):
"""
Return a tf.Summary object with name and simple scalar value v
Returns:
tf.Summary: a tf.Summary object with name and simple scalar value v.
"""
assert
isinstance
(
name
,
six
.
string_types
),
type
(
name
)
v
=
float
(
v
)
...
...
@@ -29,8 +31,10 @@ def create_summary(name, v):
def
add_activation_summary
(
x
,
name
=
None
):
"""
Add summary to graph for an activation tensor x.
If name is None, use x.name.
Add summary for an activation tensor x. If name is None, use x.name.
Args:
x (tf.Tensor): the tensor to summary.
"""
ctx
=
get_current_tower_context
()
if
ctx
is
not
None
and
not
ctx
.
is_main_training_tower
:
...
...
@@ -47,16 +51,20 @@ def add_activation_summary(x, name=None):
tf
.
summary
.
scalar
(
name
+
'-rms'
,
rms
(
x
))
def
add_param_summary
(
summary_lists
):
def
add_param_summary
(
*
summary_lists
):
"""
Add summary
for all trainable variables matching the regex
Add summary
Ops for all trainable variables matching the regex.
:param summary_lists: list of (regex, [list of summary type to perform]).
Type can be 'mean', 'scalar', 'histogram', 'sparsity', 'rms'
Args:
summary_lists (list): each is (regex, [list of summary type to perform]).
Summary type can be 'mean', 'scalar', 'histogram', 'sparsity', 'rms'
"""
ctx
=
get_current_tower_context
()
if
ctx
is
not
None
and
not
ctx
.
is_main_training_tower
:
return
if
len
(
summary_lists
)
==
0
and
isinstance
(
summary_lists
[
0
],
list
):
logger
.
warn
(
"[Deprecated] Use positional args to call add_param_summary() instead of a list."
)
summary_lists
=
summary_lists
[
0
]
def
perform
(
var
,
action
):
ndim
=
var
.
get_shape
()
.
ndims
...
...
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