Skip to main content...
ML → Deep Learning via PyTorch — the Garment Classifier
30 min

Day 39: Training the Garment Classifier: overfitting countermeasures

Training for real, with the overfitting toolkit

Now you train the actual Garment Classifier: pretrained ResNet backbone, your 8+ class dataset, the training loop from Day 29, validation from Day 30. The enemy is overfitting — with a few thousand images and millions of parameters, the model can memorize. You have a full toolkit of countermeasures, and stating them is a Stage 1 exit criterion.

  • Data augmentation (Day 38) — the strongest single defense; each epoch sees slightly different images.
  • Dropout — randomly zeroing activations during training so the model can't rely on any single neuron.
  • Weight decay (Day 32) — penalizing large weights toward simpler solutions.
  • Early stopping (Day 30) — halt at the best validation epoch.
  • Transfer learning + freezing (Day 37) — fewer trainable parameters means less to overfit.
Adding dropout to the classifier head, with weight decay in the optimizer
import torch.nn as nn

model.fc = nn.Sequential(
    nn.Dropout(0.5),                          # regularize the head
    nn.Linear(model.fc.in_features, 8),
)
optimizer = torch.optim.Adam(
    model.parameters(), lr=1e-4, weight_decay=1e-4  # L2 regularization
)

Add countermeasures one at a time

Don't throw every regularizer in at once — you won't know what helped. Establish a baseline, then add augmentation, measure; add dropout, measure. This is the Continuous-tracks discipline the roadmap enforces from Stage 3: every change re-runs the evaluation, and improvement is a measured number, not a hunch.

Key terms

Dropout
Randomly zeroing a fraction of activations during training so the network cannot depend on any single neuron, reducing overfitting.
Regularization
Any technique that constrains a model to prefer simpler solutions that generalize better.
Overfitting countermeasures
The toolkit — augmentation, dropout, weight decay, early stopping, transfer learning — for closing the train/val gap.

What does a dropout layer do during training?

We use cookies

We use cookies to enhance your browsing experience, serve personalized content, and analyze our traffic. By clicking "Accept All", you consent to our use of cookies. Learn more

    Day 39: Training the Garment Classifier: overfitting countermeasures | RBTechIconX