Commit 78ce3a96 authored by Yuxin Wu's avatar Yuxin Wu

summary for all parameters

parent d8330092
...@@ -72,7 +72,7 @@ def get_model(inputs, is_training): ...@@ -72,7 +72,7 @@ def get_model(inputs, is_training):
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_histogram_summary('.*/W') # monitor histogram of all W add_param_summary('.*/W') # monitor histogram of all W
return [prob, nr_wrong], tf.add_n([wd_cost, cost], name='cost') return [prob, nr_wrong], tf.add_n([wd_cost, cost], name='cost')
def get_config(): def get_config():
......
...@@ -73,7 +73,7 @@ def get_model(inputs, is_training): ...@@ -73,7 +73,7 @@ def get_model(inputs, is_training):
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_histogram_summary('.*/W') # monitor histogram of all W add_param_summary('.*') # monitor all variables
return [prob, nr_wrong], tf.add_n([wd_cost, cost], name='cost') return [prob, nr_wrong], tf.add_n([wd_cost, cost], name='cost')
def get_config(): def get_config():
...@@ -155,5 +155,5 @@ if __name__ == '__main__': ...@@ -155,5 +155,5 @@ if __name__ == '__main__':
if args.load: if args.load:
config.session_init = SaverRestore(args.load) config.session_init = SaverRestore(args.load)
if args.gpu: if args.gpu:
config['nr_tower'] = len(args.gpu.split(',')) config.nr_tower = len(args.gpu.split(','))
start_train(config) start_train(config)
...@@ -82,7 +82,7 @@ def get_model(inputs, is_training): ...@@ -82,7 +82,7 @@ def get_model(inputs, is_training):
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_histogram_summary('.*/W') # monitor histogram of all W add_param_summary('.*/W') # monitor histogram of all W
return [prob, nr_wrong], tf.add_n([wd_cost, cost], name='cost') return [prob, nr_wrong], tf.add_n([wd_cost, cost], name='cost')
def get_config(): def get_config():
......
...@@ -140,6 +140,7 @@ def start_train(config): ...@@ -140,6 +140,7 @@ def start_train(config):
grads = [] grads = []
for i in range(config.nr_tower): for i in range(config.nr_tower):
with tf.device('/gpu:{}'.format(i)): with tf.device('/gpu:{}'.format(i)):
with tf.name_scope('tower{}'.format(i)) as scope:
model_inputs = get_model_inputs() model_inputs = get_model_inputs()
output_vars, cost_var = config.get_model_func(model_inputs, is_training=True) output_vars, cost_var = config.get_model_func(model_inputs, is_training=True)
grads.append( grads.append(
......
...@@ -32,15 +32,18 @@ def add_activation_summary(x, name=None): ...@@ -32,15 +32,18 @@ def add_activation_summary(x, name=None):
tf.histogram_summary(name + '/activations', x) tf.histogram_summary(name + '/activations', x)
tf.scalar_summary(name + '/sparsity', tf.nn.zero_fraction(x)) tf.scalar_summary(name + '/sparsity', tf.nn.zero_fraction(x))
def add_histogram_summary(regex): def add_param_summary(regex):
""" """
Add histogram summary for all trainable variables matching the regex Add summary for all trainable variables matching the regex
""" """
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): if re.search(regex, name):
if p.get_shape().ndims == 0:
tf.scalar_summary(name, p)
else:
tf.histogram_summary(name, p) tf.histogram_summary(name, p)
def summary_moving_average(cost_var): def summary_moving_average(cost_var):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment