0
0
TensorFlowml~20 mins

Conv2D layers in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Conv2D Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
A(1, 30, 30, 16)
B(1, 32, 32, 16)
C(1, 31, 31, 16)
D(1, 29, 29, 16)
Attempts:
2 left
💡 Hint
Remember that 'valid' padding means no padding is added, so output size shrinks by kernel_size - 1.
Model Choice
intermediate
1: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?
A'same'
B'valid'
C'causal'
D'full'
Attempts:
2 left
💡 Hint
Padding adds pixels around the input to keep output size same as input.
Hyperparameter
advanced
2: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?
A31 x 31
B30 x 30
C32 x 32
D29 x 29
Attempts:
2 left
💡 Hint
Output size formula: floor((input_size - kernel_size)/stride) + 1
Metrics
advanced
2: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?
A300
B290
C270
D280
Attempts:
2 left
💡 Hint
Parameters = (kernel_height * kernel_width * input_channels * filters) + filters (if bias used).
🔧 Debug
expert
2: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)
ANo error, runs successfully
BValueError: Input rank must be 4, got 4 with wrong dimension order
CTypeError: Conv2D expects input shape (batch, height, width, channels)
DValueError: Input tensor has wrong shape, expected channels last
Attempts:
2 left
💡 Hint
TensorFlow Conv2D expects input shape with channels last by default.