Skip to main content
Xenors Xenors
Home › Data Science › CNN Architectures: AlexNet, VGG16, ResNet & Inception

Module 9: Advanced Deep LearningBy Ashok Kumar Yadav4 min read

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.

Diagram comparing AlexNet, VGG16, Inception and ResNet convolutional neural network architectures
Quick answer: AlexNet proved deep CNNs work on GPUs, VGG16 showed that stacks of small 3x3 filters scale well, Inception ran several filter sizes in parallel, and ResNet added skip connections so networks with 50 to 150 layers train reliably.

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.

ModelYearDepthKey idea
AlexNet20128ReLU, dropout, GPU training
VGG16201416Stacked 3x3 convolutions
Inception v1201422Parallel 1x1, 3x3, 5x5 branches
ResNet-50201550Skip (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.

Compare parameter counts of the four architectures
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.

Practical tipWhen the input and output shapes differ, use a 1x1 convolution on the shortcut so the two tensors can be added.
A minimal residual block
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.

Classify one image with top-3 predictions
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

Practice example
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

Practice example
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.

Written by Ashok Kumar Yadav
Ashok Kumar Yadav writes Xenors tutorials on applied AI, programming and data workflows. Every lesson is built around code you can run and check yourself.
GitHub · LinkedIn

Continue exploring