Challenge - 5 Problems
Conv2D Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output shape of Conv2D layer
Given the following Conv2D layer in TensorFlow, what is the output shape when the input shape is (32, 32, 3)?
TensorFlow
import tensorflow as tf layer = tf.keras.layers.Conv2D(filters=16, kernel_size=3, strides=1, padding='valid') input_shape = (1, 32, 32, 3) output = layer(tf.random.uniform(input_shape)) print(output.shape)
Attempts:
2 left
💡 Hint
Remember that 'valid' padding means no padding is added, so output size shrinks by kernel_size - 1.
✗ Incorrect
With 'valid' padding and kernel size 3, the output height and width are input_size - kernel_size + 1 = 32 - 3 + 1 = 30. The number of filters is 16, so output shape is (1, 30, 30, 16).
❓ Model Choice
intermediate1:30remaining
Choosing padding for same output size
You want a Conv2D layer that keeps the input height and width unchanged after convolution. Which padding option should you use?
Attempts:
2 left
💡 Hint
Padding adds pixels around the input to keep output size same as input.
✗ Incorrect
'same' padding adds zeros around the input so the output height and width remain the same as input when stride is 1.
❓ Hyperparameter
advanced2:30remaining
Effect of stride on output size
If you apply a Conv2D layer with kernel_size=5, padding='valid', and stride=2 on an input of shape (64, 64, 3), what will be the output height and width?
Attempts:
2 left
💡 Hint
Output size formula: floor((input_size - kernel_size)/stride) + 1
✗ Incorrect
Output size = floor((64 - 5)/2) + 1 = floor(59/2) + 1 = 29 + 1 = 30. The output height and width are 30 x 30.
❓ Metrics
advanced2:00remaining
Calculating number of parameters in Conv2D
How many trainable parameters does a Conv2D layer have with 10 filters, kernel size 3x3, input channels 3, and use_bias=True?
Attempts:
2 left
💡 Hint
Parameters = (kernel_height * kernel_width * input_channels * filters) + filters (if bias used).
✗ Incorrect
Parameters = (3*3*3*10) + 10 = 270 + 10 = 280.
🔧 Debug
expert2:30remaining
Identifying error in Conv2D input shape
What error will this code raise?
import tensorflow as tf
layer = tf.keras.layers.Conv2D(8, 3)
input_data = tf.random.uniform((32, 3, 32, 3))
output = layer(input_data)
Attempts:
2 left
💡 Hint
TensorFlow Conv2D expects input shape with channels last by default.
✗ Incorrect
The input shape (32, 3, 32, 3) is invalid for the default 'channels_last' data format because the height and width dimensions are swapped. TensorFlow expects input shape (batch, height, width, channels). This will raise a TypeError indicating the expected input shape.