Oxford 17 Flowers — ResNet18 (97.8% test accuracy)
ResNet18 fine-tuned on the Oxford 17 Flowers dataset. Classifies RGB images into 17 flower categories.
Successor of the from-scratch educational CNN at darjja/oxford-17-flowers-cnn — same CLI, much higher accuracy:
| Model | Test accuracy |
|---|---|
| From-scratch CNN, 64×64 (original) | 62.13% |
| From-scratch CNN + augmentation & label smoothing | 66.91% |
| ResNet18 fine-tuned, 224×224 (this repo) | 97.79% |
Quick start
pip install torch torchvision huggingface_hub pillow
Download the script and run it on any image:
huggingface-cli download sergiudanstan/oxford-17-flowers-cnn predict.py --local-dir .
python predict.py your_flower.jpg
python predict.py your_flower.jpg --top 5
The script downloads flower_cnn.pth, config.json, and model.py from this repo automatically on first run.
Training recipe
- ImageNet-pretrained ResNet18 (torchvision
IMAGENET1K_V1), full fine-tune at 224×224 - Differential learning rates: backbone 1e-4, new head 1e-3 (AdamW, weight decay 1e-4)
- CosineAnnealingLR, label smoothing 0.1, early stopping on validation accuracy
- Augmentation: RandomResizedCrop(0.7–1.0), horizontal flip, rotation ±15°, ColorJitter 0.2
- Split: 924 train / 164 val (15%, seed 42) / 272 official test
- ~3 minutes on a laptop RTX 5050
Files in this repo
| File | Purpose |
|---|---|
predict.py | CLI script — pass any image path as argument |
model.py | Model definition (ResNet18 wrapper, FlowerCNN) |
flower_cnn.pth | Fine-tuned weights (~45 MB) |
config.json | Image size, class names |
Classes
Bluebell, Buttercup, Coltsfoot, Cowslip, Crocus, Daffodil, Daisy, Dandelion, Fritillary, Iris, Lilyvalley, Pansy, Snowdrop, Sunflower, Tigerlily, Tulip, Windflower