Challenge - 5 Problems
Flatten and Dense Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output shape after Flatten layer
Given the following TensorFlow model snippet, what is the shape of the tensor after the Flatten layer?
TensorFlow
import tensorflow as tf model = tf.keras.Sequential([ tf.keras.layers.InputLayer(input_shape=(28, 28, 3)), tf.keras.layers.Flatten(), ]) output_shape = model.output_shape
Attempts:
2 left
💡 Hint
Multiply the dimensions except the batch size: 28 * 28 * 3.
✗ Incorrect
The Flatten layer converts the 3D input (28x28x3) into a 1D vector per sample. 28*28*3 = 2352, so the output shape is (None, 2352).
❓ Model Choice
intermediate2:00remaining
Choosing the correct Dense layer output size
You want to build a classification model with 10 classes. Which Dense layer configuration correctly outputs the class scores?
Attempts:
2 left
💡 Hint
For multi-class classification, output layer size equals number of classes with softmax activation.
✗ Incorrect
A Dense layer with 10 units and softmax activation outputs probabilities for each of the 10 classes, suitable for multi-class classification.
❓ Hyperparameter
advanced2:00remaining
Effect of changing units in Dense layer
What is the effect of increasing the number of units in a Dense layer from 64 to 256 in a neural network?
Attempts:
2 left
💡 Hint
More units mean more parameters and complexity.
✗ Incorrect
Increasing units increases the number of parameters, allowing the model to learn more complex patterns but also increasing overfitting risk.
❓ Metrics
advanced2:00remaining
Interpreting accuracy with Dense output layer
A model with a Dense output layer of 3 units and softmax activation achieves 85% accuracy on validation data. What does this accuracy represent?
Attempts:
2 left
💡 Hint
Accuracy measures correct predictions over total samples.
✗ Incorrect
Accuracy is the fraction of samples where the predicted class matches the true class, here among 3 classes.
🔧 Debug
expert2:00remaining
Identifying error in model with Flatten and Dense layers
Consider this model code snippet. What error will it raise when running model.fit()?
TensorFlow
import tensorflow as tf model = tf.keras.Sequential([ tf.keras.layers.Dense(64, activation='relu', input_shape=(28, 28, 3)), tf.keras.layers.Flatten(), tf.keras.layers.Dense(10, activation='softmax') ]) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy')
Attempts:
2 left
💡 Hint
Dense layers expect 2D inputs (batch_size, features).
✗ Incorrect
The first Dense layer receives a 3D input (28,28,3) which causes a ValueError because Dense expects 2D input. Flatten should come before Dense.