Challenge - 5 Problems
Conv2d Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output shape after Conv2d layer
What is the output shape of the tensor after applying this Conv2d layer?
Input tensor shape: (batch_size=1, channels=3, height=32, width=32)
Layer: nn.Conv2d(in_channels=3, out_channels=6, kernel_size=5, stride=1, padding=0)
Input tensor shape: (batch_size=1, channels=3, height=32, width=32)
Layer: nn.Conv2d(in_channels=3, out_channels=6, kernel_size=5, stride=1, padding=0)
PyTorch
import torch import torch.nn as nn conv = nn.Conv2d(in_channels=3, out_channels=6, kernel_size=5, stride=1, padding=0) input_tensor = torch.randn(1, 3, 32, 32) output = conv(input_tensor) print(output.shape)
Attempts:
2 left
💡 Hint
Remember the formula for output size: (W - K + 2P) / S + 1
✗ Incorrect
The output height and width are calculated as (32 - 5 + 0) / 1 + 1 = 28. The output channels are 6 as set by out_channels.
❓ Model Choice
intermediate2:00remaining
Choosing Conv2d parameters for same input-output size
You want a Conv2d layer that keeps the input height and width the same after convolution.
Input shape: (batch_size=1, channels=3, height=28, width=28)
Which Conv2d layer parameters will achieve this?
Input shape: (batch_size=1, channels=3, height=28, width=28)
Which Conv2d layer parameters will achieve this?
Attempts:
2 left
💡 Hint
Padding can help keep the size same if chosen correctly.
✗ Incorrect
Using kernel_size=3, stride=1, and padding=1 keeps the height and width unchanged because (28 - 3 + 2*1)/1 + 1 = 28.
❓ Hyperparameter
advanced2:00remaining
Effect of stride on Conv2d output size
Given an input tensor of shape (1, 3, 64, 64), which Conv2d layer will produce an output with height and width equal to 16?
Attempts:
2 left
💡 Hint
Use the formula: output = (W - K + 2P)/S + 1 and solve for output=16.
✗ Incorrect
For option A: (64 - 3 + 0)/4 + 1 = 15.25 + 1 = 16.25, which floors to 16 in PyTorch. Others produce different sizes.
🔧 Debug
advanced2:00remaining
Identifying error in Conv2d layer usage
What error will this code raise when run?
conv = nn.Conv2d(in_channels=3, out_channels=6, kernel_size=3)
input_tensor = torch.randn(1, 1, 28, 28)
output = conv(input_tensor)
conv = nn.Conv2d(in_channels=3, out_channels=6, kernel_size=3)
input_tensor = torch.randn(1, 1, 28, 28)
output = conv(input_tensor)
PyTorch
import torch import torch.nn as nn conv = nn.Conv2d(in_channels=3, out_channels=6, kernel_size=3) input_tensor = torch.randn(1, 1, 28, 28) output = conv(input_tensor)
Attempts:
2 left
💡 Hint
Check if input channels match the Conv2d in_channels parameter.
✗ Incorrect
The input tensor has 1 channel but Conv2d expects 3 channels, causing a runtime error.
🧠 Conceptual
expert3:00remaining
Understanding dilation effect in Conv2d
How does increasing the dilation parameter in nn.Conv2d affect the receptive field and output size?
Choose the correct statement.
Choose the correct statement.
Attempts:
2 left
💡 Hint
Think of dilation as spacing out kernel elements, making the filter cover a larger area.
✗ Incorrect
Dilation spaces out kernel elements, increasing receptive field. Without adjusting padding, output size shrinks because effective kernel size grows.