Challenge - 5 Problems
Input Shape Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output shape of the model's first layer?
Consider the following TensorFlow Keras model code. What is the output shape of the first Dense layer?
TensorFlow
import tensorflow as tf model = tf.keras.Sequential([ tf.keras.layers.InputLayer(input_shape=(28, 28)), tf.keras.layers.Flatten(), tf.keras.layers.Dense(64, activation='relu') ]) output_shape = model.layers[2].output_shape
Attempts:
2 left
💡 Hint
Remember that Flatten changes the input shape before the Dense layer.
✗ Incorrect
The Flatten layer converts the input from (28, 28) to (784,), so the Dense layer outputs (None, 64) where None is the batch size.
❓ Model Choice
intermediate2:00remaining
Which input shape is correct for grayscale 32x32 images?
You want to build a CNN model in TensorFlow for grayscale images of size 32x32 pixels. Which input_shape argument is correct for the first Conv2D layer?
Attempts:
2 left
💡 Hint
TensorFlow expects channels last format by default.
✗ Incorrect
TensorFlow uses channels last format, so the input shape should be (height, width, channels). For grayscale, channels=1.
❓ Hyperparameter
advanced2:00remaining
What happens if input_shape is omitted in the first layer?
In TensorFlow Keras, what is the effect of not specifying input_shape in the first layer of a Sequential model?
Attempts:
2 left
💡 Hint
Think about how Keras can build models dynamically.
✗ Incorrect
If input_shape is not specified, Keras waits until it sees data to infer the input shape automatically.
🔧 Debug
advanced2:00remaining
Why does this model raise a shape error?
Given this model code, why does it raise a shape mismatch error when training?
TensorFlow
import tensorflow as tf model = tf.keras.Sequential([ tf.keras.layers.Dense(10, activation='relu', input_shape=(20,)), tf.keras.layers.Dense(5) ]) import numpy as np x = np.random.rand(32, 10) y = np.random.rand(32, 5) model.compile(optimizer='adam', loss='mse') model.fit(x, y, epochs=1)
Attempts:
2 left
💡 Hint
Check the input_shape argument and the shape of x.
✗ Incorrect
The model expects input vectors of length 20, but x has vectors of length 10, causing a shape mismatch error.
🧠 Conceptual
expert3:00remaining
Why specify batch size in Input layer for stateful RNNs?
In TensorFlow, why is it necessary to specify batch_size in the Input layer when building a stateful RNN model?
Attempts:
2 left
💡 Hint
Think about how RNN states are preserved across batches.
✗ Incorrect
Stateful RNNs keep hidden states between batches, so batch size must be fixed and known to maintain correct state alignment.