摘自博客:https://blog.csdn.net/mao_xiao_feng/article/details/71713358
conv2d_transpose(value, filter, output_shape, strides, padding="SAME", data_format="NHWC", name=None)
除去name参数用以指定该操作的name,与方法有关的一共六个参数:
tf.nn.conv2d 中的filter参数,是[filter_height, filter_width, in_channels, out_channels]
tf.nn.conv2d_transpose 中的filter参数,是[filter_height, filter_width, out_channels,in_channels]
x1 = tf.constant(1.0, shape=[1,3,3,1])
x2 = tf.constant(1.0, shape=[1,6,6,3]) #6×6的3通道图
x3 = tf.constant(1.0, shape=[1,5,5,3]) #5×5的3通道图
kernel = tf.constant(1.0, shape=[3,3,3,1])
y2 = tf.nn.conv2d(x3, kernel, strides=[1,2,2,1], padding="SAME")
y3 = tf.nn.conv2d_transpose(y2,kernel,output_shape=[1,5,5,3], strides=[1,2,2,1],padding="SAME")
y4 = tf.nn.conv2d(x2, kernel, strides=[1,2,2,1], padding="SAME")
'''
Wrong!!This is impossible
y5 = tf.nn.conv2d_transpose(x1,kernel,output_shape=[1,10,10,3],strides=[1,2,2,1],padding="SAME")
'''
sess = tf.Session()
tf.global_variables_initializer().run(session=sess)
x1_decov, x3_cov, y2_decov, x2_cov=sess.run([y1,y2,y3,y4])
print(x1_decov.shape)
print(x3_cov.shape)
print(y2_decov.shape)
print(x2_cov.shape)
返回的y2是[1,3,3,1]的Tensor,是一个单通道的图
对y2做conv2d_transpose,返回的Tensor和x3的shape是一样的[1,5,5,3]
x2做卷积,获得y4的shape也为[1,3,3,1]。
说明[1,3,3,1]的图反卷积产生了两种情况。所以这里指定output_shape是有意义的,当然随意指定output_shape是不允许的如y5
博客:https://blog.csdn.net/hustwayne/article/details/83989207 中有动图,方便理解