【问题标题】:tf.nn.conv2d_transpose output_shape for FCNFCN 的 tf.nn.conv2d_transpose output_shape
【发布时间】:2017-08-17 15:18:25
【问题描述】:

我想在 tensorflow 中为 FCN 模型实现反卷积层,我对 5 个 conv 输出中的每一个都使用了 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")

我做得对吗?

【问题讨论】:

    标签: tensorflow


    【解决方案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])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多