tf.nn.conv2d(input, filter, strides, padding, use_cudnn_on_gpu=None, data_format=None, name=None)
Arguments
input shape: [batch, in_height, in_width, in_channels]
filter shape: [filter_height, filter_width, in_channels, out_channels]
stride: Must have strides[0] = strides[3] = 1. For the most common case of the same horizontal and vertices strides, strides = [1, stride, stride, 1].
padding: A string from: “SAME“, “VALID“. The type of padding algorithm to use.
注意:
Input shape 和 filter shape 不同, input shape是普通图片数据集的四个维度,分别是 batch height width 和channel。
Filter shape 是 height, width, input channel, output channel。 filter 改变channel, 而不会改变batch size。 filter 和 stride 一起改变了height 和 width。
stride 的 batch (stride[0]) 和 channel (stride[3]) 都是1, height 和 width相等。
padding的方法有两种:
1、如果padding = ‘VALID’
new_height = new_width = (W – F + 1) / S (结果向上取整)
VALID方式不会在原有输入上加padding
2、如果padding = ‘SAME’
new_height = new_width = W / S (结果向上取整)
最常见的如果stride = [1 , 1, 1, 1] 图片会加padding使得输入与输出的height width 不变