1. 程式人生 > >tensorflow.nn.conv2d引數解釋(padding方式)

tensorflow.nn.conv2d引數解釋(padding方式)

conv2d的引數解釋:

tf.nn.conv2d(input, filter, strides, padding, use_cudnn_on_gpu=None, name=None)
除去name引數用以指定該操作的name,與方法有關的一共五個引數:

第一個引數input:指需要做卷積的輸入影象,它要求是一個Tensor,具有[batch, in_height, in_width, in_channels]這樣的shape,具體含義是[訓練時一個batch的圖片數量, 圖片高度, 圖片寬度, 影象通道數],注意這是一個4維的Tensor,要求型別為float32和float64其中之一

第二個引數filter:相當於CNN中的卷積核,它要求是一個Tensor,具有[filter_height, filter_width, in_channels, out_channels]這樣的shape,具體含義是[卷積核的高度,卷積核的寬度,影象通道數,卷積核個數],要求型別與引數input相同,filter的通道數要求與input的in_channels一致,有一個地方需要注意,第三維in_channels,就是引數input的第四維

第三個引數strides:卷積時在影象每一維的步長,這是一個一維的向量,長度4,strides[0]=strides[3]=1

第四個引數padding:string型別的量,只能是"SAME","VALID"其中之一,這個值決定了不同的卷積方式(後面會介紹)

第五個引數:use_cudnn_on_gpu:bool型別,是否使用cudnn加速,預設為true

結果返回一個Tensor,這個輸出,就是我們常說的feature map


padding方式

在這裡插入圖片描述
1、VALID是採用丟棄的方式,比如上述的input_width=13,只允許滑動2次,多餘的元素全部丟掉。
2、SAME的方式,採用的是補全的方式,對於上述的情況,允許滑動3次,但是需要補3個元素,左奇右偶,在左邊補一個0,右邊補2個0。
3、計算方法
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]))

For the VALID padding,
the output height and width are computed as:
out_height = ceil(float(in_height - filter_height + 1) / float(strides[1]))
out_width = ceil(float(in_width - filter_width + 1) / float(strides[2]))

本文來自 BYR_jiandong 的CSDN 部落格 ,全文地址請點選:https://blog.csdn.net/lujiandong1/article/details/53728053?utm_source=copy