Skip to content

Devaaldo/tomatoes-detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tomato Leaf Disease Classification

EfficientNetB0-based image classifier for detecting 10 categories of tomato leaf diseases using transfer learning and fine-tuning on the PlantVillage dataset.

Overview

Item Detail
Model EfficientNetB0 (ImageNet pretrained)
Dataset PlantVillage Tomato Leaf — kaustubhb999
Classes 10
Training images 10,000
Validation images 1,000
Val Accuracy 92.50%
Macro AUC 0.99+
Framework TensorFlow 2.21 / Keras
Export formats .keras, .h5, .tflite (16.56 MB)

Classes

Label Disease
Tomato___Bacterial_spot Bacterial Spot
Tomato___Early_blight Early Blight
Tomato___Late_blight Late Blight
Tomato___Leaf_Mold Leaf Mold
Tomato___Septoria_leaf_spot Septoria Leaf Spot
Tomato___Spider_mites Two-spotted_spider_mite Spider Mites
Tomato___Target_Spot Target Spot
Tomato___Tomato_Yellow_Leaf_Curl_Virus Yellow Leaf Curl Virus
Tomato___Tomato_mosaic_virus Mosaic Virus
Tomato___healthy Healthy

Dataset Distribution

Class Distribution

The dataset is perfectly balanced: 1,000 training images and 100 validation images per class.

Augmented Training Samples

Augmented Samples

Augmentation applied: rotation (±40°), width/height shift, zoom, shear, horizontal/vertical flip, brightness and channel shift.

Training Strategy

Two-phase transfer learning:

Phase 1 — Head Training (20 epochs) Base EfficientNetB0 frozen. Only the classification head trained with Adam(lr=1e-3).

Phase 2 — Fine-Tuning (10 epochs) Last 10 layers of the base unfrozen, retrained with Adam(lr=1e-5).

Both phases use: EarlyStopping, ReduceLROnPlateau, ModelCheckpoint, CSVLogger.

Training History

Training History

The dashed vertical line marks the transition from Phase 1 to Phase 2. Best validation accuracy: 93.20% at epoch 20 (Phase 1), settling at 92.50% after fine-tuning.

Evaluation Results

Confusion Matrix

Confusion Matrix

Per-Class Metrics

Per-Class Metrics

Class Precision Recall F1
Bacterial Spot 0.94 0.94 0.94
Early Blight 0.95 0.80 0.87
Late Blight 0.95 0.95 0.95
Leaf Mold 0.96 0.97 0.97
Septoria Leaf Spot 0.82 0.97 0.89
Spider Mites 0.90 0.94 0.92
Target Spot 0.81 0.91 0.86
Yellow Leaf Curl Virus 0.99 0.93 0.96
Mosaic Virus 0.99 0.95 0.97
Healthy 0.98 0.88 0.93
Weighted avg 0.93 0.92 0.92

ROC-AUC Curves

ROC-AUC

Prediction Confidence Distribution

Confidence Distribution

Sample Predictions

Sample Predictions

Green title = correct prediction, red = incorrect.

Grad-CAM Visualization

Grad-CAM

Grad-CAM activation maps highlight the leaf regions the model focuses on when making predictions.

Repository Structure

tomatoes-detection/
├── tomatoes-detection.ipynb        # Main notebook
├── config.json                     # Hyperparameter config
├── requirements.txt
├── .gitignore
├── output/
│   ├── 01_dataset/
│   │   ├── class_distribution.png
│   │   └── augmented_samples.png
│   ├── 02_training/
│   │   └── training_history.png
│   ├── 03_evaluation/
│   │   ├── confusion_matrix.png
│   │   ├── per_class_metrics.png
│   │   ├── roc_auc_curves.png
│   │   ├── confidence_distribution.png
│   │   ├── sample_predictions.png
│   │   └── classification_report.txt
│   └── 04_gradcam/
│       └── gradcam_samples.png
└── saved_model/                    # Excluded from git (see .gitignore)
    ├── best_model.keras
    ├── final_model.keras
    ├── final_model.h5
    ├── model.tflite
    └── model_metadata.json

How to Run

# 1. Clone and install dependencies
git clone <repo-url>
cd tomatoes-detection
pip install -r requirements.txt

# 2. Open the notebook
jupyter notebook tomatoes-detection.ipynb

The notebook downloads the dataset automatically via kagglehub. A Kaggle API key is required — see kaggle.com/docs/api.

License

Educational and portfolio use. Dataset credit: kaustubhb999 on Kaggle.

About

Tomato leaf disease classifier using EfficientNetB0 transfer learning — 10 classes, 92.5% accuracy, TFLite export ready.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors