Skip to content

Instantly share code, notes, and snippets.

@kakauandme
Forked from panmari/conv_summary.py
Created January 9, 2016 09:16
Show Gist options
  • Save kakauandme/bc64b1886804d4bac24e to your computer and use it in GitHub Desktop.
Save kakauandme/bc64b1886804d4bac24e to your computer and use it in GitHub Desktop.
Tensorflow visualize convolutions
channels = 32
img_size = 128
W_conv1 = weight_variable([5, 5, 1, channels])
h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1))
# Produces a tensor of size [-1, img_size, img_size, channels]
## Prepare for visualization
# Take only convolutions of first image, discard convolutions for other images.
V = tf.slice(h_conv1, (0, 0, 0, 0), (1, -1, -1, -1), name='slice_first_input')
V = tf.reshape(V, (img_size, img_size, channels))
# Reorder so the channels are in the first dimension, x and y follow.
V = tf.transpose(V, (2, 0, 1))
# Bring into shape expected by image_summary
V = tf.reshape(V, (-1, img_size, img_size, 1))
tf.image_summary("first_conv", V)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment