Tensorflow conv2d函数后的输出大小错误

Tensorflow conv2d函数后的输出大小错误,tensorflow,computer-vision,deep-learning,Tensorflow,Computer Vision,Deep Learning,图像大小为[m,32,32,3](m=训练示例的数量) 过滤器大小为[3,3,3,10] 步幅=1 填充=无 如果我使用tensorflow.nn.conv2d对其进行卷积,则根据公式,输出形状应为 out ={ ( 32 - 3 + 2*(0) ) / 1 }+ 1 = 30 所以输出大小应该是[m,30,30,10] 但是我得到的输出形状是[m,32,32,10] 为什么会这样 # convolution layer 1 c1 = tf.nn.conv2d(x_train, w1, str

图像大小为[m,32,32,3](m=训练示例的数量)

过滤器大小为[3,3,3,10]

步幅=1

填充=无

如果我使用tensorflow.nn.conv2d对其进行卷积,则根据公式,输出形状应为

out ={ ( 32 - 3 + 2*(0) ) / 1 }+ 1 = 30
所以输出大小应该是[m,30,30,10] 但是我得到的输出形状是[m,32,32,10]

为什么会这样

# convolution layer 1
c1 = tf.nn.conv2d(x_train, w1, strides = [1,1,1,1], padding = 'SAME')
print('c1 size: ', c1.shape)
# activation function for c1: relu
r1 = tf.nn.relu(c1)
# maxpooling
p1 = tf.nn.max_pool(r1, ksize = [1,2,2,1], strides = [1,2,2,1], padding = 'SAME')
padding=“SAME”表示:

padding=“VALID”表示:

在本例中,最后一个像素丢失

因此,填充“VALID”将为您提供预期的输出

input       = [1, 2, 3, 4, 5, 6, 7, 8]
filter size = [1, 3]
stride      = [2]

so input to filter will be [[1, 2, 3], [3, 4, 5], [5, 6, 7], [7, 8, 0]]
input       = [1, 2, 3, 4, 5, 6, 7, 8]
filter size = [1, 3]
stride      = [2]

so input to filter will be [[1, 2, 3], [3, 4, 5], [5, 6, 7]]