Commit 9fc5d856 authored by Yuxin Wu's avatar Yuxin Wu

update summary API to latest

parent 1f02847d
......@@ -153,7 +153,7 @@ def get_config():
global_step=get_global_step_var(),
decay_steps=data_train.size() * 100,
decay_rate=0.5, staircase=True, name='learning_rate')
tf.scalar_summary('learning_rate', lr)
tf.summary.scalar('lr', lr)
return TrainConfig(
dataset=data_train,
......
......@@ -75,7 +75,7 @@ class Model(ModelDesc):
W_init=tf.truncated_normal_initializer(stddev=0.02)):
with tf.variable_scope('gen'):
image_gen = self.generator(z)
tf.image_summary('gen', image_gen, max_images=30)
tf.summary.image('gen', image_gen, max_images=30)
with tf.variable_scope('discrim'):
vecpos = self.discriminator(image_pos)
with tf.variable_scope('discrim', reuse=True):
......
......@@ -52,8 +52,8 @@ class RandomZData(DataFlow):
def build_GAN_losses(vecpos, vecneg):
sigmpos = tf.sigmoid(vecpos)
sigmneg = tf.sigmoid(vecneg)
tf.histogram_summary('sigmoid-pos', sigmpos)
tf.histogram_summary('sigmoid-neg', sigmneg)
tf.summary.histogram('sigmoid-pos', sigmpos)
tf.summary.histogram('sigmoid-neg', sigmneg)
d_loss_pos = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(
vecpos, tf.ones_like(vecpos)), name='d_CE_loss_pos')
......
......@@ -66,7 +66,7 @@ class Model(ModelDesc):
W_init=tf.truncated_normal_initializer(stddev=0.02)):
with tf.variable_scope('gen'):
image_gen = self.generator(z)
tf.image_summary('gen', image_gen, max_images=30)
tf.summary.image('gen', image_gen, max_images=30)
with tf.variable_scope('discrim'):
vecpos, _ = self.discriminator(image_pos)
with tf.variable_scope('discrim', reuse=True):
......
......@@ -61,7 +61,7 @@ class Model(ModelDesc):
transform1 = tf.concat(1, [padded1[:,:,:,0], padded1[:,:,:,1]])
transform2 = tf.concat(1, [padded2[:,:,:,0], padded2[:,:,:,1]])
stacked = tf.concat(2, [img_orig, transform1, transform2], 'viz')
tf.image_summary('visualize',
tf.summary.image('visualize',
tf.expand_dims(stacked, -1), max_images=30)
sampled = tf.concat(3, [sampled1, sampled2], 'sampled_concat')
......
......@@ -38,7 +38,7 @@ class Model(ModelDesc):
keep_prob = tf.constant(0.5 if is_training else 1.0)
if is_training:
tf.image_summary("train_image", image, 10)
tf.summary.image("train_image", image, 10)
image = image / 4.0 # just to make range smaller
with argscope(Conv2D, nl=BNReLU, use_bias=False, kernel_shape=3):
......
......@@ -104,7 +104,7 @@ def get_config():
# This will also put the summary in tensorboard,stat.json and print in
# terminal, but without the moving average
tf.scalar_summary('learning_rate', lr)
tf.summary.scalar('lr', lr)
# get the config which contains everything necessary in a training
return TrainConfig(
......
......@@ -92,7 +92,7 @@ def get_config():
global_step=get_global_step_var(),
decay_steps=data_train.size() * 60,
decay_rate=0.2, staircase=True, name='learning_rate')
tf.scalar_summary('learning_rate', lr)
tf.summary.scalar('lr', lr)
return TrainConfig(
dataset=data_train,
......
# -*- coding: utf-8 -*-
# File: stat.py
# File: stats.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import tensorflow as tf
......@@ -40,6 +40,9 @@ class StatHolder(object):
:param k: name
:param v: value
"""
suffix = '-summary'
if k.endswith(suffix):
k = k[:-len(suffix)]
self.stat_now[k] = float(v)
def set_print_tag(self, print_tag):
......
......@@ -110,7 +110,7 @@ class SummaryGradient(MapGradient):
name = var.op.name
if name not in _summaried_gradient:
_summaried_gradient.add(name)
tf.histogram_summary(name + '/grad', grad)
tf.summary.histogram(name + '-grad', grad)
add_moving_summary(rms(grad, name=name + '/rms'))
return grad
......
......@@ -38,11 +38,10 @@ def add_activation_summary(x, name=None):
"Summary a scalar with histogram? Maybe use scalar instead. FIXME!"
if name is None:
name = x.name
with tf.name_scope('act_summary'):
tf.histogram_summary(name + '/activation', x)
tf.scalar_summary(name + '/activation_sparsity', tf.nn.zero_fraction(x))
tf.scalar_summary(
name + '/activation_rms', rms(x))
with tf.name_scope('activation-summary'):
tf.summary.histogram(name, x)
tf.summary.scalar(name + '-sparsity', tf.nn.zero_fraction(x))
tf.summary.scalar(name + '-rms', rms(x))
def add_param_summary(summary_lists):
"""
......@@ -59,25 +58,25 @@ def add_param_summary(summary_lists):
name = var.name.replace(':0', '')
if action == 'scalar':
assert ndim == 0, "Scalar summary on high-dimension data. Maybe you want 'mean'?"
tf.scalar_summary(name, var)
tf.summary.scalar(name, var)
return
assert ndim > 0, "Cannot perform {} summary on scalar data".format(action)
if action == 'histogram':
tf.histogram_summary(name, var)
tf.summary.histogram(name, var)
return
if action == 'sparsity':
tf.scalar_summary(name + '/sparsity', tf.nn.zero_fraction(var))
tf.summary.scalar(name + '-sparsity', tf.nn.zero_fraction(var))
return
if action == 'mean':
tf.scalar_summary(name + '/mean', tf.reduce_mean(var))
tf.summary.scalar(name + '-mean', tf.reduce_mean(var))
return
if action == 'rms':
tf.scalar_summary(name + '/rms', rms(var))
tf.summary.scalar(name + '-rms', rms(var))
return
raise RuntimeError("Unknown summary type: {}".format(action))
params = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES)
with tf.name_scope('param_summary'):
with tf.name_scope('param-summary'):
for p in params:
name = p.name
for rgx, actions in summary_lists:
......@@ -111,7 +110,7 @@ def summary_moving_average(tensors=None):
"""
if tensors is None:
tensors = tf.get_collection(MOVING_SUMMARY_VARS_KEY)
with tf.name_scope('EMA_summary'):
with tf.name_scope('EMA-summary'):
# TODO will produce EMA_summary/tower0/xxx. not elegant
with tf.name_scope(None):
averager = tf.train.ExponentialMovingAverage(
......@@ -119,6 +118,6 @@ def summary_moving_average(tensors=None):
avg_maintain_op = averager.apply(tensors)
for idx, c in enumerate(tensors):
name = re.sub('tower[p0-9]+/', '', c.op.name)
tf.scalar_summary(name, averager.average(c))
tf.summary.scalar(name, averager.average(c))
return avg_maintain_op
......@@ -116,5 +116,6 @@ def get_scalar_var(name, init_value, summary=False, trainable=False):
initializer=tf.constant_initializer(init_value),
trainable=trainable)
if summary:
tf.scalar_summary(name, ret)
# this is recognized in callbacks.StatHolder
tf.summary.scalar(name + '-summary', ret)
return ret
......@@ -109,8 +109,8 @@ class Trainer(object):
if not hasattr(logger, 'LOG_DIR'):
raise RuntimeError("logger directory wasn't set!")
self.summary_writer = tf.train.SummaryWriter(logger.LOG_DIR, graph=self.sess.graph)
self.summary_op = tf.merge_all_summaries()
self.summary_writer = tf.summary.FileWriter(logger.LOG_DIR, graph=self.sess.graph)
self.summary_op = tf.summary.merge_all()
# create an empty StatHolder
self.stat_holder = StatHolder(logger.LOG_DIR)
......
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