Converting Keras (Tensorflow) convolutional neural networks to PyTorch convolutional networks?
Keras and PyTorch use different arguments for padding: Keras requires a string to be input, while PyTorch works with numbers. What is the difference, and how can one be translated into another (what code gets the equivalent result in either framework)?

PyTorch also takes the args in_channels, out_chanels while keras only takes an argument called filters. What does 'filters' mean?

Regarding padding, 

Keras => 'valid' - no padding; 
         'same'  - input is padded so that the output shape is same as input shape

Pytorch => you explicitly specify the padding

Valid padding

&gt;&gt;&gt; model = keras.Sequential()
&gt;&gt;&gt; model.add(keras.layers.Conv2D(filters=10, kernel_size=3, padding='valid', input_shape=(28,28,3)))
&gt;&gt;&gt; model.layers[0].output_shape
(None, 26, 26, 10)

&gt;&gt;&gt; x = torch.randn((1,3,28,28))
&gt;&gt;&gt; conv = torch.nn.Conv2d(in_channels=3, out_channels=10, kernel_size=3)
&gt;&gt;&gt; conv(x).shape
torch.Size([1, 10, 26, 26])


Same padding

&gt;&gt;&gt; model = keras.Sequential()
&gt;&gt;&gt; model.add(keras.layers.Conv2D(filters=10, kernel_size=3, padding='same', input_shape=(28,28,3)))
&gt;&gt;&gt; model.layers[0].output_shape
(None, 28, 28, 10)

&gt;&gt;&gt; x = torch.randn((1,3,28,28))
&gt;&gt;&gt; conv = torch.nn.Conv2d(in_channels=3, out_channels=10, kernel_size=3, padding=1)
&gt;&gt;&gt; conv(x).shape
torch.Size([1, 10, 28, 28])


W - Input Width, F - Filter(or kernel) size, P - padding, S - Stride, Wout - Output width

Wout = ((W−F+2P)/S)+1

Similarly for Height. With this formula, you can calculate the amount of padding required to retain the input width or height in the output.

http://cs231n.github.io/convolutional-networks/

Regarding in_channels, out_chanels and filters,

filters is the same as out_channels. In Keras, the in_channels is automatically inferred from the previous layer shape or input_shape(in case of first layer).
