metadata
title: LeafScan
emoji: πΏ
colorFrom: green
colorTo: gray
sdk: docker
app_file: app.py
pinned: false
πΏ LeafScan β Plant Disease Detection using Deep Learning
A full-stack AI application that detects plant leaf diseases from real-world images using a fine-tuned EfficientNetB3 model trained on the PlantVillage dataset.
π Live Demo
- π Hugging Face Space: https://huggingface.co/spaces/tktejask/leafscan
π§ Project Overview
LeafScan is a real-time plant disease detection system that:
Accepts real-world leaf images
Detects 38 disease classes + 1 non-leaf class
Provides:
- Disease name
- Confidence score
- Severity
- Description
- Treatment suggestion
- Top-5 predictions
π Dataset
- Source: PlantVillage Dataset
- Link: https://www.kaggle.com/datasets/abdallahalidev/plantvillage-dataset
- Size: ~54,000 images
- Classes: 38 diseases + healthy + 1 synthetic "not a leaf" class
ποΈ Model Architecture
Input Image (300Γ300)
β
EfficientNetB3 (Pretrained on ImageNet)
β
Feature Vector (1536)
β
Custom Head:
Dense β GELU β Dropout
Dense β GELU β Dropout
Output Layer (39 classes)
β
Softmax Probabilities
βοΈ Training Strategy
| Phase | Description |
|---|---|
| Phase 1 | Train only classifier head |
| Phase 2 | Unfreeze last layers |
| Phase 3 | Full fine-tuning |
Techniques used:
- Transfer Learning
- Test Time Augmentation (TTA Γ6)
- AdamW optimizer
- Label smoothing
- Class balancing
π¬ Inference Pipeline
Input Image
β
Preprocessing (Resize β Normalize)
β
Model Prediction
β
TTA Averaging
β
Confidence + Decision Logic
β
Final Output + Top-5 Classes
π§ͺ Features
- β Works on real-world images (not just dataset)
- β Detects non-leaf images
- β REST API support
- β Beautiful frontend UI
- β Deployable locally + cloud
π₯οΈ Local Deployment
1. Setup
python -m venv venv
venv\Scripts\activate
pip install -r requirements.txt
2. Run server
python app.py
3. Output
Model ready.
* Running on http://127.0.0.1:7860
4. Open in browser
http://localhost:7860
π Hugging Face Deployment
- Platform: Hugging Face Spaces
- Runtime: Flask (Docker/Spaces)
- URL: https://huggingface.co/spaces/tktejask/leafscan
What was done:
- Uploaded model + backend + frontend
- Configured app.py to run on port 7860
- Added README config block
π API Endpoints
| Endpoint | Description |
|---|---|
/api/predict |
Upload image |
/api/predict-url |
Predict from URL |
/api/predict-base64 |
Predict from base64 |
/api/classes |
List classes |
/api/health |
Server status |
π Model Performance
- Accuracy: ~96% (on PlantVillage test set)
- Supports: 38 disease classes
- Handles real-world noise via TTA
β οΈ Limitations
- Trained on controlled dataset β real-world variation may reduce accuracy
- Needs clear leaf image
- Heavy model β slow on CPU
π₯ Key Highlights (Interview Points)
- Built end-to-end ML system
- Used transfer learning (EfficientNetB3)
- Implemented TTA for robustness
- Designed Flask API + frontend integration
- Deployed on Hugging Face Spaces
- Handled real-world inference issues
π¦ Project Structure
leaf scan/
βββ app.py
βββ model.py
βββ predict.py
βββ metrics.py
βββ models/
β βββ best_model.pth
βββ data/
β βββ classes.txt
βββ frontend/
β βββ index.html
βββ requirements.txt
π οΈ Tech Stack
- Python
- PyTorch
- timm
- Flask
- HTML/CSS/JS
- Hugging Face Spaces
π License
Educational project. Dataset is public (PlantVillage).