在tensorflow中使用tf.nn.conv2d_transpose获取反卷积层的输出形状 [英] Getting the output shape of deconvolution layer using tf.nn.conv2d_transpose in tensorflow
问题描述
根据此纸张,输出形状为N + H - 1
,N
是输入的高度或宽度,H
是内核的高度或宽度.这是明显的卷积逆过程.此教程给出了一个计算卷积输出形状的公式,该公式为(W−F+2P)/S+1
,F
-过滤器大小,P
-填充大小,S
-跨度.但是在 Tensorflow 中,有一些测试用例,例如:
According to this paper, the output shape is N + H - 1
, N
is input height or width, H
is kernel height or width. This is obvious inverse process of convolution. This tutorial gives a formula to calculate the output shape of convolution which is (W−F+2P)/S+1
, W
- input size, F
- filter size, P
- padding size, S
- stride. But in Tensorflow, there are test cases like:
strides = [1, 2, 2, 1]
# Input, output: [batch, height, width, depth]
x_shape = [2, 6, 4, 3]
y_shape = [2, 12, 8, 2]
# Filter: [kernel_height, kernel_width, output_depth, input_depth]
f_shape = [3, 3, 2, 3]
因此,根据公式(W−F+2P)/S+1
,我们使用y_shape
,f_shape
和x_shape
来计算填充大小P
.从(12 - 3 + 2P) / 2 + 1 = 6
,我们得到P = 0.5
,它不是整数.去卷积如何在Tensorflow中工作?
So we use y_shape
, f_shape
and x_shape
, according to formula (W−F+2P)/S+1
to calculate padding size P
. From (12 - 3 + 2P) / 2 + 1 = 6
, we get P = 0.5
, which is not an integer. How does deconvolution works in Tensorflow?
推荐答案
用于反卷积,
output_size = strides * (input_size-1) + kernel_size - 2*padding
步幅,input_size,kernel_size,padding为整数 对于有效",填充为零
strides, input_size, kernel_size, padding are integer padding is zero for 'valid'
这篇关于在tensorflow中使用tf.nn.conv2d_transpose获取反卷积层的输出形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!