Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What does nn.MaxPool2d do in a neural network?
nn.MaxPool2d takes the largest value from each small region (window) of the input image or feature map. It helps reduce size and keeps the strongest features.
Click to reveal answer
beginner
How does nn.AvgPool2d differ from nn.MaxPool2d?
nn.AvgPool2d calculates the average value in each small region instead of the maximum. It smooths the features rather than picking the strongest one.
Click to reveal answer
beginner
What is the role of the kernel_size parameter in nn.MaxPool2d and nn.AvgPool2d?
kernel_size sets the size of the window that moves over the input to pool values. For example, kernel_size=2 means a 2x2 window.
Click to reveal answer
intermediate
Why do we use pooling layers like nn.MaxPool2d in convolutional neural networks?
Pooling layers reduce the size of data, making the model faster and less likely to overfit. Max pooling keeps important features by selecting the strongest signals.
Click to reveal answer
intermediate
What happens if you set stride smaller than kernel_size in nn.MaxPool2d?
The pooling windows will overlap, which means some input values are pooled multiple times. This can give smoother downsampling but increases computation.
Click to reveal answer
What does nn.MaxPool2d do with each pooling window?
ACalculates the average value
BSums all values
CSelects the maximum value
DSelects the minimum value
✗ Incorrect
nn.MaxPool2d selects the maximum value in each window to keep the strongest feature.
Which parameter controls the size of the pooling window in nn.AvgPool2d?
Akernel_size
Bstride
Cpadding
Ddilation
✗ Incorrect
kernel_size sets the size of the window that moves over the input for pooling.
What is the main effect of applying pooling layers in CNNs?
AReduce data size and keep important features
BAdd noise to data
CIncrease data size
DConvert images to grayscale
✗ Incorrect
Pooling reduces data size and keeps important features, helping the model run faster and generalize better.
If stride is equal to kernel_size in nn.MaxPool2d, what happens?
APooling windows overlap
BPooling windows do not overlap
CPooling windows skip input values
DPooling windows double in size
✗ Incorrect
When stride equals kernel_size, windows move without overlapping, covering the input evenly.
Which pooling method smooths features by averaging values?
Ann.BatchNorm2d
Bnn.MaxPool2d
Cnn.Conv2d
Dnn.AvgPool2d
✗ Incorrect
nn.AvgPool2d calculates the average in each window, smoothing the features.
Explain in your own words how nn.MaxPool2d and nn.AvgPool2d work and why they are useful in CNNs.
Think about how these layers look at small parts of the image and summarize them.
You got /5 concepts.
Describe the effect of changing kernel_size and stride in nn.MaxPool2d on the output size and feature selection.
Consider how the window moves and how big it is.
You got /5 concepts.
Practice
(1/5)
1. What is the main difference between nn.MaxPool2d and nn.AvgPool2d in PyTorch?
easy
A. nn.MaxPool2d selects the maximum value in each window, while nn.AvgPool2d computes the average value.
B. nn.MaxPool2d computes the average value, while nn.AvgPool2d selects the maximum value.
C. Both perform the same operation but on different input shapes.
D. nn.MaxPool2d increases data size, nn.AvgPool2d decreases it.
Solution
Step 1: Understand pooling operations
nn.MaxPool2d picks the highest value in each sliding window, emphasizing strong features. nn.AvgPool2d calculates the average, smoothing the features.
Step 2: Compare their behavior
Max pooling keeps the strongest signals, while average pooling provides a smoothed summary of the window.
Final Answer:
nn.MaxPool2d selects the maximum value in each window, while nn.AvgPool2d computes the average value. -> Option A
4. Identify the error in the following PyTorch code using nn.AvgPool2d:
import torch
import torch.nn as nn
input_tensor = torch.randn(1, 1, 5, 5)
pool = nn.AvgPool2d(kernel_size=2, stride=3)
output = pool(input_tensor)
print(output.shape)
medium
A. No error; code runs correctly
B. Kernel size must be odd
C. Stride cannot be greater than kernel size
D. Input tensor shape is invalid
Solution
Step 1: Check parameter validity
PyTorch allows stride to be different from kernel size, including stride > kernel size. Kernel size can be even or odd. Input tensor shape is valid.
Step 2: Confirm code runs without error
Running this code produces a valid output shape without errors.
Final Answer:
No error; code runs correctly -> Option A
Quick Check:
Stride can differ from kernel size [OK]
Hint: Stride can be any positive int, not limited by kernel size [OK]
Common Mistakes:
Assuming stride must be <= kernel size
Thinking kernel size must be odd
Believing input shape is invalid for pooling
5. You want to reduce the spatial size of a feature map from (1, 1, 10, 10) to (1, 1, 3, 3) using pooling layers. Which combination of nn.MaxPool2d or nn.AvgPool2d with kernel size and stride will achieve this output shape?
hard
A. Use nn.MaxPool2d with kernel_size=2, stride=2 twice sequentially
B. Use nn.AvgPool2d with kernel_size=4, stride=4
C. Use nn.MaxPool2d with kernel_size=3, stride=3
D. Use nn.AvgPool2d with kernel_size=5, stride=5
Solution
Step 1: Calculate output size for kernel_size=3, stride=3