The pretrained vision model menu
torchvision ships pretrained weights for dozens of architectures. The four families you'll reach for most:
- ResNet (resnet18/34/50/101/152) — the workhorse. Reliable, well-understood, fast on every backend. Default starting point for any new task.
- EfficientNet (efficientnet_b0..b7, _v2_*) — better accuracy/parameter trade-off. Use when model size matters (mobile deployment, large-scale inference).
- ConvNeXt (convnext_tiny/small/base/large) — modern ConvNet that closed the gap to ViTs. Surprisingly strong, faster than ViT for the same accuracy.
- Vision Transformer (vit_b_16/32, vit_l_16, vit_h_14) — Transformer applied to images. State-of-the-art for many tasks but more data-hungry than CNNs and slightly slower per parameter.
Adapting them — head replacement is architecture-specific
Each architecture exposes its classifier head differently:
- ResNet:
model.fc = nn.Linear(model.fc.in_features, num_classes) - EfficientNet:
model.classifier[1] = nn.Linear(model.classifier[1].in_features, num_classes) - ConvNeXt:
model.classifier[2] = nn.Linear(model.classifier[2].in_features, num_classes) - ViT:
model.heads.head = nn.Linear(model.heads.head.in_features, num_classes)
The pattern: print(model) first, find the final Linear, replace it. The convention is consistent enough that you can write a small helper function once and reuse it.