[英]tf.nn.conv2d_transpose output_shape for FCN
I want to implement deconvolution layer in tensorflow for FCN model, I used tf.nn.conv2d_transpose for each of 5 conv outputs, what I need is that the output shape of each of the 5 deconv to be the same as the input image shape. 我想为FCN模型在tensorflow中实现反卷积层,我对5个conv输出中的每个使用tf.nn.conv2d_transpose,我需要的是5个deconv中的每个输出的形状都与输入图像形状相同。 So I set 所以我设定
deconv_shape = tf.shape(input)
tf.nn.conv2d_transpose(value=deconv5_1,
filter=[32, 32, 1, 1],
output_shape=deconv_shape,
strides=16,
padding="same",
name="deconv5_2")
Am I doing it right? 我做对了吗?
I think your implementation isn't correct, here's the few step to get it right. 我认为您的实现方式不正确,这是正确解决问题的几个步骤。
in_channels = input.shape[-1]
# here set the output_height, width as [stride*input_height, stride*input_width]]
output_shape = [batch_size, output_height, output_width, out_channels]
filter_size =2 # for example
stride = 2 # for example if you want 2x scale of input height, width
shape = [filter_size, filter_size, out_channels, in_channels]
w = tf.get_variable(
name='W',
shape=shape,
initializer=w_init,
regularizer=w_regularizer,
trainable=trainable
)
output = tf.nn.conv2d_transpose(
input, w, output_shape=output_shape, strides=[1, stride, stride, 1])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.