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
9fe18ff8
Commit
9fe18ff8
authored
Feb 26, 2016
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better param summary
parent
565404ec
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
11 deletions
+27
-11
example_alexnet.py
example_alexnet.py
+0
-2
example_cifar10.py
example_cifar10.py
+1
-1
example_mnist.py
example_mnist.py
+1
-1
tensorpack/utils/summary.py
tensorpack/utils/summary.py
+25
-7
No files found.
example_alexnet.py
View file @
9fe18ff8
...
@@ -76,8 +76,6 @@ class Model(ModelDesc):
...
@@ -76,8 +76,6 @@ class Model(ModelDesc):
regularize_cost
(
'fc.*/W'
,
tf
.
nn
.
l2_loss
),
regularize_cost
(
'fc.*/W'
,
tf
.
nn
.
l2_loss
),
name
=
'regularize_loss'
)
name
=
'regularize_loss'
)
tf
.
add_to_collection
(
MOVING_SUMMARY_VARS_KEY
,
wd_cost
)
tf
.
add_to_collection
(
MOVING_SUMMARY_VARS_KEY
,
wd_cost
)
add_param_summary
(
'.*/W'
)
# monitor histogram of all W
return
tf
.
add_n
([
wd_cost
,
cost
],
name
=
'cost'
)
return
tf
.
add_n
([
wd_cost
,
cost
],
name
=
'cost'
)
def
get_config
():
def
get_config
():
...
...
example_cifar10.py
View file @
9fe18ff8
...
@@ -87,7 +87,7 @@ class Model(ModelDesc):
...
@@ -87,7 +87,7 @@ class Model(ModelDesc):
name
=
'regularize_loss'
)
name
=
'regularize_loss'
)
tf
.
add_to_collection
(
MOVING_SUMMARY_VARS_KEY
,
wd_cost
)
tf
.
add_to_collection
(
MOVING_SUMMARY_VARS_KEY
,
wd_cost
)
add_param_summary
(
'.*'
)
# monitor all variables
add_param_summary
(
[(
'.*/W'
,
[
'histogram'
,
'sparsity'
])])
# monitor W
return
tf
.
add_n
([
cost
,
wd_cost
],
name
=
'cost'
)
return
tf
.
add_n
([
cost
,
wd_cost
],
name
=
'cost'
)
def
get_config
():
def
get_config
():
...
...
example_mnist.py
View file @
9fe18ff8
...
@@ -77,7 +77,7 @@ class Model(ModelDesc):
...
@@ -77,7 +77,7 @@ class Model(ModelDesc):
name
=
'regularize_loss'
)
name
=
'regularize_loss'
)
tf
.
add_to_collection
(
MOVING_SUMMARY_VARS_KEY
,
wd_cost
)
tf
.
add_to_collection
(
MOVING_SUMMARY_VARS_KEY
,
wd_cost
)
add_param_summary
(
'.*/W'
)
# monitor histogram of all W
add_param_summary
(
[(
'.*/W'
,
[
'histogram'
,
'sparsity'
])]
)
# monitor histogram of all W
return
tf
.
add_n
([
wd_cost
,
cost
],
name
=
'cost'
)
return
tf
.
add_n
([
wd_cost
,
cost
],
name
=
'cost'
)
def
get_config
():
def
get_config
():
...
...
tensorpack/utils/summary.py
View file @
9fe18ff8
...
@@ -33,20 +33,38 @@ def add_activation_summary(x, name=None):
...
@@ -33,20 +33,38 @@ def add_activation_summary(x, name=None):
tf
.
histogram_summary
(
name
+
'/activation'
,
x
)
tf
.
histogram_summary
(
name
+
'/activation'
,
x
)
tf
.
scalar_summary
(
name
+
'/activation_sparsity'
,
tf
.
nn
.
zero_fraction
(
x
))
tf
.
scalar_summary
(
name
+
'/activation_sparsity'
,
tf
.
nn
.
zero_fraction
(
x
))
def
add_param_summary
(
regex
):
def
add_param_summary
(
summary_lists
):
"""
"""
summary_lists: list of (regex, [list of action to perform])
action can be 'mean', 'scalar', 'histogram', 'sparsity'
Add summary for all trainable variables matching the regex
Add summary for all trainable variables matching the regex
"""
"""
def
perform
(
var
,
action
):
ndim
=
var
.
get_shape
()
.
ndims
if
action
==
'scalar'
:
assert
ndim
==
0
,
"Scalar summary on high-dimension data. Maybe you want 'mean'?"
tf
.
scalar_summary
(
var
.
name
,
var
)
return
assert
ndim
>
0
,
"Cannot perform {} summary on scalar data"
.
format
(
action
)
if
action
==
'histogram'
:
tf
.
histogram_summary
(
var
.
name
,
var
)
return
if
action
==
'sparsity'
:
tf
.
scalar_summary
(
var
.
name
+
'/sparsity'
,
tf
.
nn
.
zero_fraction
(
var
))
return
if
action
==
'mean'
:
tf
.
scalar_summary
(
var
.
name
+
'/mean'
,
tf
.
reduce_mean
(
var
))
return
raise
RuntimeError
(
"Unknown action {}"
.
format
(
action
))
import
re
import
re
params
=
tf
.
get_collection
(
tf
.
GraphKeys
.
TRAINABLE_VARIABLES
)
params
=
tf
.
get_collection
(
tf
.
GraphKeys
.
TRAINABLE_VARIABLES
)
for
p
in
params
:
for
p
in
params
:
name
=
p
.
name
name
=
p
.
name
if
re
.
search
(
regex
,
name
):
for
rgx
,
actions
in
summary_lists
:
if
p
.
get_shape
()
.
ndims
==
0
:
if
re
.
search
(
rgx
,
name
):
tf
.
scalar_summary
(
name
,
p
)
for
act
in
actions
:
else
:
perform
(
p
,
act
)
#tf.scalar_summary(name + '/sparsity', tf.nn.zero_fraction(p))
tf
.
histogram_summary
(
name
,
p
)
def
summary_moving_average
(
cost_var
):
def
summary_moving_average
(
cost_var
):
""" Create a MovingAverage op and summary for all variables in
""" Create a MovingAverage op and summary for all variables in
...
...
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