0
0
PyTorchml~20 mins

Kernel size, stride, padding in PyTorch - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Convolution Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output shape after convolution with stride and padding
Given a 1-channel input tensor of shape (1, 1, 10, 10), a convolutional layer with kernel size 3, stride 2, and padding 1 is applied. What is the shape of the output tensor?
PyTorch
import torch
import torch.nn as nn

input_tensor = torch.randn(1, 1, 10, 10)
conv = nn.Conv2d(in_channels=1, out_channels=1, kernel_size=3, stride=2, padding=1)
output = conv(input_tensor)
output.shape
A(1, 1, 6, 6)
B(1, 1, 4, 4)
C(1, 1, 7, 7)
D(1, 1, 5, 5)
Attempts:
2 left
💡 Hint
Recall the formula for output size: floor((input + 2*padding - kernel_size)/stride) + 1
🧠 Conceptual
intermediate
1:30remaining
Effect of stride on convolution output size
Which statement correctly describes the effect of increasing the stride in a convolutional layer?
AIncreasing stride has no effect on output spatial dimensions.
BIncreasing stride increases the output spatial dimensions.
CIncreasing stride decreases the output spatial dimensions.
DIncreasing stride increases the number of output channels.
Attempts:
2 left
💡 Hint
Think about how stride controls the step size when sliding the kernel.
Metrics
advanced
2:00remaining
Padding effect on output size with kernel size 5
A convolutional layer uses kernel size 5 and stride 1 on an input of size 28x28. Which padding value will keep the output size the same as the input size?
APadding = 2
BPadding = 1
CPadding = 0
DPadding = 3
Attempts:
2 left
💡 Hint
Use the formula: output = floor((input + 2*padding - kernel_size)/stride) + 1
🔧 Debug
advanced
1:30remaining
Identify the error in convolution output size calculation
A user calculates the output size of a convolution as output = (input_size - kernel_size + 2*padding) / stride + 1 without flooring the division. What problem can this cause?
AOutput size will always be larger than input size.
BOutput size may be a float, which is invalid for tensor dimensions.
CPadding will be ignored during convolution.
DStride will be treated as 1 regardless of value.
Attempts:
2 left
💡 Hint
Tensor shapes must be integers.
Model Choice
expert
2:30remaining
Choosing padding and stride for specific output size
You want a convolutional layer with kernel size 4 on a 32x32 input to produce an output of size 15x15. Which combination of stride and padding achieves this?
AStride = 2, Padding = 0
BStride = 3, Padding = 0
CStride = 1, Padding = 1
DStride = 2, Padding = 1
Attempts:
2 left
💡 Hint
Use output size formula and solve for stride and padding.