0
0
TensorFlowml~20 mins

CNN architecture for image classification in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
CNN Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output shape after Conv2D layer
Given the following TensorFlow code snippet for a CNN layer, what is the output shape of the tensor after the Conv2D layer?
TensorFlow
import tensorflow as tf
input_tensor = tf.random.uniform([1, 64, 64, 3])
conv_layer = tf.keras.layers.Conv2D(filters=16, kernel_size=3, strides=2, padding='same')
output_tensor = conv_layer(input_tensor)
print(output_tensor.shape)
A(1, 64, 64, 16)
B(1, 31, 31, 16)
C(1, 62, 62, 16)
D(1, 32, 32, 16)
Attempts:
2 left
💡 Hint
Remember that padding='same' keeps the spatial size divided by stride.
Model Choice
intermediate
1:30remaining
Choosing activation function for CNN output layer
You are building a CNN to classify images into 10 categories. Which activation function should you use in the output layer to get probabilities for each class?
ASoftmax
BReLU
CSigmoid
DTanh
Attempts:
2 left
💡 Hint
The output should represent probabilities that sum to 1.
Hyperparameter
advanced
2:00remaining
Effect of increasing kernel size in Conv2D
In a CNN, what is the most likely effect of increasing the kernel size from 3x3 to 7x7 in the first Conv2D layer?
AThe model captures larger spatial features but increases parameters and computation
BThe model reduces overfitting by decreasing parameters
CThe model output size increases significantly
DThe model training speed increases due to fewer computations
Attempts:
2 left
💡 Hint
Think about how kernel size affects receptive field and parameter count.
Metrics
advanced
2:00remaining
Interpreting CNN training accuracy and loss
During CNN training for image classification, you observe training accuracy steadily increasing but validation accuracy plateaus and then decreases. What does this indicate?
AThe dataset is too small to train
BThe model is underfitting the training data
CThe model is overfitting the training data
DThe learning rate is too low
Attempts:
2 left
💡 Hint
Think about what it means when training improves but validation worsens.
🔧 Debug
expert
2:30remaining
Identifying error in CNN model definition
What error will this TensorFlow CNN model code raise when run?
TensorFlow
import tensorflow as tf
model = tf.keras.Sequential([
    tf.keras.layers.Conv2D(32, kernel_size=3, activation='relu', input_shape=(28, 28, 1)),
    tf.keras.layers.MaxPooling2D(pool_size=2),
    tf.keras.layers.Flatten(),
    tf.keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
ARuntimeError: Missing Flatten layer before Dense
BValueError: Input shape must have 3 dimensions for Conv2D
CTypeError: activation function 'relu' not recognized
DNo error, model compiles successfully
Attempts:
2 left
💡 Hint
Check the input_shape parameter for Conv2D layer.