tf.nn。为FCN conv2d_transpose output_shape

时间:2023-02-08 17:36:07

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. So I set

我想在FCN模型的张量流中实现反褶积层,我使用了tf.nn。对于5个conv输出的每个conv2d_转置,我需要的是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")

Am I doing it right?

我做得对吗?

1 个解决方案

#1


-1  

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

#1


-1  

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