About the shape changing using ConvTranspose2d

When we use nn.ConvTranspose2d to build the Generator, we have such code:


And then run the test code

The shape of “test_uns_noise” which also be the input of test_hidden_block is 100x10x1x1, and the output shape is 100x20x4x4.
During this process, I can understand “image” 1x1 is extended to 4x4 by the kernel (4x4).
But how to interpret the shape change of the channels ?

Hey @apricot,
We will have 20 kernels of shape (10, 4, 4), each of which will be applied on (10, 1, 1) block of input, leading to a (1, 4, 4) output, and since, we have 20 such kernels, hence, the shape of the output will be (20, 4, 4). And hence, our final 100 blocks of shape (10, 1, 1) will be transformed into 100 blocks of shape (20, 4, 4), i.e., (100, 10, 1, 1) to (100, 20, 4, 4). I hope this helps. For more reference, you can refer to ConvTranspose2d — PyTorch 1.10.1 documentation

1 Like