Recall & Review
beginner
What is the purpose of a Flatten layer in a neural network?
A Flatten layer converts a multi-dimensional input (like an image) into a one-dimensional vector so it can be fed into a fully connected layer.
Click to reveal answer
beginner
How does the Flatten layer affect the shape of the input tensor?
It reshapes the input tensor from shape (batch_size, channels, height, width) to (batch_size, channels * height * width), keeping the batch size the same.
Click to reveal answer
beginner
Show a simple PyTorch code snippet to add a Flatten layer in a model.
import torch.nn as nn
model = nn.Sequential(
nn.Flatten(),
nn.Linear(28*28, 10)
)Click to reveal answer
beginner
Why do we need to flatten data before feeding it to a fully connected layer?
Fully connected layers expect 1D input vectors. Flattening changes multi-dimensional data into a 1D vector so the layer can process it.
Click to reveal answer
beginner
Can the Flatten layer change the batch size of the input?
No, the Flatten layer keeps the batch size unchanged. It only reshapes the other dimensions into one dimension.
Click to reveal answer
What does the Flatten layer do to the input tensor?
✗ Incorrect
The Flatten layer reshapes each sample into a 1D vector without changing batch size.
In PyTorch, which class is used to add a Flatten layer?
✗ Incorrect
PyTorch provides nn.Flatten to flatten input tensors.
Why is flattening necessary before a fully connected layer?
✗ Incorrect
Fully connected layers expect 1D vectors, so flattening prepares the data.
If input shape is (batch_size, 3, 32, 32), what will be the shape after Flatten?
✗ Incorrect
Flatten combines all dimensions except batch into one dimension.
Does Flatten layer change the batch size dimension?
✗ Incorrect
Flatten only reshapes other dimensions, batch size remains unchanged.
Explain in your own words what a Flatten layer does and why it is used in neural networks.
Think about how images are prepared before classification.
You got /4 concepts.
Write a simple PyTorch model snippet that includes a Flatten layer followed by a linear layer.
Use nn.Sequential for simplicity.
You got /3 concepts.