0

Based on my understanding, CNN output size for 1D is

output_size = (input_size - kernel_size + 2*padding)//stride + 1

Refer to PyTorch DQN Tutorial. In the tutorial, it uses 0 padding, which is fine. However, it computes the output size as follows:

        def conv2d_size_out(size, kernel_size = 5, stride = 2):
            return (size - (kernel_size - 1) - 1) // stride  + 1

It the above a mistake or is there something I missed?

Shern
  • 712
  • 1
  • 8
  • 20

1 Answers1

2

No, it's not a mistake because

size - (kernel_size - 1) - 1 = size - kernel_size + 2 * 0

with 0 as padding
(it's not code, its an equation sorry for the formatting)
I think the tutorial is using the formula for the output size from the official document which is

output_size = ((input_size + 2 * padding - dialation * (kernel_size - 1) - 1) // stride + 1

official doc for conv1d

ddoGas
  • 861
  • 7
  • 17
  • Thanks. Learnt something new - Dilation. Good visuals to explain dilated convolutions at https://github.com/vdumoulin/conv_arithmetic/blob/master/README.md – Shern Feb 26 '20 at 07:49