Padding:valid和same

卷积操作有两个问题:
1. 图像越来越小;
2. 图像边界信息丢失,即有些图像角落和边界的信息发挥作用较少。因此需要padding。

卷积核大小通常为奇数
一方面是为了方便same卷积padding对称填充,左右两边对称补零;
n+2p-f+1=n
p=(f-1)/2
另一方面,奇数过滤器有中心像素,便于确定过滤器的位置。

padding


padding的方式:


这里写图片描述

备注


    "VALID" only ever drops the right-most columns (or bottom-most rows).
    "SAME" tries to pad evenly left and right, but if the amount of columns to be added is odd, it will add the extra column to the right, as is the case in this example (the same logic applies vertically: there may be an extra row of zeros at the bottom).
  • 1
  • 2
  • 3
不同的padding方式,VALID是采用丢弃的方式,比如上述的input_width=13,只允许滑动2次,多余的元素全部丢掉
SAME的方式,采用的是补全的方式,对于上述的情况,允许滑动3次,但是需要补3个元素,左奇右偶,在左边补一个0,右边补2个0
  • 1
  • 2

Tensorflow中的定义


 The TensorFlow Convolution example gives an overview about the difference between SAME and VALID :

    For the SAME padding, the output height and width are computed as:

    out_height = ceil(float(in_height) / float(strides[1]))

    out_width = ceil(float(in_width) / float(strides[2]))

And

    For the VALID padding, the output height and width are computed as:

    out_height = ceil(float(in_height - filter_height + 1) / float(strides1))

    out_width = ceil(float(in_width - filter_width + 1) / float(strides[2]))

猜你喜欢

转载自blog.csdn.net/u013498583/article/details/81359629