Challenge - 5 Problems
Keras Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Model Choice
intermediate2:00remaining
Choosing the correct Keras model for image classification
You want to build a simple image classifier using Keras in TensorFlow. Which model type is best suited for this task?
Attempts:
2 left
💡 Hint
Think about the type of data images are and which layers process spatial information.
✗ Incorrect
Images have spatial structure best captured by convolutional layers (Conv2D). A Sequential model with Conv2D and Dense layers is a simple and effective choice for image classification.
❓ Predict Output
intermediate2:00remaining
Output shape of a Keras Conv2D layer
What is the output shape of this Keras layer when input shape is (32, 32, 3)?
TensorFlow
from tensorflow.keras.layers import Conv2D layer = Conv2D(filters=16, kernel_size=3, strides=1, padding='valid') output_shape = layer.compute_output_shape((None, 32, 32, 3)) print(output_shape)
Attempts:
2 left
💡 Hint
Padding='valid' means no padding, so output size shrinks by kernel_size - 1.
✗ Incorrect
With kernel size 3 and valid padding, output height and width = input - 3 + 1 = 30. Filters define output channels = 16.
❓ Hyperparameter
advanced2:00remaining
Choosing the right optimizer for faster convergence
You train a Keras model but it learns very slowly. Which optimizer change is most likely to speed up training without losing stability?
Attempts:
2 left
💡 Hint
Adam adapts learning rates per parameter and often converges faster than vanilla SGD.
✗ Incorrect
Adam optimizer combines momentum and adaptive learning rates, usually speeding up convergence compared to SGD.
❓ Metrics
advanced2:00remaining
Interpreting Keras model accuracy during training
After training a Keras classification model, the training accuracy is 95% but validation accuracy is 70%. What does this indicate?
Attempts:
2 left
💡 Hint
High training accuracy but much lower validation accuracy usually means the model memorizes training data.
✗ Incorrect
Overfitting happens when the model learns training data too well but fails to generalize to new data, causing lower validation accuracy.
🔧 Debug
expert3:00remaining
Identifying the cause of a Keras model training error
You run this Keras code and get a ValueError: 'Input 0 of layer dense_1 is incompatible with the layer: expected axis -1 of input shape to have value 64 but received input with shape (None, 32)'. What is the most likely cause?
TensorFlow
from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense, Flatten model = Sequential([ Flatten(input_shape=(8,8)), Dense(64, activation='relu'), Dense(10, activation='softmax') ]) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy') model.fit(x_train, y_train, epochs=5)
Attempts:
2 left
💡 Hint
Flatten converts (8,8) to 64 features. The error says input to Dense has shape (None, 32), which is unexpected.
✗ Incorrect
The error means the data fed to the model has shape (None, 8, 4) or similar, not (None, 8, 8). Flatten outputs 64 features, but input data shape is inconsistent.