Last active
January 15, 2019 14:54
-
-
Save panmari/4622b78ce21e44e2d69c to your computer and use it in GitHub Desktop.
Tensorflow visualize convolutions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Just an update: use tf.summary.image("first_conv", V) instead of tf.image_summary("first_conv", V). The code will be
channels = 32
img_size = 128
W_conv1 = weight_variable([5, 5, 1, channels])
h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1))
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))
V = tf.transpose(V, (2, 0, 1))
V = tf.reshape(V, (-1, img_size, img_size, 1))
tf.summary.image("first_conv", V)