Case study
SortWise
Upload a photo of a waste item and get the top-3 categories with a Grad-CAM heatmap of what the model looked at. Most of the work went into checking that the result is real, reproducible and understandable.
- PyTorch
- EfficientNet-B0
- Grad-CAM
- Gradio
- HF Hub
- GitHub Actions
Problem
Training a CNN on a ready-made dataset is the easy part. The hard part is knowing whether the score is real: TrashNet turned out to contain duplicate images with different labels, the first training runs were not reproducible, and a single accuracy number hides the smallest class. SortWise is a 6-class waste classifier (cardboard, glass, metal, paper, plastic, other) built to answer those questions, not just to report a number.
What I built
- Data pipeline: TrashNet download, SHA-256 manifest, duplicate removal, stratified 70/15/15 split saved with the excluded files.
- Training loop with early stopping on macro-F1, deterministic seeding, and three backbones (ResNet18, EfficientNet-B0, MobileNetV3-Small) in head-only and fine-tune modes.
- Own hook-based Grad-CAM implementation and heatmap galleries for correct predictions and errors.
- Gradio app showing the top-3 classes with a heatmap; ~44 ms per image including the heatmap on a desktop CPU.
- Model published to the Hugging Face Hub as a versioned package (weights, label map, config, metrics) under an immutable tag; the app loads a pinned version.
- GitHub Actions running pytest on every push: split leakage and duplicates, seed reproducibility, Grad-CAM for every model, predictor contract.
Engineering decisions
- Macro-F1 as the main metric: the trash class is 3–4× smaller than the others and accuracy would hide it.
- Test set used exactly once, after all decisions; hyperparameters tuned on validation only. The val→test drop (0.925 → 0.893) is reported, not hidden.
- Picked the more stable setting (lr 3e-4, 0.919 ± 0.015 over 3 seeds) over the best single run, and documented that the gap is within seed-to-seed spread.
- EfficientNet-B0 over ResNet18: a near-identical score at ~3× smaller weights (16 MB vs 45 MB).
- Show top-3 classes instead of one answer: errors come with 84–100% confidence, so a threshold alone would catch few of them.
Results
- Test set (379 images, used once): macro-F1 0.893, accuracy 0.910.
- Per-class F1: cardboard 0.93, paper 0.92, plastic 0.92, glass 0.91, metal 0.91, other 0.76.
- Found 3 pairs of identical images with different labels in the dataset and a seeding bug that made the same config score 0.896 or 0.928.
- Grad-CAM explained the typical errors: flat cardboard looks like paper, a bottle neck looks like glass.
- App reproduces the evaluation script's predictions on 60/60 test images.
Gallery





Limitations & next
- TrashNet shows single items on a plain light background; performance on other backgrounds or several items is not measured.
- Only 6 classes: anything else still gets one of them. Softmax score is not a calibrated probability.
- Next: evaluation on own photos, analysis history with user corrections, in-browser demo without a server (ONNX).