Skip to content

The Plant Disease Classification project uses the NasNetMobile deep learning model to classify plant conditions into five categories: fungus, healthy, virus, pests , and bacteria . With a FastAPI backend, SQL Server database, and Streamlit frontend, it enables users to upload images and get quick, accurate disease predictions.

License

Notifications You must be signed in to change notification settings

AnshKGoyal/Plant-Disease-Classification

Repository files navigation

Plant Disease Classification

This project is an automated system for plant disease classification using machine learning techniques. It aims to assist farmers, agricultural researchers, and enthusiasts in quickly and accurately diagnosing plant health issues through image analysis.

The application consists of a backend built with FastAPI, a database managed with SQL Server, and a frontend powered by Streamlit. The project leverages a pre-trained deep learning model to identify diseases from plant images.

Features

  • User registration and authentication
  • Image upload and processing
  • Automated disease classification using a deep learning model
  • Community interaction through a comment system
  • User activity logging
  • Detailed prediction results with confidence scores

Project Structure

plant_disease_classification/
├── backend/
│   ├── main.py                        # FastAPI main application
│   ├── models.py                      # SQLAlchemy models
│   ├── database.py                    # Database connection setup
│   ├── schemas.py                     # Pydantic schemas for data validation
│   ├── app.py                         # Streamlit frontend
│   ├── ml_model.py                    # Model loading and inference
│   └── uploads/                       # Directory to store uploaded images
├── model/			       
│   ├── label_encoder.joblib           # Label encoder for disease labels
│   ├── resnet_50_95.h5                # Pre-trained model
│   ├── NasNetMobile.h5                # Pre-trained model
│   ├── NasNetMobile.keras             # Pre-trained model
├── example_images/                    # Example images for testing
├── plant-disease-classification.ipynb # Jupyter notebook for training               
├── requirements.txt                   # Dependencies for the project
└── README.md                          # Project documentation

Note: In case GitHub's LFS bandwidth limit is reached, you can also download the models using this Google Drive link.

Additional Resources

For a more detailed overview of the project, please refer to the Project Overview.

It also contains visual diagrams like Data Flow Diagram and Entity Relationship Diagram to support understanding.

Demo Video

To see the Plant Disease Classification Web app in action, check out this demo video:

Recording.2024-10-01.233501.mp4

Installation

Prerequisites

Setup

  1. Clone or Download the Repository and open the project directory in your editor (VS Code)

  2. Create a virtual environment and activate it:

python -m venv venv
source venv/bin/activate  # On Windows, use `.\venv\Scripts\activate`
  1. Install the required dependencies:
python -m pip install -r requirements.txt

Note: If the bandwidth limit for GitHub LFS is exceeded and you cannot download the models, you can also use this Google Drive link to download the models.

  1. Update the SERVER and DATABASE variables in backend/database.py with your SQL Server details.
SERVER = 'your_server_name'
DATABASE = 'plant_disease'

Ensure that the required tables are created by running the FastAPI app, which will automatically generate the tables in the database.

  1. Start the FastAPI backend:
cd backend
uvicorn main:app --reload
  1. Start the Streamlit frontend:
cd backend
streamlit run app.py

The frontend will be accessible at http://localhost:8501.

Training the Model

The pre-trained models are included in the models/ directory, so no additional download is necessary. However, if you want to retrain the model, you can either use the public Kaggle notebook or download the same notebook from GitHub.

This project uses the Plant Pathogens dataset , which is already linked in the Kaggle notebook but can also be downloaded for local use from GitHub. (Note: This Dataset is licensed under CC BY-NC-SA 4.0, so The model trained using this dataset cannot be used for commercial purposes.)

Steps to Train the Model:

  1. Option 1: Use Kaggle's Public Notebook :

    • Directly Fork the Plant Disease Classification Notebook on Kaggle. This allows you to create your own copy of the notebook, ready to run and customize.
    • The dataset is pre-linked in the notebook, and you can use Kaggle's free GPU/TPU resources for training.
  2. Option 2: Use the GitHub Notebook :

    • Download the plant-disease-classification.ipynb notebook from the GitHub repository and run it locally.
    • Install the necessary dependencies and ensure the dataset is properly downloaded and loaded.

    Important Note: The notebook in this GitHub repository is the same as the one uploaded on Kaggle. If you're running it locally, please be aware that:

    • You may need to manually install required libraries.
    • Some import statements might need adjustments due to differences between the Kaggle environment and your local setup.
    • While the notebook was originally run using TPU on Kaggle, the code is GPU-agnostic and can be run on different hardware setups with appropriate modifications.
  3. Training the Model :

    • Customize the model's hyperparameters (e.g., learning rate, batch size) in either environment.
    • Monitor the performance metrics (loss, accuracy) during training to ensure the model is learning effectively.
    • If using Kaggle, utilize the GPU/TPU to speed up training, especially for large datasets.
  4. Saving and Downloading Models :

    • After training, save your model using torch.save() or model.save(), depending on the framework.
    • For Kaggle users, download the trained model files for local use. For GitHub users, simply save the model in your local directory.

By following these steps, you can train the model either on Kaggle or locally using the provided notebook. Remember to adjust your environment and code as necessary when running locally.

Licensing Information

Contributing


Contributions to this project are welcome. Please fork the repository and submit a pull request with your changes.

About

The Plant Disease Classification project uses the NasNetMobile deep learning model to classify plant conditions into five categories: fungus, healthy, virus, pests , and bacteria . With a FastAPI backend, SQL Server database, and Streamlit frontend, it enables users to upload images and get quick, accurate disease predictions.

Topics

Resources

License

Stars

Watchers

Forks