Reputation: 95
Recently I have been trying to understand tensorflow's tf.nn.conv2d_transpose
, however I have a hard time understanding the input parameters for it. It's defined as:
tf.nn.conv2d_transpose(value, filter, output_shape, strides, padding='SAME')
For example, let's say I have a image of size [batch_size, 7, 7, 128]
and want to transform it to [batch_size, 14, 14, 64]
. Then output_shape=[batch_size, 14, 14, 64]
, strides=[2,2]
, however I can't figure out how to get the shape of the filter. Any thoughts?
Furthermore how does padding="SAME"
works for conv2d_transpose
? Is it applied to the output image or the input?
Upvotes: 1
Views: 1432
Reputation: 5808
For the first question on filter shapes, I'd use the object oriented version tf.layers.Conv2DTranspose
and look at the kernel
property to figure out the filter shapes:
>>> import tensorflow as tf
>>> l = tf.layers.Conv2DTranspose(filters=64, kernel_size=1, padding='SAME', strides=[2, 2])
>>> l(tf.ones([12, 7, 7, 128]))
<tf.Tensor 'conv2d_transpose/BiasAdd:0' shape=(12, 14, 14, 64) dtype=float32>
>>> l.kernel
<tf.Variable 'conv2d_transpose/kernel:0' shape=(1, 1, 64, 128) dtype=float32_ref>
>>>
On second padding question, conv2d_transpose
computes the gradient of conv2d
. Since conv2d
pads its inputs, conv2d_transpose
needs to pad its output to fit the gradient.
Upvotes: 1