Tensorflow 卷积神经网络 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.

 

  • 5
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值