What Shape Does nn.Linear(512, 10) Output?
nn.Linear(512, 10) takes input shape [..., 512] and outputs [..., 10]. It has 512×10 + 10 = 5,130 parameters (5,120 weight values + 10 bias values).
How Linear Layers Work
A Linear layer performs output = input @ weight.T + bias. The weight matrix has shape (out_features, in_features) = (10, 512), and the bias has shape (10,). Only the last dimension of the input changes:
# Input shapes and corresponding outputs:
(32, 512) -> (32, 10) # batch of 32
(8, 16, 512) -> (8, 16, 10) # 3D input
(512,) -> (10,) # single sample
Parameter Count
Parameters = in_features * out_features + out_features
= 512 * 10 + 10
= 5,120 + 10
= 5,130
PyTorch Code
import torch
import torch.nn as nn
fc = nn.Linear(512, 10)
print(sum(p.numel() for p in fc.parameters())) # 5130
x = torch.randn(32, 512)
output = fc(x)
print(output.shape) # torch.Size([32, 10])
Common Use Case
This is a typical final classification head. The 512-dimensional feature vector (from a CNN backbone or other encoder) is mapped to 10 class logits. For CIFAR-10, ImageNet subsets, or digit classification, this is the standard pattern: features in, class scores out.