Deep Learning Foundations / Module 4 of 8
15-min lesson

Data Augmentation

Preparing the Data · Model Creation · Data Augmentation · Training with Augmentation · Saving the Model

Preparing the Data & Model Creation

Same ASL loading pipeline and CNN architecture as Module 3 — nothing changes here. Augmentation is something you add to training, not something that changes how you load or architect a model.

Data Augmentation

Dropout (Module 3) fights overfitting from inside the model. Augmentation fights the same problem from the data side: your model only ever sees the exact pixels in your dataset, so it can start memorizing those specific pixels instead of the underlying letter. Augmentation creates realistic variations of those images on the fly — a slight rotation, a small shift — so there's no single fixed image left to memorize.

import torchvision.transforms.v2 as transforms

random_transforms = transforms.Compose([
    transforms.RandomRotation(10),
    transforms.RandomAffine(degrees=0, translate=(0.1, 0.1)),
])
Notice what's missing: no RandomHorizontalFlip. For photos of cats, flipping is free extra data — a mirrored cat is still a cat. For ASL, flipping a hand sign can turn it into a different letter, or one that isn't valid at all. Augmentation isn't "always add more transforms" — it's "add the transforms that match what's actually still true after you apply them." Get this wrong and you're not augmenting your data, you're corrupting your labels.

Training with Augmentation

Augmentation runs only on the training batches. Validation must stay untouched — it's supposed to measure how the model does on real data, so augmenting it would make the accuracy number meaningless.

for epoch in range(20):
    model.train()
    for x, y in train_loader:
        x = random_transforms(x)          # augmentation: training only
        optimizer.zero_grad()
        output = model(x)
        loss = loss_fn(output, y)
        loss.backward()
        optimizer.step()

    model.eval()
    with torch.no_grad():
        for x, y in valid_loader:         # NOT augmented
            output = model(x)
            ...

Saving the Model

state_dict() is just a dictionary of the model's learned weights — not its architecture. To reload it later, you recreate the exact same architecture first, then load the weights into it:

torch.save(model.state_dict(), 'asl_model.pth')

# ...later, possibly in a different script:
model2 = build_same_architecture()        # must match exactly
model2.load_state_dict(torch.load('asl_model.pth'))
model2.eval()
A saved model is only half a model. The architecture that built it is the other half — and you have to bring both.

Vocabulary

Data augmentation
Creating realistic variations of existing training images on the fly, rather than collecting new data.
Transform
A single operation applied to an image — a rotation, a shift, a flip.
state_dict()
A dictionary of a model's learned weights, without its architecture.
Overfitting
See Module 3 — memorizing training data instead of learning general patterns.

15-min quiz