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.Conv2d layer do in a neural network?
It applies a set of filters (kernels) to 2D input data (like images) to extract features such as edges or textures by sliding the filters over the input.
Click to reveal answer
beginner
What are the main parameters of nn.Conv2d?
The main parameters are: in_channels (input depth), out_channels (number of filters), kernel_size (filter size), stride (step size for sliding), padding (border added), and dilation (spacing inside the kernel).
Click to reveal answer
intermediate
How does padding affect the output size of nn.Conv2d?
Padding adds pixels around the input edges, allowing the filter to cover border areas. This can keep the output size the same as input or control shrinking.
Click to reveal answer
intermediate
What is the effect of stride in nn.Conv2d?
Stride controls how far the filter moves each step. A stride of 1 moves one pixel at a time, producing larger outputs. Larger strides skip pixels, reducing output size.
Click to reveal answer
beginner
Why do we use multiple filters (out_channels) in nn.Conv2d?
Multiple filters let the network learn different features from the input, like edges, colors, or shapes, improving the model's ability to understand complex patterns.
Click to reveal answer
What does the kernel_size parameter in nn.Conv2d specify?
AThe number of filters used
BThe size of the filter applied to the input
CThe step size of the filter movement
DThe amount of padding added
✗ Incorrect
kernel_size defines the height and width of the filter sliding over the input.
If stride is set to 2 in nn.Conv2d, what happens to the output size compared to stride 1?
AOutput size becomes zero
BOutput size doubles
COutput size stays the same
DOutput size halves approximately
✗ Incorrect
A stride of 2 moves the filter two pixels at a time, reducing output size roughly by half.
What is the role of padding in nn.Conv2d?
ATo add borders so output size can be controlled
BTo speed up training
CTo change the input channels
DTo increase the number of filters
✗ Incorrect
Padding adds pixels around input edges to control output size and preserve border information.
What does out_channels parameter control in nn.Conv2d?
ANumber of filters applied
BNumber of input channels
CSize of the input image
DStride length
✗ Incorrect
out_channels sets how many filters the layer uses, determining output depth.
Which of these is NOT a typical use of nn.Conv2d?
AExtracting image features
BReducing image size
CClassifying text documents directly
DDetecting edges in images
✗ Incorrect
nn.Conv2d is designed for 2D data like images, not for direct text classification.
Explain how the parameters kernel_size, stride, and padding affect the output size of an nn.Conv2d layer.
Think about how the filter moves and covers the input image.
You got /4 concepts.
Describe why multiple filters (out_channels) are used in nn.Conv2d and how they help the model learn.
Imagine looking at an image with different colored glasses to see different details.
You got /4 concepts.
Practice
(1/5)
1. What does the nn.Conv2d layer in PyTorch primarily do?
easy
A. It increases the image size by adding pixels.
B. It slides filters over images to find patterns.
C. It converts images to grayscale.
D. It sorts images by color intensity.
Solution
Step 1: Understand the role of convolution layers
Convolution layers slide small filters over input images to detect features like edges or textures.
Step 2: Match the function to the options
Only It slides filters over images to find patterns. correctly describes this sliding filter action, while others describe unrelated image operations.
Final Answer:
It slides filters over images to find patterns. -> Option B
Quick Check:
Convolution = sliding filters [OK]
Hint: Conv2d = sliding filters over images to find features [OK]
Common Mistakes:
Thinking Conv2d changes image size by adding pixels
Confusing Conv2d with image color adjustments
Assuming Conv2d sorts or rearranges pixels
2. Which of the following is the correct way to create a Conv2d layer with 3 input channels, 16 output channels, and a 3x3 kernel in PyTorch?
easy
A. nn.Conv2d(3, 16, kernel_size=3)
B. nn.Conv2d(16, 3, kernel_size=3)
C. nn.Conv2d(3, 16, kernel=3)
D. nn.Conv2d(input=3, output=16, size=3)
Solution
Step 1: Recall Conv2d constructor parameters
The correct order is nn.Conv2d(in_channels, out_channels, kernel_size).
Step 2: Check each option
nn.Conv2d(3, 16, kernel_size=3) matches the correct parameter order and uses the correct keyword for kernel size. The other options have wrong parameter order or incorrect keywords.
Padding=3 is large for kernel=3, causing output spatial size to increase unexpectedly, which is unusual and may cause unexpected behavior.
Final Answer:
Padding is too large causing output size to increase unexpectedly. -> Option C
Quick Check:
Large padding inflates output size [OK]
Hint: Check padding size relative to kernel size for output shape [OK]
Common Mistakes:
Thinking stride=2 is invalid
Assuming input shape is wrong for 3 channels
Believing kernel size must be odd always
5. You want to design a Conv2d layer that keeps the input image size (28x28) unchanged after convolution with a 5x5 kernel and stride 1. Which padding value should you use?