Search code examples
pythonpytorchconv-neural-networkconvolution

Understand weight in PyTorch convolution layer 1D


I am trying to understand the work of convolution layer 1D in PyTorch. I use Conv1D(750,14,1) with input channels equal to 750, output channels are 14 with kernel size 1. As I understand, the weight in convolution layer is the kernel/filter so in this case, the weight dimension is 14x1. but when I print the weight, the dimension is 14x750x1.

Is my understanding about weight for convolution layer wrong?


Solution

  • By default, convolution is performed in channel-wise fashion, in your case the number of input channels is 750, you requested 14 kernels of size 1x1 each.

    That's why the weight tensor is 14x750x1 (14 kernels of size 1 "running" through the whole depth of 750 input channels).