File size: 4,096 Bytes
58cb4f6 565aecf 445b2a2 565aecf 445b2a2 565aecf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | ---
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
```bash
python -m venv venv
venv\Scripts\activate
pip install -r requirements.txt
```
---
### 2. Run server
```bash
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).
|