Reputation: 694
I want to visualize the filter weights of my CNN. They are of size height
xwidth
xinput
xoutput
.
However, TensorBoard requires the image_summary to be a Tensor of shape batches
xheight
xwidth
xchannels
.
How can I convert my filter weights to the correct form?
Some context:
W1 = tf.Variable(tf.random_normal([5, 5, 1, 64]), name='W1')
conv = tf.nn.conv2d(x, W1, strides=[1, 1, 1, 1], padding='SAME')
Upvotes: 1
Views: 4406
Reputation: 3358
A normal image batch has shape [batch, height, width, 3]
so you can make Tensorboard show a batch of colored images for the first convolution layer by transposing the filters to [output, height, width, 3]
. This answer has the code: How to visualize learned filters on tensorflow.
For weights in other layers, you can only show input * output
grayscale images. You first need to split the tensor along input/output channel, transpose and concatenate the tensor to shape [input * output, height, width, 1]
. You can find some example code here: https://github.com/tensorflow/tensorflow/issues/908
Upvotes: 1