title: Keras Conv2D dimension calculation when padding=same
body: <p>Just trying to use Keras but I am a bit confused about the Conv2D function when using padding=same. I wonder if someone can help me to figure out how p (padding) value is set when padding="same"?</p>
  
  <p>Here is a code example:</p>
  
  
  
  <pre class="lang-python prettyprint-override"><code># X.shape = (3, 2, 2, 2) at this point
  
  X = Conv2D(filters=4, kernel_size=(2, 2), strides = (1, 1), padding = 'same', 
             name = 'apply_conv_2', 
             kernel_initializer = glorot_uniform())(X)
  X = BatchNormalization(axis = 3, name = 'apply_bn_2')(X)
  X = Activation('relu')(X)
  
  # X.shape = (3, 2, 2, 4) at this point
  </code></pre>
  
  <p>You should read dimensions as (nr_samples, height, width, nr_channels)</p>
  
  <p>If padding="same", height and width will remain the same. But I am a bit confused which value p takes here when calculating dimensions.</p>
  
  <p>For instance, the dimension height should be calculated as:</p>
  
  <p>height_next = ROUND_DOWN((( height_prev + 2xpadding - kernel_size ) / stride) + 1)</p>
  
  <p>height_next = height_prev = 2.
  And as seen above, kernel_size = 2 above. And stride = 1.</p>
  
  <p>So.. 
  2 = ROUND_DOWN(((2 + 2xpadding - 2) / 1) + 1)</p>
  
  <p>If padding is 2, then the result becomes 5, which is not equal to 2.
  If padding is 1, then result is 3 which is not equal to 2.
  If padding is 0, then result is 1, which is not equal to 2.</p>
  
  <p>I assume padding needs to be an integer value.</p>
  
  <p>How does Keras calculate padding value here? </p>