Challenge - 5 Problems
Padding and Stride Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output shape with SAME padding and stride 2
Consider a 2D convolution layer in TensorFlow with input shape (1, 28, 28, 3), kernel size 3x3, stride 2, and padding='SAME'. What is the output shape after applying this convolution?
TensorFlow
import tensorflow as tf input_tensor = tf.random.uniform((1, 28, 28, 3)) conv_layer = tf.keras.layers.Conv2D(filters=5, kernel_size=3, strides=2, padding='SAME') output = conv_layer(input_tensor) print(output.shape)
Attempts:
2 left
💡 Hint
Padding='SAME' keeps output size roughly input size divided by stride.
✗ Incorrect
With padding='SAME' and stride=2, output height and width are ceil(input_dim / stride). For 28 input, output is ceil(28/2)=14.
🧠 Conceptual
intermediate1:30remaining
Effect of stride on output size
In a convolutional neural network, if you increase the stride from 1 to 3 while keeping padding='VALID' and kernel size fixed, what happens to the output feature map size?
Attempts:
2 left
💡 Hint
Think about how stride controls the step size when sliding the kernel.
✗ Incorrect
Increasing stride makes the kernel jump more pixels, reducing the number of positions it fits, so output size decreases.
❓ Metrics
advanced2:00remaining
Calculate output size with padding='VALID' and stride 2
Given an input image of size 32x32, a convolutional layer with kernel size 5x5, stride 2, and padding='VALID', what is the output width and height?
Attempts:
2 left
💡 Hint
Use formula: output = floor((input - kernel + 1) / stride)
✗ Incorrect
Output size = floor((32 - 5 + 1) / 2) = floor(28 / 2) = 14.
🔧 Debug
advanced2:00remaining
Identify the error in convolution output shape calculation
A user writes this code to compute output shape after a convolution:
input_shape = (1, 64, 64, 3)
kernel_size = 7
stride = 2
padding = 'VALID'
output_height = (input_shape[1] - kernel_size) // stride
output_width = (input_shape[2] - kernel_size) // stride
print(f'Output shape: (1, {output_height}, {output_width}, 10)')
What is wrong with this calculation?
Attempts:
2 left
💡 Hint
Recall the formula for output size with VALID padding.
✗ Incorrect
The formula for output size with VALID padding is floor((input - kernel + 1) / stride), missing the +1 causes wrong output size.
❓ Model Choice
expert2:30remaining
Choosing padding and stride for preserving spatial dimensions
You want to design a convolutional layer that keeps the input image size exactly the same after convolution. Which combination of padding and stride should you choose?
Attempts:
2 left
💡 Hint
Think about how padding and stride affect output size.
✗ Incorrect
Padding='SAME' with stride=1 keeps output size equal to input size by adding zero padding as needed.