繁体   English   中英

找到零的数量以填充卷积层的输入

[英]Finding the amount of zeros to pad the input of a convolutional layer

我使用这些这些 资源打造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]

关于我在做什么错的任何想法吗?

您使用的功能未考虑跨步。 实际上,它只是将初始输入值减少1。 对于一维情况,知道输入大小i ,内核大小k ,步幅s和填充p ,则可以计算出卷积的输出大小为:

在此处输入图片说明

在这里|| 操作员表示天花板操作。 一旦知道了每个暗角是独立的,就知道了1暗角情况的数学原理,n暗角情况很容易。 因此,您只需分别滑动每个尺寸。


查看公式,知道您的o应该等于i ,您可以计算适当的填充。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM