C1M4 - Determining the size of a flattened layer following conv_blocks

Hi,

I was able to find the solution using some simple troubleshooting of the Python error, but I am not sure how we are supposed to arrive there otherwise.

For the programming assignment for module 4, course 1, EX 3 we are supposed to build out a simpleCNN with module style programming. The progression of the conv_blocks is given to us: (3 → 32 → 64 → 128). No MaxPooling is involved in this case.

After these blocks we move to a linear classifier layer. What I’ve not been able to figure out yet is how we determine the input size of the first linear layer ? The second is straight forward. As said I got the number (can’t share it) through troubleshooting but the answer is not what I expected it to be (?).

@Nevermnd

this should help you

Each cnn block has maxpool2d with stride 2 which halves the height and width dimension from 32 to 16 to 8 to 4, making the last output of the 3rd convblock to have outchannel of 128 x4 x 4 features which is then passed to flatten layer to convert (2D to 1D) the 128, 4, 4 to 2048 =>input size of the first linear layer in the classifier.

1 Like

Oh, okay. I was only looking at the current block of code and forgot there was a MaxPool2d implemented in our earlier conv block definition. Now it makes sense.

Thanks.

1 Like