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]))
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章