Skip to content

Gamferno/plant-disease-detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒฟ AI Plant Disease Detection System

A deep learning-based web application for detecting and classifying plant diseases from leaf images. The system uses Convolutional Neural Networks (CNNs) with EfficientNetV2S architecture to identify 38 different classes of plant diseases across 14 crop species, achieving 96.81% validation accuracy.

Python TensorFlow Streamlit Accuracy License

๐Ÿ“‹ Table of Contents

โœจ Features

  • Multi-Class Detection: Identifies 38 different plant disease classes
  • 14 Crop Species: Supports Apple, Blueberry, Cherry, Corn, Grape, Orange, Peach, Pepper, Potato, Raspberry, Soybean, Squash, Strawberry, and Tomato
  • High Accuracy: 96.81% validation accuracy, 96.92% training accuracy
  • EfficientNetV2S Architecture: State-of-the-art deep learning model with transfer learning
  • Real-time Inference: Fast prediction with confidence scores
  • User-Friendly Interface: Clean and intuitive Streamlit web interface
  • Confidence Metrics: Visual confidence indicators for predictions
  • Healthy/Diseased Classification: Identifies both healthy and diseased plants

๐ŸŽฅ Demo

The application provides a simple interface where users can:

  1. Upload an image of a crop leaf (JPG, JPEG, or PNG format)
  2. View the uploaded image
  3. Get instant prediction results including:
    • Plant species identification
    • Disease classification
    • Confidence percentage
    • Health status indicator

Access the app at: http://localhost:8502

Homepage

Prediction Result

๐ŸŒฑ Supported Plants & Diseases

The model can identify the following plant species and their associated diseases:

Plant Species Diseases Detected
Apple Apple Scab, Black Rot, Cedar Apple Rust, Healthy
Blueberry Healthy
Cherry Powdery Mildew, Healthy
Corn (Maize) Cercospora Leaf Spot, Common Rust, Northern Leaf Blight, Healthy
Grape Black Rot, Esca (Black Measles), Leaf Blight, Healthy
Orange Huanglongbing (Citrus Greening)
Peach Bacterial Spot, Healthy
Pepper (Bell) Bacterial Spot, Healthy
Potato Early Blight, Late Blight, Healthy
Raspberry Healthy
Soybean Healthy
Squash Powdery Mildew
Strawberry Leaf Scorch, Healthy
Tomato Bacterial Spot, Early Blight, Late Blight, Leaf Mold, Septoria Leaf Spot, Spider Mites, Target Spot, Yellow Leaf Curl Virus, Mosaic Virus, Healthy

Total Classes: 38 (including healthy variants)

๐Ÿ› ๏ธ Tech Stack

Core Technologies

  • Python 3.10: Programming language
  • TensorFlow 2.21: Deep learning framework
  • Keras 3.12: High-level neural networks API
  • Streamlit 1.55: Web application framework

Libraries & Dependencies

  • NumPy: Numerical computations and array operations
  • Pillow: Image processing and manipulation
  • Pandas: Data handling (via Streamlit)
  • H5Py: Model file handling

๐Ÿ“ Project Structure

plant_disease_detection/
โ”œโ”€โ”€ app.py                          # Main Streamlit application
โ”œโ”€โ”€ notebooks/                      # Jupyter notebooks
โ”‚   โ””โ”€โ”€ plant_disease_training.ipynb  # Training notebook (Colab-ready)
โ”œโ”€โ”€ saved_model/                    # TensorFlow SavedModel (download from Drive)
โ”‚   โ”œโ”€โ”€ saved_model.pb             # Model architecture and weights
โ”‚   โ”œโ”€โ”€ variables/                 # Model variables
โ”‚   โ”œโ”€โ”€ assets/                    # Model assets
โ”‚   โ””โ”€โ”€ fingerprint.pb             # Model fingerprint
โ”œโ”€โ”€ class_labels.json               # Disease class mappings (38 classes)
โ”œโ”€โ”€ screenshots/                    # Application screenshots
โ”œโ”€โ”€ requirements.txt                # Python dependencies
โ”œโ”€โ”€ .gitignore                     # Git ignore rules
โ”œโ”€โ”€ LICENSE                         # MIT License
โ””โ”€โ”€ README.md                       # Project documentation

Note: Model files are hosted separately on Google Drive due to size constraints.

๐Ÿš€ Installation

Prerequisites

  • Python 3.10 or compatible version (3.8-3.11)
  • pip package manager
  • Model files (download separately)

Step-by-Step Installation

  1. Clone the repository

    git clone https://github.com/gamferno/plant-disease-detection.git
    cd plant_disease_detection
  2. Download the model files

    Download saved_model.zip from Google Drive:

    The saved_model/ directory should be in the project root.

  3. Create a virtual environment

    python -m venv tf-env
  4. Activate the virtual environment

    On Linux/Mac:

    source tf-env/bin/activate

    On Windows:

    tf-env\Scripts\activate
  5. Install dependencies

    pip install --upgrade pip
    pip install -r requirements.txt

Quick Install (One Command)

python -m venv tf-env && source tf-env/bin/activate && pip install -r requirements.txt

Note: Don't forget to download and extract the model files before running the app!

๐Ÿ’ป Usage

Running the Application

  1. Activate the virtual environment (if not already activated)

    source tf-env/bin/activate  # Linux/Mac
    # or
    tf-env\Scripts\activate  # Windows
  2. Start the Streamlit app

    streamlit run app.py
  3. Access the application

    • Open your browser and navigate to http://localhost:8501
    • The application will automatically open in your default browser

Using the Application

  1. Click on "Choose a leaf image" to upload an image
  2. Select an image file (JPG, JPEG, or PNG) of a crop leaf
  3. Wait for the model to process the image
  4. View the results:
    • Plant Type: Identified crop species
    • Disease: Disease classification
    • Confidence: Prediction confidence percentage with visual progress bar
    • Health Status: Clear indicator if the plant is healthy or diseased

Command Line Options

Run with custom configuration:

streamlit run app.py --server.port 8080
streamlit run app.py --server.address 0.0.0.0  # For network access
streamlit run app.py --theme.base dark  # Dark theme

๐Ÿง  Model Architecture

Model Details

  • Type: Convolutional Neural Network (CNN)
  • Architecture: EfficientNetV2S (Transfer Learning)
  • Framework: TensorFlow/Keras
  • Pre-trained Weights: ImageNet
  • Input Size: 300x300x3 (RGB images)
  • Output: 38 classes (softmax activation)
  • Model Format: TensorFlow SavedModel
  • Model Size: ~5 MB (SavedModel format)

Performance Metrics

  • Validation Accuracy: 96.81%
  • Training Accuracy: 96.92%
  • Architecture: EfficientNetV2S with custom classification head
  • Training Strategy: Two-phase (frozen backbone โ†’ fine-tuning)

Preprocessing Pipeline

  1. Image resizing to 300x300 pixels
  2. RGB conversion (3 channels)
  3. Normalization: pixel values scaled to [0, 1]
  4. Batch dimension expansion for model input

Inference

  • Uses TensorFlow SavedModel signature for inference
  • Serving endpoint: serving_default
  • Output: Softmax probabilities for all 38 classes
  • Prediction: argmax of output probabilities

๐Ÿ“Š Dataset

The model is trained on the New Plant Diseases Dataset from Kaggle, a comprehensive augmented dataset for plant disease classification.

Dataset Information

  • Source: New Plant Diseases Dataset (Kaggle)
  • Total Classes: 38 (including healthy variants)
  • Plant Species: 14
  • Image Type: RGB leaf images
  • Resolution: Resized to 300x300 pixels
  • Augmentation: Includes rotation, zoom, flip, and shift transformations
  • Split: Training and validation sets provided

Class Distribution

  • Multiple disease types per plant species
  • Healthy class for most plant types
  • Balanced representation across major crops
  • Over 70,000 augmented training images

Dataset Citation

@dataset{new_plant_diseases_dataset,
  author = {Vipoooool},
  title = {New Plant Diseases Dataset},
  year = {2020},
  publisher = {Kaggle},
  url = {https://www.kaggle.com/datasets/vipoooool/new-plant-diseases-dataset}
}

๐Ÿ“ˆ Performance

Model Accuracy

  • Validation Accuracy: 96.81%
  • Training Accuracy: 96.92%
  • Architecture: EfficientNetV2S with transfer learning
  • Dataset: New Plant Diseases Dataset (Augmented)

Key Metrics

The model provides:

  • 38-Class Classification: High accuracy across all disease types
  • Confidence Score: Probability-based confidence metric (0-100%)
  • Real-time Inference: Fast prediction (<3 seconds on CPU)
  • Robust Performance: Validated on diverse leaf images

Hardware Requirements

  • CPU: Modern multi-core processor (Intel/AMD)
  • RAM: Minimum 4 GB, Recommended 8 GB
  • Storage: 500 MB for model and dependencies
  • GPU: Optional (CUDA-compatible GPU for faster inference)

Optimization

  • oneDNN: Optimized for Intel CPU instructions (AVX2, AVX512F)
  • Model Caching: Streamlit caching for fast reloads
  • Efficient Memory: Lightweight inference pipeline

๐Ÿ““ Training Notebooks

The notebooks/ directory contains Jupyter notebooks for model training and experimentation:

  • plant_disease_training.ipynb: Clean, production-ready training notebook
    • Complete training pipeline from data download to model export
    • Google Colab compatible with GPU support
    • Well-documented with markdown sections
    • Includes data augmentation, transfer learning, and evaluation
    • Two-phase training: frozen backbone โ†’ fine-tuning

Open In Colab

See notebooks/README.md for running instructions and TRAINING.md for detailed training guide.

๐Ÿ”ง API Reference

Model Interface

import tensorflow as tf
import numpy as np
from PIL import Image

# Load model
model = tf.saved_model.load("saved_model")
infer = model.signatures["serving_default"]

# Prepare image
image = Image.open("leaf.jpg").convert("RGB")
img = image.resize((300, 300))
img_array = np.array(img, dtype=np.float32) / 255.0
img_array = np.expand_dims(img_array, axis=0)

# Predict
outputs = infer(tf.constant(img_array))
predictions = list(outputs.values())[0].numpy()

# Get result
predicted_class = np.argmax(predictions[0])
confidence = predictions[0][predicted_class]

Streamlit Components

The application uses:

  • st.file_uploader: Image upload widget
  • st.image: Display uploaded images
  • st.spinner: Loading indicator
  • st.metric: Display plant and disease info
  • st.progress: Confidence visualization
  • st.success/st.warning: Status messages

๐Ÿค Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch
    git checkout -b feature/AmazingFeature
  3. Commit your changes
    git commit -m 'Add some AmazingFeature'
  4. Push to the branch
    git push origin feature/AmazingFeature
  5. Open a Pull Request

Areas for Contribution

  • Add more plant species and diseases
  • Improve model accuracy
  • Add mobile responsiveness
  • Implement batch processing
  • Add disease treatment recommendations
  • Create REST API endpoint
  • Add multilingual support
  • Improve UI/UX design

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Dataset: New Plant Diseases Dataset by Vipoooool on Kaggle
  • TensorFlow Team: For the deep learning framework
  • Streamlit: For the amazing web app framework
  • EfficientNet: For the state-of-the-art architecture
  • Kaggle: For hosting the dataset and providing GPU resources

๐Ÿ“ง Contact

For questions, suggestions, or issues, please open an issue on the GitHub repository.

๐Ÿ”ฎ Future Enhancements

  • Mobile application (iOS/Android)
  • Batch image processing
  • Disease treatment recommendations
  • Historical tracking of plant health
  • REST API for integration
  • Model retraining pipeline
  • Multi-language support
  • Severity assessment
  • Geolocation-based disease prevalence
  • Export reports as PDF

๐Ÿ“š References

  1. New Plant Diseases Dataset: https://www.kaggle.com/datasets/vipoooool/new-plant-diseases-dataset
  2. EfficientNetV2: https://arxiv.org/abs/2104.00298
  3. TensorFlow Documentation: https://www.tensorflow.org/
  4. Streamlit Documentation: https://docs.streamlit.io/

Made with โค๏ธ for sustainable agriculture

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors