Challenge - 5 Problems
CNN Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output shape after convolution and pooling
Given the following PyTorch CNN layer definitions, what is the output shape after passing a batch of 16 RGB images of size 64x64 through the layers?
PyTorch
import torch import torch.nn as nn conv = nn.Conv2d(in_channels=3, out_channels=8, kernel_size=3, stride=1, padding=1) pool = nn.MaxPool2d(kernel_size=2, stride=2) x = torch.randn(16, 3, 64, 64) x = conv(x) x = pool(x) output_shape = x.shape
Attempts:
2 left
💡 Hint
Remember that padding keeps the spatial size same before pooling, and pooling halves the height and width.
✗ Incorrect
The convolution with padding=1 and kernel_size=3 keeps the height and width at 64. The max pooling with kernel_size=2 and stride=2 halves the height and width to 32. The batch size is 16 and output channels are 8.
❓ Model Choice
intermediate2:00remaining
Choosing the correct CNN layer sequence
Which of the following PyTorch CNN layer sequences correctly applies two convolutional layers followed by a max pooling layer?
Attempts:
2 left
💡 Hint
Check the order of layers and the input/output channels for each convolution.
✗ Incorrect
Option D correctly applies Conv2d from 3 to 16 channels, then from 16 to 32 channels, then max pooling. Other options have wrong order or channel sizes.
❓ Hyperparameter
advanced2:00remaining
Effect of kernel size on output dimension
If a convolutional layer has input size 28x28, stride=1, padding=0, and kernel_size=5, what will be the output spatial size?
Attempts:
2 left
💡 Hint
Use the formula: output = (input - kernel + 2*padding)/stride + 1
✗ Incorrect
Output size = (28 - 5 + 0)/1 + 1 = 24. So output is 24x24.
❓ Metrics
advanced2:00remaining
Interpreting CNN training accuracy and loss
During CNN training for image classification, if the training loss decreases steadily but the validation accuracy plateaus early, what does this indicate?
Attempts:
2 left
💡 Hint
Think about what it means when training improves but validation does not.
✗ Incorrect
Decreasing training loss with stagnant validation accuracy suggests the model fits training data well but fails to generalize, indicating overfitting.
🔧 Debug
expert3:00remaining
Identifying error in CNN forward pass
What error will this PyTorch CNN forward method raise when given input of shape (10, 3, 32, 32)?
PyTorch
import torch import torch.nn as nn class SimpleCNN(nn.Module): def __init__(self): super().__init__() self.conv1 = nn.Conv2d(3, 16, 3) self.pool = nn.MaxPool2d(2) self.fc1 = nn.Linear(16 * 15 * 15, 10) def forward(self, x): x = self.pool(self.conv1(x)) x = x.view(-1, 16 * 15 * 15) x = self.fc1(x) return x model = SimpleCNN() input_tensor = torch.randn(10, 3, 32, 32) output = model(input_tensor)
Attempts:
2 left
💡 Hint
Check the size after conv and pooling before reshaping with view.
✗ Incorrect
After conv1 with kernel=3 and default stride=1, input 32x32 becomes 30x30. MaxPool2d(2) halves it to 15x15. So x shape is (10,16,15,15). The view tries to reshape to (10, 16*16*16=4096), but actual features are 16*15*15=3600, causing RuntimeError.