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

Day 38: Building the garment dataset: labeling ≥8 classes

The dataset is the product

Model architecture is mostly solved; your dataset is where you actually win or lose. For the Garment Classifier you need at least 8 classes (shirt, trousers, dress, saree, shoes, bag, …) with enough labelled examples each. You can bootstrap from DeepFashion or a similar public set, supplement with your own catalog photos (cleaned by the Stage 0 tool!), and label consistently. Class balance matters — Day 20's imbalance lessons apply to images too.

  • Enough per class: aim for a few hundred images per class minimum for transfer learning; more for rarer classes.
  • Balanced: wildly uneven classes push the model toward the majority — mirror Day 20's class-weighting or oversample.
  • Consistent labels: decide edge cases up front (is a "kurta" its own class or under "dress"?) and apply the rule uniformly.
  • Held-out split: split by *garment*, not by photo — multiple photos of the same item must not straddle train and val (that's Day 16 leakage).
Transforms: augmentation for train, plain normalization for val
from torchvision import transforms

# ImageNet normalization stats — required when using pretrained models
norm = transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])

train_tf = transforms.Compose([
    transforms.RandomResizedCrop(224),
    transforms.RandomHorizontalFlip(),
    transforms.ColorJitter(0.2, 0.2, 0.2),
    transforms.ToTensor(), norm,
])
val_tf = transforms.Compose([
    transforms.Resize(256), transforms.CenterCrop(224),
    transforms.ToTensor(), norm,
])

Match the pretrained model's normalization

When fine-tuning an ImageNet-pretrained model you must normalize your images with ImageNet's mean/std (the numbers above). Skip this and the input distribution won't match what the backbone expects, quietly tanking accuracy. It's a one-line bug that costs hours if you don't know to check it.

Assemble and split the garment dataset

Build a labelled dataset of ≥8 garment classes, split by item (not photo) into train/val, and set up augmented training transforms plus plain validation transforms with ImageNet normalization. Record per-class counts — you'll want them when diagnosing which classes the model struggles with on Day 40.

Key terms

Data augmentation
Randomly transforming training images (crops, flips, color shifts) to expand effective dataset size and improve generalization.
Normalization stats
The per-channel mean/std used to standardize inputs; must match what a pretrained model was trained with.
Split by item
Ensuring all photos of one garment go entirely to train or entirely to val, preventing leakage.

You have five photos of each garment. Why must all five photos of one item go to the same split (all train OR all val)?

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 38: Building the garment dataset: labeling ≥8 classes | RBTechIconX