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