简体   繁体   中英

Tensorflow's tf.nn.conv2d_transpose parameters

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM