liveBook · Manning

Pretraining

As explained in Inside Deep Learning: Math, Algorithms, Models

A strategy of training a model on a source dataset before adapting it to a downstream task.

Pretraining initializes a model with weights learned on a source dataset before adapting it to a downstream task. For image classification, a ResNet pretrained on ImageNet starts with convolutional filters already shaped by a large set of images; replacing its final layer supplies a new, randomly initialized classifier for the target labels. section 13.2.1

The intuition is that early convolutional layers learn broadly useful visual features, such as edges, colors, and changes in color. Those features can provide a better starting point than random weights when learning a new image task. section 13.2.1

Pretrained weights can be used in different ways during adaptation:

  • A warm start allows the pretrained weights to change during training; frozen weights remain constant. These choices offer different benefits depending on how much data is available. section 13.6
  • A warm start is a general optimization strategy, not a synonym for transfer learning: initial weights need only be expected to be closer to the desired solution than random weights. section 13.2.3
model_pretrained = torchvision.models.resnet18(pretrained=True)     #1
model_pretrained.fc = nn.Linear(model_pretrained.fc.in_features, 2) #2

This PyTorch example loads pretrained ResNet-18 weights, then replaces the final layer with a two-output classifier. section 13.2.1

How Inside Deep Learning: Math, Algorithms, Models covers it

How deep it goes
Explains pretrained convolutional features and classifier replacement, then summarizes warm and frozen weights without deriving their training mechanics.
Examples
Demonstrates ImageNet-pretrained ResNet-18 adapted to cat-versus-dog classification with a replacement final layer.
What you can do after
Apply it via torchvision.models by loading pretrained ResNet-18 weights and replacing its final classification layer.
How it connects
Connects pretraining to transfer learning, warm starts, fine-tuning, convolutional networks, and transformers.

Also explained in

Compare how 14 books explain pretraining →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Inside Deep Learning: Math, Algorithms, Models. The section links point to the parts of the book it draws on.