Transfer learning project using VGG19 and YOLOv5 for 102-category flower classification.
- Oxford 102 Flowers Dataset
- 8,189 images across 102 flower categories
- Split: 50% training / 25% validation / 25% testing
- Two random seeds (42 and 123) used to evaluate model robustness
| Model | Seed 42 | Seed 123 | Trainable Params |
|---|---|---|---|
| VGG19 | ~84% | ~85.3% | ~124M |
| YOLOv5-cls | 91.75% | 91.89% | ~130K |
- Python 3.8+
- PyTorch 2.8.0
- matplotlib -sickcit learn
- See requirements.txt for full list
git clone https://github.com/Jacob170/flower_classification.git
cd flower_classificationpython3 -m venv venv
source venv/bin/activate # Linux/Mac
# or
venv\Scripts\activate # Windowspip install -r requirements.txt- data_preparation.py - splits the dats 25%|25%|50%
- evaluate - prints the plots of accuracy and loss
- train_vgg19.py - training class for vgg
- train_yolov5.py - training class for yolo
- preproccessing - augmentation normalization of iamges before training
- main - main program runs everything (except the data_preparation.py so no split)
python src/data_preparation.pyThis creates stratified train/val/test splits for seeds 42 and 123.
python src/main.pyThis runs preprocessing, training, and evaluation for both models.
in the main change the DataLoader arguments
to work with num_workers=1 or 2
and the pin_memory=False or just remove it
This code optimized to work with cuda
- Frozen: 16 convolutional layers (feature extractor)
- Trainable: 3 fully-connected classifier layers
- Modified: Final layer changed from 1000 → 102 classes
- Optimizer: SGD (lr=0.01, momentum=0.9)
- Epochs: 35
- Frozen: Backbone layers 0-8
- Trainable: Classification head (layer 9)
- Modified: Final linear layer changed from 1000 → 102 classes
- Optimizer: Adam (lr=0.001)
- Epochs: 20
- Modern architectures win: YOLOv5-cls (2020) outperformed VGG19 (2014) by ~12% accuracy
- Efficiency matters: YOLOv5-cls trained 1000x fewer parameters
- Both models are robust: < 0.2% variance between different random seeds
- Transfer learning works: Achieved 92% accuracy with only ~4,000 training images
- VGG19 Test Accuracy: 85.30%
- YOLOv5 Test Accuracy: 91.89%
Jacob Yaacubov & Barak Milshtein
https://github.com/Jacob170/flower_classification
- Primary: Oxford 102 Flowers
- Additional: [if you used any]