卷积神经网络 tf.nn.conv2d函数的strides参数理解

首先 Tensorflow里面对于conv2d的原型声明:

conv2d(input, fileter, strides, padding, use_cudnn_on_gpu=None, name=None)

除了参数name用以指定该操作的name,其中5个参数一一解释如下:

(1)input: 指定需要做卷积的输入图像,它要求是 Tensor,具有 [batch, in_height, in_width, in_channels] 这样的形状 (shape).

具体含义是指  “训练时,一个batch的图片数量,图片高度,图片宽度,图像通道数(彩色图像为3通道,灰度图像为1通道)”。注

意 input 是一个四维的 Tensor,要求为float32 或者是 float64.

(2)filter: 相当于CNN的卷积核,它要求是一个Tensor,具有[filter_height, filter_width, in_channels, out_channels]这样的shape.

具体含义是指  “滤波器的高度,滤波器的宽度,图像通道数,滤波器个数”,类型和参数 input 相同。值得注意的是:第三维的

in_channels,就是参数 input 的第四维。

(3)strides:卷积时在图像上每一维得步长,是一个一维的向量,长度为4。

默认设置strides [1, x, y, 1], The typical use sets the first (the batch) and last (the depth) stride to 1.

batch = 1指在样本上的步长为1,depth = 1 指在通道上的步长为1,即 strides[0] = strides[3] = 1;

strides[1] = strides[2]="你设置的步长大小"。

(4)padding: string 类型的变量,决定了卷积方式只能是 SAME 或者是 VALID这两种类型。'VALID' 表示边缘不填充,'SAME'

表示边缘填充 。

(5)use_cudnn_on_gpu:bool 类型,是否使用 cudnn 加速,默认为 true。

关于strides参数, Why strides [1, x, y, 1] for convnets

在 stackoverflow 上有人解释的非常好,链接在此

 strides:[ A list of ints that has length >= 4. The stride of the sliding window for each dimension of the input tensor.]

The first 1 is the batch: You don't usually want to skip over examples in your batch, or you shouldn't have included them in the first place. :)

The last 1 is the depth of the convolution: You don't usually want to skip inputs, for the same reason.

The conv2d operator is more general, so you could create convolutions that slide the window along other dimensions, but that's not a typical use in convnets. The typical use is to use them spatially.

猜你喜欢

转载自blog.csdn.net/qq_28632639/article/details/86588843
今日推荐