Reputation: 369
the image size is [m,32,32,3] (m = no. of training examples)
the filter size is [3,3,3,10]
stride = 1
padding = None
if I convolve this using tensorflow.nn.conv2d then the output shape should be this, according to the formula
out ={ ( 32 - 3 + 2*(0) ) / 1 }+ 1 = 30
so the output size should be [m, 30, 30, 10] but the output shape i am getting is [m, 32, 32, 10]
why is this happening?
# 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')
Upvotes: 1
Views: 583
Reputation: 14001
padding = "SAME" means:
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]]
padding = "VALID" means:
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]]
Last pixel got dropped in this case.
So padding "VALID" will give you the output you expect.
Upvotes: 3