TF CNN 示例中的感受野算法

Receptive Field Arithmetic on the TF CNN example

下面是tensorflow提供的代码。我将描述我目前对感受野大小变化的理解,如果有人能告诉我我的误解在哪里,我将不胜感激。

概览: [28,28] -> 32 [24,24] -> 32 [12,12] -> 2048 [8,8]

长版:

2048 [8,8]s 不是后续代码中表示的。我的错误是什么?感谢所有指导。

  # Input Layer
  input_layer = tf.reshape(features["x"], [-1, 28, 28, 1])

  # Convolutional Layer #1
  conv1 = tf.layers.conv2d(
      inputs=input_layer,
      filters=32,
      kernel_size=[5, 5],
      padding="same",
      activation=tf.nn.relu)

  # Pooling Layer #1
  pool1 = tf.layers.max_pooling2d(inputs=conv1, pool_size=[2, 2], strides=2)

  # Convolutional Layer #2 and Pooling Layer #2
  conv2 = tf.layers.conv2d(
      inputs=pool1,
      filters=64,
      kernel_size=[5, 5],
      padding="same",
      activation=tf.nn.relu)             
  pool2 = tf.layers.max_pooling2d(inputs=conv2, pool_size=[2, 2], strides=2)

  # Dense Layer
  pool2_flat = tf.reshape(pool2, [-1, 7 * 7 * 64])
  dense = tf.layers.dense(inputs=pool2_flat, units=1024, activation=tf.nn.relu)
  dropout = tf.layers.dropout(
      inputs=dense, rate=0.4, training=mode == tf.estimator.ModeKeys.TRAIN)

conv2d 层使用 padding="same",这意味着输入用零填充,以便输出大小相同。为了获得您期望的结果,我们将使用 padding="valid",这意味着没有填充。