AI-powered plant disease detection from leaf images β built with PyTorch, tracked with ClearML, and deployed on Hugging Face Spaces.
| Resource | Link |
|---|---|
| π GitHub Repository | knd8412/PlantDiseaseClassifier |
| π Live Demo (Hugging Face) | Vinuit/PlantDiseaseClassifier |
| π§ͺ Baseline CNN Experiment | c0422871afdd43a4905b6801890f3324 |
| π§ ResNet18 Experiment | d6035906610145b7b2cfeca0fb1fa155 |
PlantDiseaseClassifier is an end-to-end machine learning system that identifies plant diseases from photographs of leaves. Upload a photo β get a diagnosis.
The model is trained on the PlantVillage dataset, which contains 55,400 images across 39 plantβdisease classes at 256Γ256 resolution. Examples of classes include Tomato_Early_Blight, Grape_Black_Rot, and Apple_Cedar_Rust.
The project covers the full ML lifecycle:
Raw Data β Preprocessing β Model Training β Experiment Tracking β Evaluation β Deployment
- π§ Custom CNN trained from scratch on PlantVillage
- π Transfer Learning option with ResNet18
- π Real-time experiment tracking via ClearML (metrics, checkpoints, hyperparameters)
- πΌοΈ Data augmentation and normalization pipeline
- π Interactive Gradio web app β upload any leaf photo and get a prediction
- π¦ Batch classification support
- π Public deployment on Hugging Face Spaces
- π CI/CD automation via self-hosted GitHub Actions runner
- πͺ Pre-commit hooks for code quality and style (flake8)
- π Architecture auto-detection β evaluation script figures out your model type automatically
- ποΈ Error gallery β visual analysis of worst misclassification patterns
| Component | Technology |
|---|---|
| Deep Learning Framework | PyTorch |
| Experiment Tracking | ClearML (KCL-hosted server) |
| Web Interface | Gradio |
| Deployment | Hugging Face Spaces |
| CI/CD | GitHub Actions (self-hosted runner) |
| Linting | flake8 |
| Testing | pytest |
| Code Quality | pre-commit hooks |
| Version Control | Git / GitHub |
PlantDiseaseClassifier/
βββ .github/ # GitHub Actions CI/CD workflows
βββ configs/ # YAML configuration files for training/evaluation
βββ data/ # Dataset utilities and preprocessing scripts
βββ datasetNotebooks/ # Exploratory data analysis notebooks
βββ examples/ # Sample images for testing
βββ src/
β βββ train.py # Main training script
β βββ evaluate.py # Evaluation script with error gallery
βββ tests/ # pytest test suite
βββ ui/
β βββ app.py # Gradio web application
βββ requirements.txt # Python dependencies
βββ pyproject.toml # Project metadata and tooling config
βββ .pre-commit-config.yaml
βββ .flake8
βββ README.md
git clone https://github.com/knd8412/PlantDiseaseClassifier.git
cd PlantDiseaseClassifierpython -m venv .venv
# Windows:
.venv\Scripts\activate
# Linux / macOS:
source .venv/bin/activatepip install -r requirements.txtOnly needed once. Skip if you don't need experiment tracking.
clearml-initpython -m ui.appThe Gradio app will open in your browser at http://localhost:7860.
# Train using default config (25% subset for fast prototyping)
python src/train.py --config configs/train.yamlThe dataset downloads automatically from Hugging Face Hub on first run and is cached at ~/.cache/huggingface/datasets/. Subsequent runs use the cache β no re-download needed.
π‘ Tip: Adjust
batch_sizein the config to fit your GPU/CPU memory. To force CPU, setdevice: cpuin the config file.
Outputs after training:
| File | Description |
|---|---|
outputs/best.pt |
Best model weights (by validation accuracy) |
outputs/metrics.json |
Summary of the last run's metrics |
| ClearML dashboard | Full task logs, metrics curves, and registered model |
The evaluation script auto-detects the model architecture using a 3-step fallback:
- Checkpoint metadata β reads embedded
model_configif saved by the updatedtrain.py - Auto-inference β analyzes
state_dictweight shapes and key patterns - Config file fallback β uses
--configorconfigs/train.yamlas last resort
# Basic evaluation (architecture auto-detected)
python src/evaluate.py --model outputs/best.pt --split val
# Evaluate on the test split
python src/evaluate.py --model outputs/best.pt --split test
# Validate your setup without running full evaluation
python src/evaluate.py --model outputs/best.pt --dry-run
# Skip error gallery for faster runs
python src/evaluate.py --model outputs/best.pt --split val --no-error-gallery
# Override architecture with a specific config (for old checkpoints)
python src/evaluate.py --model outputs/best.pt --config configs/train_quick_test.yaml --split val| Output | Description |
|---|---|
| Overall Accuracy | % of correctly classified samples |
| Top-5 Accuracy | % where correct class appears in top 5 predictions |
| Per-class Metrics | Precision, recall, F1-score for each disease class |
confusion_matrix.png |
Visual heatmap of classification patterns |
errors/ directory |
Error gallery with misclassified samples |
| JSON results file | Full metrics and per-class statistics |
The error gallery visualizes the worst confusion patterns your model makes β useful for diagnosing where and why it fails.
python src/evaluate.py --model outputs/best.pt --split val \
--error-gallery \
--gallery-top-pairs 5 \
--gallery-samples-per-pair 10Generated output:
- Image grids of misclassified samples per confusion pair
- Metadata files with sample indices and confusion statistics
- Full analysis report in Markdown format
See ERROR_GALLERY_README.md for detailed documentation.
The confusion matrix defaults to the 15 most confused classes for readability.
# Show top 10 most confused classes
python src/evaluate.py --model outputs/best.pt --split val --cm-classes 10
# Show all 39 classes
python src/evaluate.py --model outputs/best.pt --split val --cm-classes 0pytest tests/Pre-commit hooks run automatically on every git commit to enforce code quality. To run them manually:
pre-commit run --all-filesAll training and evaluation runs are automatically logged to ClearML:
- π Accuracy and loss curves
- πΌοΈ Confusion matrix uploaded as an artifact
- ποΈ Error gallery images organized by confusion pair
- π Error analysis Markdown as a downloadable artifact
- βοΈ All hyperparameters captured automatically
Check your ClearML project dashboard after any train.py or evaluate.py run.
The app is publicly deployed on Hugging Face Spaces:
π https://huggingface.co/spaces/Vinuit/PlantDiseaseCLassifier
Upload any plant leaf image and receive an instant disease prediction.
| GitHub | Name |
|---|---|
| @knd8412 | Kamyar Nadarkhani |
| @Vinuitik | Vinuitik |
| @k23099462 | Jaroslav Rakoto-Miklas |
| @SoroushSoroush20041383 | Soroush |
Built with π± for plant health and deep learning.