Why conv2d in tensorflow gives an output has the same shape as input
<p>According to this Deep Learning course <a href="http://cs231n.github.io/convolutional-networks/#conv" rel="nofollow">http://cs231n.github.io/convolutional-networks/#conv</a>, It says that if there is an input <code>x</code> with shape <code>[W,W]</code> (where <code>W = width = height</code>) goes through a <strong>Convolutional Layer</strong> with <strong>filter</strong> shape <code>[F,F]</code>and <strong>stride</strong> <code>S</code>, the <strong>Layer</strong> will return an <code>output</code> with shape <code>[(W-F)/S +1, (W-F)/S +1]</code></p>

<p>However, when I'm trying to follow the tutorial of the Tensorflow: <a href="https://www.tensorflow.org/versions/r0.11/tutorials/mnist/pros/index.html" rel="nofollow">https://www.tensorflow.org/versions/r0.11/tutorials/mnist/pros/index.html</a>. There seems to have difference of the function <code>tf.nn.conv2d(inputs, filter, stride)</code></p>

<p>Whatever how do I change my filter size, <code>conv2d</code> will constantly return me a value with the same shape as the input.</p>

<p>In my case, I am using the <code>MNIST</code> dataset which indicates that every image has size <code>[28,28]</code>(ignoring <code>channel_num = 1</code>)</p>

<p>but after I defining the first <code>conv1</code> layers, I used the <code>conv1.get_shape()</code> to see its output, it gives me <code>[28,28, num_of_filters]</code></p>

<p>Why is this? I thought the return value should follow the formula above.</p>

<hr>

<p>Appendix: Code snippet </p>

<pre><code>#reshape x from 2d to 4d

x_image = tf.reshape(x, [-1, 28, 28, 1]) #[num_samples, width, height, channel_num]

## define the shape of weights and bias
w_shape = [5, 5, 1, 32] #patch_w, patch_h, in_channel, output_num(out_channel)
b_shape =          [32] #bias only need to be consistent with output_num

## init weights of conv1 layers
W_conv1 = weight_variable(w_shape)
b_conv1 = bias_variable(b_shape)

## first layer x_iamge-&gt;conv1/relu-&gt;pool1

#Our convolutions uses a stride of one 
#and are zero padded 
#so that the output is the same size as the input
h_conv1 = tf.nn.relu(
    conv2d(x_image, W_conv1) + b_conv1
                    )

print 'conv1.shape=',h_conv1.get_shape() 
## conv1.shape= (?, 28, 28, 32) 
## I thought conv1.shape should be (?, (28-5)/1+1, 24 ,32)

h_pool1 = max_pool_2x2(h_conv1) #output 32 num
print 'pool1.shape=',h_pool1.get_shape() ## pool1.shape= (?, 14, 14, 32)
</code></pre>