コード例 #1
0
 def sampler_summaries(x_repeated_depth, g_sampler, args):
     with tf.variable_scope('sampler_metrics'):
         # mean and var metrics for sampler
         g_sampler = tf.reshape(
             g_sampler, x_repeated_depth.shape)  # reattach shape info
         sampler_gan.summarize_moments(g_sampler, 'depth', args)
         sampler_gan.summarize_moments(
             g_sampler - tf.reduce_mean(g_sampler), 'depth_normalized',
             args)
         # ground truth example
         ic = tf.expand_dims(x_repeated_depth[0], axis=0)
         ic = hem.rescale(ic, (-1, 1), (0, 1))
         ic = hem.colorize(ic)
         tf.summary.image('real_depth', ic)
         # mean and min l2 loss from sampler
         sample_l2_loss = tf.reduce_mean(tf.square(x_repeated_depth -
                                                   g_sampler),
                                         axis=[1, 2, 3])
         mean_l2_loss = tf.reduce_mean(sample_l2_loss)
         min_l2_loss = tf.reduce_min(sample_l2_loss)
         tf.summary.scalar('mean sample l2', mean_l2_loss)
         tf.summary.scalar('min sample l2', min_l2_loss)
         sample_rmse_loss = tf.reduce_mean(tf.sqrt(
             tf.square(x_repeated_depth - g_sampler)),
                                           axis=[1, 2, 3])
         mean_rmse_loss = tf.reduce_mean(sample_rmse_loss)
         min_rmse_loss = tf.reduce_min(sample_rmse_loss)
         tf.summary.scalar('mean sample rmse', mean_rmse_loss)
         tf.summary.scalar('min sample rmse', min_rmse_loss)
コード例 #2
0
ファイル: pix2pix.py プロジェクト: huangpu1/3dgan
 def summarize_moments(x, name, args):
     mean, var = tf.nn.moments(x, axes=[0])
     tf.summary.scalar(name + '/mean', tf.reduce_mean(mean))
     tf.summary.scalar(name + '/var', tf.reduce_mean(var))
     tf.summary.histogram(name + '/mean', mean)
     tf.summary.histogram(name + '/var', var)
     var = tf.expand_dims(var, axis=0)
     var = hem.colorize(var)
     tf.summary.image(name + '/var', var)
コード例 #3
0
ファイル: summaries.py プロジェクト: huangpu1/3dgan
def montage(x, height=0, width=0, colorize=False, num_examples=-1, name=None):
    """Generates a m x n image montage from the given tensor.

    If m or n is 0, attempts to infer the input shape at run time.  Note
    that this may not always be possible.

    Args:
      x: Tensor, images to combine in montage. 
      m: Integer, number of rows in montage grid.
      n: Integer, number of columns in montage grid.
      name: String, name of this summary.

    Returns:
      Summary image node containing the montage.
    """


    with tf.name_scope(name, 'montage', [x]) as scope:
        # restrict montage to specific size
        if num_examples == -1:
            num_examples = x.get_shape()[0]
        x = x[0:num_examples]
        # colorize if asked and using a single-channel. otherwise make sure to convert to NHWC
        if colorize and x.get_shape()[1] == 1:
            x = hem.colorize(x)
        else:
            if len(x.shape) == 4:
                x = tf.transpose(x, [0, 2, 3, 1])
        # figure out w/h dynamically if necessary
        if height == 0 or width == 0:
            height, width = factorization(x.get_shape()[0].value)
        # create montage
        images = tf.split(x, width, axis=0)
        images = tf.concat(images, axis=1)
        images = tf.unstack(images, height, axis=0)
        images = tf.concat(images, axis=1)
        # if this is a b/w images, add a third dimension
        if len(images.shape) < 3:
            images = tf.expand_dims(images, axis=2)
        # add a first dimension for expected TB format
        images = tf.expand_dims(images, axis=0)
        y = tf.summary.image(scope, images)
    return y