Reputation: 179
I am using TensorFlow to reconstruct a CNN model called 'Deep Voxel Flow': https://github.com/liuziwei7/voxel-flow.
The output of the model is a tensor with the shape of [16,256,256,3] (16 is the batch size, 256 is the size of feature map, and 3 is the number of channels). When I tried to extract first 2 channels from the 4D tensor('flow=deconv4[:, :, :, 0:2]'), but I got an error: 'TypeError: 'Conv2dLayer' object is not subscriptable'.
deconv4 = Conv2d(deconv3_bn_relu, 3, [5, 5], act=tf.tanh, padding='SAME',
W_init=w_init, name='deconv4')
flow = deconv4[:, :, :, 0:2]
The expected result is that the 'flow' is a 4D tensor with the shape of [16,256,256,2].
Upvotes: 2
Views: 2383
Reputation: 1639
You should replace the use of Conv2D
by a convolution layer, that returns a tensor:
deconv4 = tf.layers.conv2d(deconv3_bn_relu, 3, [5, 5], activation=tf.tanh,
padding='SAME', kernel_initializer=w_init,
name='deconv4')
Then, you cannot use the []
to access the result of a Tensorflow operation directly.
But you can use other operations to reshape/modify/split/truncate..etc the tensor.
In your case I think what you're looking for might be:
flow = tf.slice(deconv4, [0,0,0,0], [16, 256, 256, 2])
Upvotes: 1