简体   繁体   English

Tensorflow的tf.nn.conv2d_transpose参数

[英]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. 最近我一直在尝试了解tensorflow的tf.nn.conv2d_transpose ,但是我很难理解它的输入参数。 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] . 例如,假设我有一个大小为[batch_size, 7, 7, 128]的图像,并且想要将其转换为[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. 然后output_shape=[batch_size, 14, 14, 64]output_shape=[batch_size, 14, 14, 64] strides=[2,2] ,但是我不知道如何获得滤波器的形状。 Any thoughts? 有什么想法吗?

Furthermore how does padding="SAME" works for conv2d_transpose ? 此外, padding="SAME"conv2d_transpose如何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: 对于有关过滤器形状的第一个问题,我将使用面向对象的版本tf.layers.Conv2DTranspose并查看kernel属性以找出过滤器形状:

>>> 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 . 上第二填充问题, conv2d_transpose计算的梯度conv2d Since conv2d pads its inputs, conv2d_transpose needs to pad its output to fit the gradient. 由于conv2d其输入,因此conv2d_transpose需要填充其输出以适合渐变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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