Input and output channel doubt during tensor representation in a CNN

weight_tensor.shape[1]…how does it give # of input channels? Shouldn’t weight_tensor.shape[0] be that?
Same question for t.shape[0] inside the function “plot_filters_multi_channel”.

What I am essentially saying is 0 should be for input and 1 be for output # of channels…or I am missing something drastically here?

Quoting from the PyTorch documentation for that variable:

Conv2d.weight ( Tensor ) – the learnable weights of the module of shape (out\_channels, in\_channels, kernel\_size[0],kernel\_size[1])

This means that:

  • The first dimension corresponds to number of conv2d filters, which is nothing but the number of output channels of your convolutional layer
  • The second dimension corresponds to depth of the input tensor/image, which is nothing but the number of input channels
    • For example, if input tensor is a color picture, the correspoding RGB image will have 3 channels