天天看点

TensorFlow strides 参数讨论

更详细地讨论见 stackoverflow:Tensorflow Strides Argument

卷积神经网络(CNN)在 TensorFlow 实现时涉及的 tf.nn.con2d(二维卷积)、tf.nn.max_pool(最大池化)、tf.nn.avg_pool(平均池化)等操作都有关于

strides

(步长)的指定,因为无论是卷积操作还是各种类型的池化操作,都是某种形式的滑动窗口(sliding window)处理,这就要求指定从当前窗口移动下一个窗口位置的移动步长。

TensorFlow 文档关于

strides

的说明如下:

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

首先要求 strides 为长度不小于 4 的整数构成的 list,

strides

参数表示的是滑窗在输入张量各个维度上的移动步长。

而且一般要求

strides

的参数,

strides[0] = strides[3] = 1

具体什么含义呢?

一般而言,对于输入张量(input tensor)有四维信息:[batch, height, width, channels](分别表示 batch_size, 也即样本的数目,单个样本的行数和列数,样本的频道数,rgb图像就是三维的,灰度图像则是一维),对于一个二维卷积操作而言,其主要作用在

height, width

上。

strides

参数确定了滑动窗口在各个维度上移动的步数。一种常用的经典设置就是要求,

strides[0]=strides[3]=1

  • strides[0] = 1,也即在 batch 维度上的移动为 1,也就是不跳过任何一个样本,否则当初也不该把它们作为输入(input)
  • strides[3] = 1,也即在 channels 维度上的移动为 1,也就是不跳过任何一个颜色通道;