CNN Architectures: AlexNet, VGG16, ResNet & Inception
Four architectures shaped modern computer vision. This lesson explains what each one changed, how to read their layer structure, and how to load and inspect them in PyTorch.
How CNN architectures evolved
AlexNet (2012) won ImageNet with 8 layers, ReLU activations and dropout. VGG16 (2014) replaced large filters with repeated 3x3 convolutions and reached 16 weight layers. GoogLeNet/Inception (2014) used parallel branches to capture patterns at several scales. ResNet (2015) introduced residual learning and made very deep networks trainable.
| Model | Year | Depth | Key idea |
|---|---|---|---|
| AlexNet | 2012 | 8 | ReLU, dropout, GPU training |
| VGG16 | 2014 | 16 | Stacked 3x3 convolutions |
| Inception v1 | 2014 | 22 | Parallel 1x1, 3x3, 5x5 branches |
| ResNet-50 | 2015 | 50 | Skip (residual) connections |
Load pretrained models in PyTorch
torchvision ships all four families with ImageNet weights. Count parameters first so you understand the cost of each choice before training or fine-tuning anything.
import torch
from torchvision import models
nets = {
"alexnet": models.alexnet(weights=models.AlexNet_Weights.DEFAULT),
"vgg16": models.vgg16(weights=models.VGG16_Weights.DEFAULT),
"resnet50": models.resnet50(weights=models.ResNet50_Weights.DEFAULT),
"googlenet": models.googlenet(weights=models.GoogLeNet_Weights.DEFAULT),
}
for name, m in nets.items():
n = sum(p.numel() for p in m.parameters())
print(f"{name:10s} {n/1e6:6.1f}M parameters")Why ResNet skip connections work
A residual block learns a correction F(x) and outputs F(x) + x. If the best transformation is close to identity, the block only has to push F(x) toward zero. Gradients also flow through the shortcut unchanged, which reduces the vanishing-gradient problem in deep stacks.
import torch.nn as nn
class BasicBlock(nn.Module):
def __init__(self, c_in, c_out, stride=1):
super().__init__()
self.conv1 = nn.Conv2d(c_in, c_out, 3, stride, 1, bias=False)
self.bn1 = nn.BatchNorm2d(c_out)
self.conv2 = nn.Conv2d(c_out, c_out, 3, 1, 1, bias=False)
self.bn2 = nn.BatchNorm2d(c_out)
self.relu = nn.ReLU(inplace=True)
self.short = nn.Identity()
if stride != 1 or c_in != c_out:
self.short = nn.Sequential(
nn.Conv2d(c_in, c_out, 1, stride, bias=False),
nn.BatchNorm2d(c_out))
def forward(self, x):
out = self.relu(self.bn1(self.conv1(x)))
out = self.bn2(self.conv2(out))
return self.relu(out + self.short(x))Run inference with ResNet-50
Always use the preprocessing that ships with the weights, otherwise accuracy drops silently.
import torch
from torchvision import models
from PIL import Image
weights = models.ResNet50_Weights.DEFAULT
model = models.resnet50(weights=weights).eval()
prep = weights.transforms()
img = Image.open("photo.jpg").convert("RGB")
with torch.no_grad():
probs = model(prep(img).unsqueeze(0)).softmax(1)[0]
top = probs.topk(3)
for p, i in zip(top.values, top.indices):
print(weights.meta["categories"][i], round(p.item(), 3))Which architecture should you choose?
Pick ResNet-50 as a strong default for transfer learning. Choose VGG16 only when you need simple, easy-to-visualise features, since it has about 138 million parameters. Use Inception-style models when multi-scale detail matters, and lighter networks such as MobileNet or EfficientNet when latency or memory is limited.
Hands-on practice
Run the examples in the downloadable Jupyter notebook. The extra checks below focus on mistakes that appear in real projects, not just syntax.
Compare parameter counts
from torchvision.models import resnet18, vgg16
for m in [resnet18(),vgg16()]:
print(type(m).__name__, sum(p.numel() for p in m.parameters()))ResNet ... ~11.7M VGG ... ~138M
Parameter count affects memory and deployment cost, not just accuracy.
Check tensor shape through a residual block
import torch
x=torch.randn(1,64,56,56)
print(x.shape)torch.Size([1, 64, 56, 56])
Residual addition requires compatible tensor shapes.
Self-check
- Can you explain why the first practice result is trustworthy rather than just plausible?
- What would you monitor or test before using this CNN Architectures workflow in production?
- Which assumption in the example would break first on a larger or messier dataset?
Frequently asked questions
Why is ResNet better than VGG16?
ResNet uses skip connections that let gradients flow through deep networks, so it reaches higher accuracy with far fewer parameters than VGG16.
What is the vanishing gradient problem?
In very deep networks the gradient can shrink as it is back-propagated through many layers, so early layers learn slowly. Residual connections give gradients a short path to those layers.
Can I use these CNNs for my own dataset?
Yes. Load pretrained weights, replace the final classifier layer with one sized for your classes, and fine-tune. See the transfer learning lesson for the full workflow.
Primary references
Use these official sources when exact syntax, defaults or definitions matter beyond the examples here.




















































































































































