Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What does 'input shape' mean in a TensorFlow model?
Input shape is the size and structure of the data that the model expects to receive. It tells the model how many features or dimensions each input example has.
Click to reveal answer
beginner
How do you specify the input shape in a TensorFlow Keras Sequential model?
You specify the input shape in the first layer using the 'input_shape' argument, for example: Dense(10, input_shape=(5,)) means each input has 5 features.
Click to reveal answer
intermediate
Why is the batch size not included in the input shape specification?
Batch size is flexible and can change during training or prediction. Input shape only describes the shape of one example, excluding the batch size.
Click to reveal answer
beginner
What is the input shape for a grayscale image of size 28x28 pixels?
The input shape is (28, 28, 1) where 28x28 is the image size and 1 is the number of color channels (grayscale).
Click to reveal answer
intermediate
How does input shape differ for sequence data like text or time series?
For sequence data, input shape usually includes the sequence length and the number of features per step, for example (100, 1) for 100 time steps with 1 feature each.
Click to reveal answer
In TensorFlow Keras, how do you specify the input shape for a model expecting 10 features per example?
Ainput_shape=(10,)
Binput_shape=10
Cinput_shape=[10]
Dinput_shape=(1,10)
✗ Incorrect
The input shape should be a tuple describing the shape of one example, so (10,) means 10 features.
Which part of the input shape is flexible and usually not specified in the model?
ANumber of features
BNumber of channels
CSequence length
DBatch size
✗ Incorrect
Batch size can vary during training or prediction, so it is not fixed in the input shape.
What input shape would you use for a color image of size 64x64 pixels?
A(3, 64, 64)
B(64, 64)
C(64, 64, 3)
D(64, 3)
✗ Incorrect
Color images usually have 3 channels (red, green, blue), so the shape is (height, width, channels).
For a sequence of 50 time steps with 2 features each, what is the input shape?
A(2,)
B(50, 2)
C(50,)
D(2, 50)
✗ Incorrect
The input shape for sequence data is (sequence length, features per step).
If you forget to specify input shape in the first layer of a Sequential model, what happens?
AModel will automatically infer input shape from data
BModel will raise an error when building
CModel will use default input shape (1,)
DModel will train but with random input shape
✗ Incorrect
Keras can infer input shape from the first batch of data if not specified explicitly.
Explain how to specify input shape for different types of data in TensorFlow models.
Think about images, tabular data, and sequences.
You got /4 concepts.
Describe why batch size is not part of the input shape and how it affects model training.
Consider how data is fed in groups during training.
You got /4 concepts.
Practice
(1/5)
1. What does the input_shape parameter specify in a TensorFlow Keras model?
easy
A. The size and format of the input data the model expects
B. The number of layers in the model
C. The learning rate for training
D. The number of output classes
Solution
Step 1: Understand the role of input_shape
The input_shape tells the model what size and type of data it will receive as input.
Step 2: Differentiate from other parameters
Other parameters like number of layers, learning rate, or output classes do not describe input data format.
Final Answer:
The size and format of the input data the model expects -> Option A
Quick Check:
input_shape = data size/type [OK]
Hint: Input shape defines data size, not layers or learning rate [OK]
Common Mistakes:
Confusing input_shape with number of layers
Thinking input_shape sets learning rate
Mixing input_shape with output classes
2. Which of the following is the correct way to specify an input shape for a model expecting 28x28 grayscale images in TensorFlow?
easy
A. tf.keras.layers.Input(shape=(28, 28))
B. tf.keras.layers.Input(shape=(28, 28, 1))
C. tf.keras.layers.Input(shape=(1, 28, 28))
D. tf.keras.layers.Input(shape=(784,))
Solution
Step 1: Identify the correct shape for grayscale images
Grayscale images have height, width, and 1 channel, so shape is (28, 28, 1).
Step 2: Check each option
tf.keras.layers.Input(shape=(28, 28, 1)) matches (28, 28, 1). tf.keras.layers.Input(shape=(28, 28)) misses channel dimension. tf.keras.layers.Input(shape=(1, 28, 28)) has wrong channel position. tf.keras.layers.Input(shape=(784,)) flattens input, not raw shape.
Final Answer:
tf.keras.layers.Input(shape=(28, 28, 1)) -> Option B
Quick Check:
Grayscale image shape = (height, width, 1) [OK]
Hint: Grayscale images need channel=1 as last dimension [OK]
Common Mistakes:
Omitting the channel dimension
Placing channel dimension first incorrectly
Using flattened input shape instead of 2D+channel
3. What will be the output shape of the following TensorFlow model's first layer?
model = tf.keras.Sequential([
tf.keras.layers.Input(shape=(32, 32, 3)),
tf.keras.layers.Conv2D(16, 3)
])
A. The shape argument should be a single tuple, not separate values
B. The input layer must specify batch size explicitly
C. The channel dimension should be first, not last
D. Input layers cannot have 3D shapes
Solution
Step 1: Check the syntax of shape argument
The shape parameter must be a single tuple, e.g., (28, 28, 1), not separate arguments.
Step 2: Verify other options
Batch size is optional and not required here. Channel last is standard. Input layers can have 3D shapes for images.
Final Answer:
The shape argument should be a single tuple, not separate values -> Option A
Quick Check:
Shape must be tuple like (28, 28, 1) [OK]
Hint: Use parentheses to group shape dimensions as a tuple [OK]
Common Mistakes:
Passing shape dimensions as separate arguments
Forcing batch size in input shape
Misplacing channel dimension
5. You want to build a model that accepts variable-length sequences of 10 features each. Which input shape specification is correct for the first layer?
hard
A. tf.keras.layers.Input(shape=(10,))
B. tf.keras.layers.Input(shape=(10, None))
C. tf.keras.layers.Input(shape=(None, 10))
D. tf.keras.layers.Input(shape=(None,))
Solution
Step 1: Understand variable-length sequences
Variable-length means the sequence length is unknown, so use None for that dimension.
Step 2: Identify feature dimension position
Each sequence element has 10 features, so feature dimension is fixed at 10, sequence length is variable.
Step 3: Match shape to (sequence_length, features)
The correct shape is (None, 10), meaning variable sequence length and fixed 10 features per step.
Final Answer:
tf.keras.layers.Input(shape=(None, 10)) -> Option C
Quick Check:
Variable length = None in first dimension [OK]
Hint: Use None for variable dimension, fixed size for features [OK]