plant-disease-detection

🌿 Plant Disease Detection & Fertilizer Recommendation System

![Python](https://img.shields.io/badge/Python-3.10+-blue.svg) ![Django](https://img.shields.io/badge/Django-5.x-green.svg) ![TensorFlow](https://img.shields.io/badge/TensorFlow-2.x-orange.svg) ![React](https://img.shields.io/badge/React-19-blue.svg) ![Vite](https://img.shields.io/badge/Vite-Frontend-purple.svg) ![License](https://img.shields.io/badge/License-MIT-yellow.svg) ### AI-Powered Plant Disease Detection using Deep Learning Detect plant diseases from leaf images and receive intelligent treatment, prevention, and fertilizer recommendations. For a detailed code-by-code explanation of the project, including the development process, technical decisions, implementation details, problems, debugging, and lessons learned, see: 👉 **[PROJECT_JOURNAL.md](/plant-disease-detection/PROJECT_JOURNAL.html)** > **PROJECT_JOURNAL.md** — Detailed code-by-code understanding and development journey

🎥 Complete System Demo

Watch the complete system in action — from uploading a plant leaf image to disease prediction, confidence score, treatment/prevention recommendations, fertilizer guidance, and prediction history.

https://github.com/user-attachments/assets/c9a22658-1487-4bd1-a0cc-2c4a18fd5279


📖 Overview

Plant Disease Detection System is a full-stack AI application that combines Deep Learning, Computer Vision, and Web Technologies to identify plant diseases from leaf images.

The system uses a MobileNetV2-based Convolutional Neural Network (CNN) trained on the PlantVillage dataset and provides:

This project is designed for:


✨ Features

🤖 AI Disease Detection

🌱 Disease Information

💊 Fertilizer Recommendation

📜 Prediction History

📱 Responsive Interface

🔌 REST API


🏗️ System Architecture

┌─────────────────┐
│ React Frontend  │
│     (Vite)      │
└────────┬────────┘
         │ Axios API Calls
         ▼
┌─────────────────────┐
│ Django REST API     │
│ (DRF Backend)       │
└────────┬────────────┘
         │
         ▼
┌─────────────────────┐
│ TensorFlow Model    │
│ MobileNetV2 CNN     │
└────────┬────────────┘
         │
         ▼
┌─────────────────────┐
│ SQLite/PostgreSQL   │
└─────────────────────┘

🌾 Supported Plants & Diseases

Plant Classes
Apple 4
Blueberry 1
Cherry 2
Corn 4
Grape 4
Orange 1
Peach 2
Pepper 2
Potato 3
Raspberry 1
Soybean 1
Squash 1
Strawberry 2
Tomato 10

Total Classes

✅ 38 Plant Disease Classes


📸 Screenshots

Home Page

[ Upload Plant Image ]

Home Page Screenshot

Prediction Result

Disease:
Tomato Early Blight

Confidence:
98.74%

Treatment:
Apply Copper Fungicide

Prevention:
Crop Rotation

Prediction Result Screenshot

Prediction History

Image | Disease | Confidence | Date

Prediction History Screenshot

Disease Information

Disease
Description
Symptoms
Treatment
Prevention

Disease Information Screenshot —

📂 Project Structure

Plant-Disease-Detection/
│
├── backend/
│   │
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
│
├── frontend/
│   │
│   ├── src/
│   │   ├── api/
│   │   │   └── api.js
│   │   │
│   │   ├── components/
│   │   │   ├── Navbar.jsx
│   │   │   ├── ImageUploader.jsx
│   │   │   ├── PredictionCard.jsx
│   │   │   ├── HistoryCard.jsx
│   │   │   └── Loading.jsx
│   │   │
│   │   ├── pages/
│   │   │   ├── Home.jsx
│   │   │   ├── History.jsx
│   │   │   └── DiseaseInfo.jsx
│   │   │
│   │   ├── App.jsx
│   │   ├── main.jsx
│   │   └── index.css
│   │
│   ├── package.json
│   └── vite.config.js
│
├── predictions/
│   ├── migrations/
│   ├── models.py
│   ├── serializers.py
│   ├── views.py
│   ├── urls.py
│   └── admin.py
│
├── media/
├── models/
│   ├── plant_disease_model.keras
│   ├── plant_disease_model.h5
│   └── class_names.json
│
├── requirements.txt
├── screenshots/
├── download_data.py
├── manage.py
├── predict.py
├── train_with_evaluate.py
└── README.md

⚙️ Installation

1️⃣ Clone Repository

git clone https://github.com/buildwithsomnath/plant-disease-detection.git

cd plant-disease-detection

Backend Setup

Create Virtual Environment

Windows

python -m venv venv

venv\Scripts\activate

Linux/Mac

python -m venv venv

source venv/bin/activate

Install Dependencies

pip install -r requirements.txt

Run Migrations

python manage.py makemigrations

python manage.py migrate

Create Superuser

python manage.py createsuperuser

Start Backend

python manage.py runserver

Backend URL:

http://127.0.0.1:8000

Frontend Setup

cd frontend

npm install

Start Frontend

npm run dev

Frontend URL:

http://localhost:5173

🔌 API Endpoints

Predict Disease

POST

/api/predict/

Request

curl -X POST \
-F "image=@leaf.jpg" \
http://localhost:8000/api/predict/

Response

{
  "success": true,
  "prediction": {
    "disease": "Tomato___Early_blight",
    "confidence": 98.74,
    "plant_type": "Tomato",
    "description": "...",
    "treatment": "...",
    "fertilizer": "...",
    "prevention": "..."
  }
}

Prediction History

GET

/api/history/

Prediction Detail

GET

/api/history/<id>/

Disease Information

GET

/api/diseases/

Disease Detail

GET

/api/diseases/<id>/

🧠 Deep Learning Model

Architecture

Input Image
    │
    ▼
Resize 224x224
    │
    ▼
MobileNetV2
    │
    ▼
Global Average Pooling
    │
    ▼
Dense Layer
    │
    ▼
Dropout
    │
    ▼
38-Class Softmax

📊 Model Performance

Metric Value
Dataset PlantVillage
Images 54,000+
Classes 38
Input Size 224x224
Framework TensorFlow
Model MobileNetV2
Accuracy ~81–84%

🛠️ Tech Stack

Frontend

Backend

Database


🚀 Deployment

Frontend

Deploy on:

npm run build

Backend

Deploy on:

Install:

pip install gunicorn

Create Procfile:

web: gunicorn backend.wsgi

🔐 Environment Variables

Create .env

SECRET_KEY=your-secret-key

DEBUG=False

ALLOWED_HOSTS=localhost,127.0.0.1

MODEL_PATH=models/plant_disease_model.keras

MAX_UPLOAD_SIZE=5242880

🔮 Future Improvements


🤝 Contributing

Contributions are welcome.

  1. Fork repository
  2. Create branch
git checkout -b feature/new-feature
  1. Commit
git commit -m "Added feature"
  1. Push
git push origin feature/new-feature
  1. Create Pull Request

👨‍💻 Author

Somnath Das

GitHub:

https://github.com/buildwithsomnath

LinkedIn:

https://linkedin.com/in/buildwithsomnath

Email:

somnathdas4462@gmail.com


🙏 Acknowledgements


⭐ Support

If you found this project helpful:

⭐ Star the repository

🍴 Fork the project

📢 Share with others


Made with ❤️ by Somnath Das