Reputation: 99
I am trying to visualize capsule network layers. Following are layers:
conv_layer1=tflearn.layers.conv.conv_2d(input_layer, nb_filter=256, filter_size=9, strides=[1,1,1,1],
padding='same', activation='relu', regularizer="L2", name='conv_layer_1')
conv_layer2=tflearn.layers.conv.conv_2d(conv_layer1, nb_filter=256, filter_size=9, strides=[1,2,2,1],
padding='same', activation='relu', regularizer="L2", name='conv_layer_2')
conv_layer3=tf.reshape(conv_layer2,[-1,1152,8], name='conv_layer3')
the shape of each layer is as follows:
layer_1: (?, 50, 50, 256)
layer_2: (?, 25, 25, 256)
layer_3: (?, 1152, 8)
Here, I can visualize first two layers with random training image. The code for visualization is as follows:
image = X_train[1]
test = tf.Session()
init = tf.global_variables_initializer()
test.run(init) #(tf.global_variables_initializer())
filteredImage = test.run(conv_layer3, feed_dict{x:image.reshape(1,50,50,3)})
for i in range(64):
plt.imshow(filteredImage[:,:,:,i].reshape(-1,25))
plt.title('filter{}'.format(i))
plt.show()
Here, for visualizing third layer, I got the following error:
InvalidArgumentError: Input to reshape is a tensor with 160000 values, but the requested shape requires a multiple of 9216
[[node conv_layer3_9 (defined at <ipython-input-36-fd98b9e18bda>:20) = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/device:CPU:0"](conv_layer_2_11/Relu, conv_layer3_9/shape)]]
How to overcome this and visualize layer 3?
Upvotes: 0
Views: 326
Reputation: 378
The problem is on the line where you define your third layer conv_layer3=tf.reshape(conv_layer2,[-1,1152,8], name='conv_layer3')
The input to this layer conv_layer2
has a shape of ?,25x25x256
which give the 160000
value on the error and you want to reshape that to a shape of ?, 1152x8
which gives the 9216
. So that the reshape works the first one should be multiple of the second.
Upvotes: 1