Conv2D padding in TensorFlow and PyTorch

I am trying to convert TensorFlow model to PyTorch but having trouble with padding. My code for for relevant platforms are as follow:

TensorFlow

conv1 = tf.layers.conv2d(
                inputs=input_layer,
                filters=32,
                kernel_size=[5, 5],
                padding="same",
                activation=tf.nn.relu,
                name = "conv1")

PyTorch

conv1 = nn.Conv2d(1, 32, kernel_size=5, stride=1, padding=2)

I have few questions:

  1. Are the above codes equivalent?
  2. How many paddings are added on left/right/top/bottom if we use same padding in tensorflow?
  3. How many paddings are added on left/right/top/bottom if we use padding=2 in pytorch?
  4. If the above two code snippets are not equivalent then how can we make the same conv layer?

Thanks in advance.

  1. Not entirely, since the TF implementation seems to add a relu to the conv layer while this is not the case in PyTorch.
  2. I guess 2 on each side, but you would have to confirm it in TF.
  3. 2 on each side.