Challenge - 5 Problems
Pooling Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of MaxPool2d with stride and kernel size
What is the output tensor shape after applying nn.MaxPool2d with kernel_size=2 and stride=2 on a tensor of shape (1, 1, 4, 4)?
PyTorch
import torch import torch.nn as nn input_tensor = torch.arange(16, dtype=torch.float32).reshape(1, 1, 4, 4) pool = nn.MaxPool2d(kernel_size=2, stride=2) output = pool(input_tensor) output.shape
Attempts:
2 left
💡 Hint
MaxPool2d reduces spatial dimensions by sliding a window and taking the max value.
✗ Incorrect
MaxPool2d with kernel_size=2 and stride=2 divides each spatial dimension by 2, so 4x4 becomes 2x2.
❓ Predict Output
intermediate2:00remaining
Output values of AvgPool2d on a simple tensor
What is the output tensor after applying nn.AvgPool2d with kernel_size=2 and stride=2 on the following tensor?
[[[[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]]]]
PyTorch
import torch import torch.nn as nn input_tensor = torch.tensor([[[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]]], dtype=torch.float32) pool = nn.AvgPool2d(kernel_size=2, stride=2) output = pool(input_tensor) output
Attempts:
2 left
💡 Hint
Average pooling computes the mean of each 2x2 block.
✗ Incorrect
Each 2x2 block's average is calculated: top-left block (1+2+5+6)/4=3.5, top-right (3+4+7+8)/4=5.5, bottom-left (9+10+13+14)/4=11.5, bottom-right (11+12+15+16)/4=13.5.
❓ Model Choice
advanced2:00remaining
Choosing pooling layer for noise reduction
You want to reduce noise in image features while keeping the strongest signals. Which pooling layer is best?
Attempts:
2 left
💡 Hint
Think about which pooling keeps the highest values.
✗ Incorrect
MaxPool2d selects the maximum value in each region, preserving strong signals and reducing noise better than averaging.
❓ Hyperparameter
advanced2:00remaining
Effect of stride on output size in MaxPool2d
If you apply nn.MaxPool2d with kernel_size=3 and stride=1 on an input tensor of shape (1, 1, 7, 7), what will be the output shape?
Attempts:
2 left
💡 Hint
Output size = (input_size - kernel_size) / stride + 1
✗ Incorrect
Output height and width = (7 - 3)/1 + 1 = 5, so output shape is (1, 1, 5, 5).
🔧 Debug
expert3:00remaining
Identifying error in pooling layer usage
What error will this code raise?
import torch
import torch.nn as nn
input_tensor = torch.randn(1, 3, 32, 32)
pool = nn.AvgPool2d(kernel_size=5, stride=2, padding=3)
output = pool(input_tensor)
PyTorch
import torch import torch.nn as nn input_tensor = torch.randn(1, 3, 32, 32) pool = nn.AvgPool2d(kernel_size=5, stride=2, padding=3) output = pool(input_tensor)
Attempts:
2 left
💡 Hint
Check the relationship between padding and kernel size in pooling layers.
✗ Incorrect
Padding cannot be larger than half the kernel size in PyTorch pooling layers, otherwise a RuntimeError occurs.