|
1 | 1 | # Plant Disease Detection |
2 | 2 |
|
3 | | -A deep learning system that detects and classifies plant diseases from leaf images using a Convolutional Neural Network (CNN). |
| 3 | +A deep learning system that detects and classifies **38 plant disease categories** from leaf images, built with EfficientNetB0 transfer learning and deployed via a Gradio web interface. |
4 | 4 |
|
5 | | -## Overview |
| 5 | +--- |
6 | 6 |
|
7 | | -Plant diseases are a major threat to global food security. Early detection helps farmers act before crops are lost. This project uses a CNN trained on the PlantVillage dataset to classify leaf images into 8 categories — identifying whether a plant is healthy or affected by a specific disease. |
| 7 | +## Results |
8 | 8 |
|
| 9 | +| Metric | Value | |
| 10 | +|---|---| |
| 11 | +| Model | EfficientNetB0 (fine-tuned) | |
| 12 | +| Dataset | PlantVillage (54,305 images) | |
| 13 | +| Classes | 38 (14 crop species) | |
| 14 | +| Expected val accuracy | 93–97% | |
| 15 | +| Input size | 224 × 224 RGB | |
| 16 | +| Confidence threshold | 50% (low-confidence inputs rejected) | |
9 | 17 |
|
10 | | -## How It Works |
| 18 | +--- |
11 | 19 |
|
12 | | -1. **Training (`training.py`)** — Loads labeled leaf images, builds a CNN with 3 convolutional layers, and trains it to classify images into 8 disease/health categories. |
13 | | -2. **Prediction (`prediction.py`)** — Loads the trained model, lets you pick an image via a file dialog, and predicts the disease class with a confidence score. |
14 | 20 |
|
15 | | -## Tech Stack |
| 21 | +## Quickstart |
16 | 22 |
|
17 | | -- Python |
18 | | -- TensorFlow / Keras |
19 | | -- EasyGUI (file selection) |
20 | | -- NumPy, Matplotlib |
| 23 | +### 1. Install dependencies |
| 24 | +```bash |
| 25 | +pip install -r requirements.txt |
| 26 | +``` |
21 | 27 |
|
22 | | -## Dataset |
| 28 | +### 2. Download the dataset |
| 29 | +Download [PlantVillage from Kaggle](https://www.kaggle.com/datasets/emmarex/plantdisease) and extract to `data/PlantVillage/`. |
| 30 | + |
| 31 | +### 3. Train the model |
| 32 | +```bash |
| 33 | +export DATA_DIR="data/PlantVillage" # Linux/Mac |
| 34 | +set DATA_DIR=data/PlantVillage # Windows |
| 35 | + |
| 36 | +python -m src.train |
| 37 | +``` |
| 38 | +This runs two training phases: |
| 39 | +- **Phase 1** (15 epochs): trains only the classification head (backbone frozen) |
| 40 | +- **Phase 2** (10 epochs): fine-tunes top 20 layers of EfficientNetB0 at low LR |
| 41 | + |
| 42 | +Model is saved to `models/best_model.keras`. |
| 43 | + |
| 44 | +### 4. Run the web app |
| 45 | +```bash |
| 46 | +python app.py |
| 47 | +``` |
| 48 | +Open `http://localhost:7860` in your browser. |
| 49 | + |
| 50 | +### 5. Run inference from CLI |
| 51 | +```bash |
| 52 | +python -m src.predict --image path/to/leaf.jpg |
| 53 | +``` |
23 | 54 |
|
24 | | -Trained on the [PlantVillage Dataset](https://github.com/spMohanty/PlantVillage-Dataset) — a public dataset of labeled plant leaf images. |
| 55 | +--- |
25 | 56 |
|
| 57 | +## Running Tests |
| 58 | +```bash |
| 59 | +pytest tests/ -v |
| 60 | +pytest tests/ -v --cov=src --cov-report=term-missing |
| 61 | +``` |
| 62 | +Tests use mocked models — no GPU or downloaded weights required. |
| 63 | + |
| 64 | +--- |
| 65 | + |
| 66 | +## Tech Stack |
| 67 | + |
| 68 | +- **Python 3.9+** |
| 69 | +- **TensorFlow / Keras** — model training and inference |
| 70 | +- **EfficientNetB0** — pretrained backbone (ImageNet weights) |
| 71 | +- **Gradio** — web interface |
| 72 | +- **Pillow / NumPy** — image processing |
| 73 | +- **pytest** — testing |
| 74 | + |
| 75 | +--- |
| 76 | + |
| 77 | +## Dataset |
26 | 78 |
|
27 | | -## Notes |
| 79 | +[PlantVillage Dataset](https://github.com/spMohanty/PlantVillage-Dataset) — 54,305 labeled leaf images across 38 classes (14 crop species). |
28 | 80 |
|
29 | | -- Update the `data_dir` and `model_path` variables in `training.py` and `prediction.py` to match your local dataset/model location before running. |
| 81 | +--- |
30 | 82 |
|
31 | 83 | ## License |
32 | 84 |
|
33 | | -This project is licensed under the MIT License — see the [LICENSE](LICENSE) file for details. |
| 85 | +MIT License — see [LICENSE](LICENSE). |
0 commit comments