TF CNN 示例中的感受野算法
Receptive Field Arithmetic on the TF CNN example
下面是tensorflow提供的代码。我将描述我目前对感受野大小变化的理解,如果有人能告诉我我的误解在哪里,我将不胜感激。
概览:
[28,28] -> 32 [24,24] -> 32 [12,12] -> 2048 [8,8]
长版:
- 从 [28,28] 数组开始
- 第一个卷积层有32个卷积核大小为[5,5]的滤波器所以输出是32[24,24]秒。
- 内核为[2,2]、步长为2的池化层保持数组的数量但减小了大小,因此输出为32[12,12]s。
- 下一个卷积层有 64 个大小为 [5,5] 的过滤器,所以我们最终得到 2048 [8,8]s
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"
,这意味着没有填充。
下面是tensorflow提供的代码。我将描述我目前对感受野大小变化的理解,如果有人能告诉我我的误解在哪里,我将不胜感激。
概览: [28,28] -> 32 [24,24] -> 32 [12,12] -> 2048 [8,8]
长版:
- 从 [28,28] 数组开始
- 第一个卷积层有32个卷积核大小为[5,5]的滤波器所以输出是32[24,24]秒。
- 内核为[2,2]、步长为2的池化层保持数组的数量但减小了大小,因此输出为32[12,12]s。
- 下一个卷积层有 64 个大小为 [5,5] 的过滤器,所以我们最终得到 2048 [8,8]s
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"
,这意味着没有填充。