Reputation: 9
I have pre-trained weights for a 3d convolutional layer using Matlab. The weights is a 5d tensor with dimension (512,4,4,4,160). [out_channels, filter_depth, filter_height, filter_width, in_channels]
Now I want to input it as the initial weights for fine-tuning in tensorflow's tf.nn.conv3d. I see that the shape of weights are allowed for 3d convolutional neural networks should be: (4,4,4,160,512).[filter_depth, filter_height, filter_width, in_channels, out_channels]. Can I just use tf.Variable().reshape(4,4,4,160,512)? But I feel it is not the correct weights if I just use reshape.
Upvotes: 0
Views: 325
Reputation: 2156
The tf.transpose
operation can reorder axes: https://www.tensorflow.org/versions/r0.11/api_docs/python/array_ops.html#transpose
Provided that initial shape of tensor input
is (512,4,4,4,160)
the output tensor of tf.transpose(input, perm=[4,1,2,3,0])
will have shape (160,4,4,4,512)
.
Also you may need to reverse your weights along some axis or axes. In tensorflow convolutions are implemented as cross-correlations: https://www.tensorflow.org/versions/r0.11/api_docs/python/nn.html#convolution
Upvotes: 0