leafscan / README.md
tktejask's picture
Update README.md
58cb4f6 verified
|
Raw
History Blame Contribute Delete
4.1 kB
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


🧠 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


πŸ—οΈ 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

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).