Flatten Output Shape Calculator
Calculate the output shape of nn.Flatten in PyTorch. See how a multi-dimensional tensor collapses into a 2D tensor for fully-connected layers.
Built by Michael Lip
Frequently Asked Questions
What does nn.Flatten do to the shape?
nn.Flatten() collapses all dimensions except the batch dimension into one. For input [batch, C, H, W], output is [batch, C*H*W]. For example, [32, 64, 7, 7] becomes [32, 3136].
When do I need to use Flatten?
Use Flatten when transitioning from convolutional layers (which output 4D tensors) to fully-connected Linear layers (which expect 2D tensors). It is the bridge between the feature extraction and classification parts of a CNN.
What is the start_dim parameter?
nn.Flatten(start_dim=1) flattens from dimension 1 onward (default). You can change start_dim to flatten only certain dimensions. For example, Flatten(start_dim=2) on [B, C, H, W] gives [B, C, H*W].
About This Tool
This tool is part of HeyTensor, a free suite of PyTorch and deep learning utilities. All calculations run entirely in your browser — no data is sent to any server. The source code is open on GitHub.
Contact
HeyTensor is built and maintained by Michael Lip. For questions or feedback, email [email protected].