tf.nn.conv2d_transpose为FCN的output_shape

时间:2017-08-17 02:21:05

标签: tensorflow

我想在FCN模型的tensorflow中实现反卷积层,我对5个转换输出中的每一个使用tf.nn.conv2d_transpose,我需要的是每个5 deconv的输出形状与输入相同图像形状。所以我设置了

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")

我做得对吗?

1 个答案:

答案 0 :(得分:-1)

我认为您的实施不正确,这是正确的步骤。

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])