C1_M4_Lab_2 - SimpleCNN error explanation typo?

**When running the SimpleCNNDebug there is an expected error because of the missing Flatten layer. In the explanation of the error there is the following line:

The error occurs in the fully connected block**, specifically at the first linear layer: x_pool has shape [64, 32, 14, 14], but the linear layer expects an input of shape [64, 2048] (its weight matrix has shape [128, 6272]).

I think the linear layer expects an input of shape [64,6272], not [64,2048]. Or am I missing something?

1 Like

hi @Phil01

is the lab you are talking about is upgraded lab?

can you post screenshot of the complete error?

Hi @Deepti_Prasad ,

Here is the screenshot.

1 Like

@Phil01

You are right the input shape of fc1 sho5be [64, 6272] but if you notice the sentence you are highlighting mention the error occurs because x pool flattens he cnn output from 64,32,14,14 to 64,32, expecting input of fc1 to be 64,2048. Here it isnt pointing 64,2048 to be the right input shape of fc1, but that sentence is explaining because of the pooling layer, fc1 layer is expecting an incorrect shape of 64,2048 and weight matrix of 128, 6272

Probably sentence framing is more confusing.

I will tag the l.t.

Thanks you for reporting this.

regards

DP

@lucas.coutinho

can you check into learner’s raised query as the sentence explanation in the assignment looks more confusing between expectations and being right with error exception explanation more confusing.

When a pooling layer operates on a CNN layer output of shape (batch_size, channels, height, width), such as (64, 32, 14, 14):

64 is the batch size.

32 is the number of channels (feature maps).

14, 14 are the height and width of each feature map.

A pooling layer, for example, a 2x2 max pooling with a stride of 2, would reduce the height and width by half. In this case, the 14x14 feature maps would become 7x7. The number of channels (32) and the batch size (64) would remain unchanged. Therefore, the output shape after this pooling layer would be (64, 32, 7, 7).

The error in the input shape of fc1.linear occurs because fully connected (linear) layers expect a 1D input for each sample in the batch. The output of the pooling layer, (64, 32, 7, 7), is a 4D tensor. Before passing this to fc1.linear, it needs to be flattened.

Solution To resolve this, the output of the pooling layer must be reshaped or flattened.

Flattening the spatial dimensions and channels: into a single dimension for each sample in the batch.

The resulting shape would be (batch_size, channels * pooled_height * pooled_width).

For the example output of (64, 32, 7, 7), the flattened size for each sample would be 32 * 7 * 7 = 1568. The input shape for fc1.linear would then be (64, 1568) which then can be initialize the fc1.linear layer with nn.Linear(1568, output_features).

Regards

DP

When looking at the definition of the SimpleCNN we see that the input size is actually hardcoded to be 32 * 14 * 14 = 6272. After pooling the filters are 14x14.

When running the SimplCNNFixed, we see that the output after pooling is indeed [64,32,14,14] and after flattening [64,6272]. The fc1 happily accepts this input.

So, at no point is [64,2048] (or any other shape) expected for the fc1.

I still think the confusing text in the explanation can best be classified as a typo; if the number is changed to 6272, it all makes sense.

1 Like

hi @Phil01

Your first screenshot is from an earlier exercise where the output does throw an error, and the screenshot you showed does give a clean output because of the debug stel carried out after pooling, where the output was first flattened before passing it to the first linear later as I explained earlier.

Also I just checked the assignment, they seem to have remove that error statement completely.

Hi Deepti,

I just checked the notebook; text is still the same:

But, it is not that important I guess; probably shouldn’t spend more time on it.

Thanks

1 Like

@Phil01

yes looks like it still exist after I refreshed my notebook, and the statement is still visible.

please wait for @lucas.coutinho to have a look at this thread, they will update the correction

Hey @Deepti_Prasad @lucas.coutinho . This issue still exists in the notebook.

Please note I am only volunteer mentor and I have informed the staff.

also as the pop up message shows staff is on holiday till 2nd Jan, probably lucas might address this a bit later.

Adding @Mubsi to check if he can look into this.

@Mubsi, this lab required some corrections, please look into this once you are back.

thank you for reporting this @panekbartosz

Regards
DP

1 Like

Thanks all. I shall take a look at this in the coming week.

Best,
Mubsi

Thanks again for reporting this @panekbartosz, @Deepti_Prasad. I have fixed the typo and updated the lab.

I’m now going to close this thread as well.

2 Likes