【发布时间】:2017-10-26 20:34:45
【问题描述】:
当我使用 tensorflow 教程学习深度 mnist 时,在对输入图像进行卷积和池化后,我遇到了关于输出大小的问题。在教程中我们可以看到:
W_conv1 = weight_variable([5, 5, 1, 32])
b_conv1 = bias_variable([32])
x_image = tf.reshape(x, [-1,28,28,1])
We then convolve x_image with the weight tensor, add the bias, apply
the ReLU function, and finally max pool. The max_pool_2x2 method
will reduce the image size to 14x14.
h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1)
h_pool1 = max_pool_2x2(h_conv1)
我认为处理输入图像有两个步骤:第一个卷积和第二个最大池?!卷积后,输出大小为(28-5+1)*(28-5+1) = 24*24。那么最大池化的输入大小为 24*24。如果池大小为 2*2,则输出大小为 (24/2)*(24/2) = 12*12 而不是 14*14。那有意义吗?请告诉我有关如何计算卷积和池化后输出大小的详细信息。非常感谢。 下图是论文中CNN的过程。 image of the CNN process
我已经明白问题出在哪里了。
def conv2d(x, W):
return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME')
padding = 'SAME' 表示输出大小与输入大小相同----图像大小。然后卷积后输出大小为28*28,池化后最终输出大小为(28/2)*(28/2) = 14*14。但是如何解释下面关于padding = 'SAME'的代码:
def max_pool_2x2(x):
return tf.nn.max_pool(x, ksize=[1, 2, 2, 1],
strides=[1, 2, 2, 1], padding='SAME')
【问题讨论】:
-
tensorflow的教程在这里:tensorflow.org/get_started/mnist/…
-
我已经明白问题出在哪里了。
标签: python tensorflow