How can I visualize the weights in cnn in Tensorflow ?

How can I visualize the weights in cnn in Tensorflow ?

Asked on December 19, 2018 in Tensorflow.
Add Comment


  • 1 Answer(s)

          Use tf.image_summary. For cifar10_train.py, Apply the following code under def train(). Note to access a var_scope ( ‘conv1’ )

    # Visualize conv1 features
    with tf.variable_scope('conv1') as scope_conv:
      weights = tf.get_variable('weights')
     
      # scale weights to [0 255] and convert to uint8 (maybe change scaling?)
      x_min = tf.reduce_min(weights)
      x_max = tf.reduce_max(weights)
      weights_0_to_1 = (weights - x_min) / (x_max - x_min)
      weights_0_to_255_uint8 = tf.image.convert_image_dtype (weights_0_to_1, dtype=tf.uint8)
     
      # to tf.image_summary format [batch_size, height, width, channels]
      weights_transposed = tf.transpose (weights_0_to_255_uint8, [3, 0, 1, 2])
     
      # this will display random 3 filters from the 64 in conv1
      tf.image_summary('conv1/filters', weights_transposed, max_images=3)
    
    Answered on December 19, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.