liveBook · Manning

Fine-tuning

As explained in Build a Text-to-Image Generator (from Scratch)

Fine-tuning is adapting a pretrained model to a new task by updating selected parameters, often only the task-specific output layers.

Fine-tuning adapts a pretrained model to a specialized task by preserving learned features and updating selected parameters instead of training every parameter from random initialization. It trades the data, time, and computation of training from scratch for a faster downstream adaptation. section 13.3.2 section 13.5

A typical fine-tuning workflow proceeds through these stages:

  • Start with a pretrained model whose learned representations suit the new problem; ResNet50 supplies general visual features learned from ImageNet. section 13.3.2 section 13.3.3
  • Define a representative, diverse, and clearly labeled dataset; deepfake detection uses real and fake images. section 13.4
  • Freeze existing parameters and replace the output head with one matching the target labels. A 1,000-class ImageNet head becomes a two-logit real/fake head. section 13.3.2 section 13.4.2
  • Train the new head with batches, a loss function, and an optimizer while evaluating validation loss after each epoch. section 13.4.2
  • Use early stopping and retain the best validation weights to reduce overfitting and wasted computation. section 13.4 section 13.4.2

Adapting ResNet50 for deepfake detection

Load pretrained ResNet50 weights through torchvision, inspect its inference behavior, then freeze its parameters and replace its fully connected layer with a small multilayer head ending in two outputs. Train with cross-entropy and Adam, validate after every epoch, and stop after three consecutive validation-loss failures. The resulting detector achieved 93.73% accuracy on the reported unseen test set. section 13.3.3 section 13.4.2 section 13.5

Figure 13.3 Modified ResNet50 architecture for deepfake detection. All original layers of ResNet50 are retained, except for the last fully connected output layer. The original output head (with 1,000 output channels) is replaced with a new head (with 2 output channels), producing logits for the “real” and “fake” classes. Parameters in the new output layer are initialized randomly and trained on our dataset. All other parameters are inherited from the pretrained model and kept frozen during fine-tuning.

Use the architecture diagram to trace which ResNet50 layers remain unchanged, which output head is replaced, and where trainable parameters are concentrated. section 13.3.2

How Build a Text-to-Image Generator (from Scratch) covers it

How deep it goes
Explains freezing, head replacement, training, validation, and early stopping, but focuses on output-head adaptation rather than full-network retraining.
Examples
Uses ResNet50 to classify sample images, then adapts it to distinguish real images from AI-generated deepfakes.
What it assumes
Assumes deep-learning and image-classification familiarity while demonstrating pretrained-model loading, preprocessing, freezing, training, and validation.
What you can do after
Apply it via PyTorch and torchvision to build a specialized image classifier with frozen pretrained features and a trainable task head.
How it connects
Connects transfer learning, pretrained models, image classification, ResNet50, ImageNet, validation, and early stopping.

Also explained in

Compare how 37 books explain fine-tuning →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Text-to-Image Generator (from Scratch). The section links point to the parts of the book it draws on.