【问题标题】:Finding the amount of zeros to pad the input of a convolutional layer查找零的数量以填充卷积层的输入
【发布时间】:2017-06-11 15:06:51
【问题描述】:

我正在使用这些 these sources 在 tensorflow 中构建卷积自动编码器。我知道我需要用零填充我的输入图像,以便从解码器获得等于原始输入的输出。 作者给出了一个简单的正方形内核示例和相等的步幅值(垂直和水平)。我需要为我的输入概括这个填充函数,但是我无法获得正确的张量形状。到目前为止,我的功能是:

def _pad(self, input_x, filter_height, filter_width):
    """
    pads input_x with the right amount of zeros.
    Args:
        input_x: 4-D tensor, [batch_side, widht, height, depth]
        filter_side: used to dynamically determine the padding amount
    Returns:
        input_x padded
    """
    # calculate the padding amount for each side
    top_bottom_padding = filter_height - 1
    left_right_padding = filter_width - 1

    # pad the input on top, bottom, left, right, with amount zeros
    return tf.pad(input_x,
                  [[0, 0], [top_bottom_padding, top_bottom_padding], [left_right_padding, left_right_padding], [0, 0]])

这给了我

Shape of input:  (10, 161, 1800, 1)
Shape of padded input: (10, 187, 1826, 1)
Shape of encoder output:  (10, 187, 913, 15)
Shape of decoder output:  (10, 187, 457, 15)

num_outputs=15, kernel_size=14, stride=[1,2]

知道我做错了什么吗?

【问题讨论】:

    标签: tensorflow padding convolution autoencoder


    【解决方案1】:

    您使用的函数没有考虑步幅。实际上,它只是将您的初始输入减 1。对于 1D 情况,知道输入大小 i、内核大小 k、步幅 s 和填充 p 即可计算卷积的输出大小为:

    这里 ||操作员是指天花板操作。了解 1-dim 情况的数学,n-dim 情况一旦你看到每个 dim 都是独立的,就很容易了。因此,您只需分别滑动每个维度。


    看公式,知道你的o应该等于i,就可以计算出合适的padding。

    【讨论】:

      猜你喜欢
      • 2019-07-08
      • 2021-11-05
      • 2018-08-04
      • 1970-01-01
      • 1970-01-01
      • 2020-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多