Skip to content

krishnaura45/PotatoLife

Repository files navigation

Potato Life : End-to-end Potato Disease Classification

Potato Life is an automated project for farmers for timely and accurate diagnosis of diseases in potato leaves.

Python TensorFlow FastAPI Streamlit Postman Optimized For Accuracy


FILES

  • PlantVillage_Data: Dataset info and zipped images.
  • Training.ipynb: Data processing and training code.
  • saved_models/: Contains trained model versions.
  • api/: Contains server.py for FastAPI and requirements.txt.
  • app.py: Streamlit web app code.
  • requirements.txt: Required libraries for deployment.
  • runtime.txt: Specifies Python runtime version for deployment.

IMPORTANT LINKS


INTRODUCTION

  • Potato(Solanum tuberosum) is the fourth-most important staple crop in the world.   
  • Potato crops are susceptible to multiple diseases.
  • This project identifies and classifies major potato diseases.
  • By accurately diagnosing diseases, farmers can apply targeted treatments, reducing the need for excessive pesticide use.

image


PROBLEM DEFINITION

  • Potato crops are highly vulnerable to diseases, impacting yield and food security.
  • Early, precise disease detection is crucial for efficient management and reduced crop loss.
  • Traditional diagnosis methods are slow and unsuitable for large-scale agriculture.
  • There's a need for automated, scalable solutions for disease detection.

METHODOLOGY

Step 1: Dataset Preparation

  • We have used publicly available ‘PlantVillage’ dataset.
  • It includes 1000 images each of ‘Early Blight’ and ‘Late Blight’, along with 152 ‘Healthy’ leaf images, totalling 2152 potato leaf images.

image

Step 2: Data Preprocessing

  • Data Batch Loading: Into 68 batches of 32 images each
  • Data Partitioning: Into train, test and validation sub-datasets
  • Data Resizing: To a constant size of 256 X 256
  • Data Rescaling: Divided pixel intensities of each image by 255.
  • Data Augmentation: As random flipping and random rotation

Step 3: Model Building

  • CNN Model Architecture: Consisted of-
    1. 6 convolutional layers with 3X3 kernel size and ReLU activation function
    2. 6 max-pooling layers
    3. A dropout layer
    4. A flattening layer
    5. 2 dense layers
  • Compiled the model using Adam optimizer, Sparse categorical cross-entropy loss and Accuracy metric.
  • The training process involved 50 epochs, with each epoch comprising 54 steps.

Step 4: FastAPI Integration

  • Implementation details:

    1. Endpoint Creation: We developed a FastAPI server on localhost, listening on port 8000.
    2. Endpoint Routes: We implemented the Post / Predict API route to facilitate interaction with the model. This route accepts an uploaded potato leaf image, processes it, feeds it into our trained model, and returns the predicted class (early blight, late blight, or healthy) along with a confidence score.
  • Image Processing and Model Prediction Upon receiving an image upload through the /predict endpoint, FastAPI performs the following steps:

    1. Image Conversion: FastAPI converts the uploaded image into a NumPy array.
    2. Tensor Conversion: The NumPy array is further transformed into a tensor, which is compatible with our trained model.
    3. Model Prediction: The tensorized image is passed through the model, and the model predicts the disease class and provides a confidence score for the prediction.
  • Response Format

image

Step 5: Web App Development and Deployment
  • Developed an interactive web app using Streamlit.
  • Key Features:
    • Image upload functionality with format validation.
    • Model prediction and visualization of class and confidence.
    • User-friendly layout with sidebar instructions.
    • Deployed on Streamlit Community Cloud for global access.
  • Enables seamless interaction for farmers and researchers for real-time disease detection.

RESULTS

  • Upon completion of training, our model achieved a remarkable test accuracy of 98.83%, demonstrating the model's efficacy in classifying potato leaves into three categories: early blight, late blight, and healthy conditions. image

  • Alongside, we have the model’s predictions on a sample of test images, where:

    • “Actual" represents the true class.
    • “Predicted represents the predicted class.
    • “Confidence" is the confidence score associated with the prediction, which reflects upon the reliability of the model's decision. image
  • FastAPI Working image image

  • Postman software interacting with the model via API request and giving prediction result as a json response for a sample leaf image. image

  • Web App Interface wai_1 wai_2


INSTALLATION

To set up the project on your local machine, follow these steps:

  1. Clone the repository:
    git clone https://github.com/krishnaura45/PotatoLife.git
    cd PotatoLife
  1. Install dependencies:
    pip install -r requirements.txt
  1. Run the Streamlit app:
    streamlit run app.py

CONTRIBUTING

  • Fork the repository.
  • Create a new branch.
  • Commit changes with clear messages.
  • Submit a pull request.
  • Ensure new features are tested and documented.

TECH STACK

  • Python: Backend logic and data handling.
  • TensorFlow: Deep learning model.
  • Streamlit: Web app development.
  • FastAPI: API interaction and server handling.
  • Postman: API testing and interaction.
  • Pillow, NumPy, Matplotlib: Image processing and visualization.

FUTURE PLANS

  • Create a mobile app
  • Emphasize on the need for FastAPI server security, including integration with Docker and measures like authentication and authorization to safeguard model and user data.

REFERENCES

  1. S. Biswas, B. Jagyasi, B. P. Singh and M. Lal, "Severity identification of Potato Late Blight disease from crop images captured under uncontrolled environment," 2014 IEEE Canada International Humanitarian Technology Conference - (IHTC), Montreal, QC, Canada, 2014, pp. 1-5, doi: 10.1109/IHTC.2014.7147519.
  2. G. Athanikar and P. Badar, “Potato Leaf Diseases Detection and Classification System”, IJCSMC, Vol. 5, Issue. 2, February 2016, pg.76 – 88
  3. Rabbia Mahum, Haris Munir, Zaib-Un-Nisa Mughal, Muhammad Awais, Falak Sher Khan, Muhammad Saqlain, Saipunidzam Mahamad & Iskander Tlili. A novel framework for potato leaf disease detection using an efficient deep learning model, Human and Ecological Risk Assessment: An International Journal; 2022.
  4. Chakraborty KK, Mukherjee R, Chakroborty C, Bora K. Automated recognition of optical image based potato leaf blight diseases using deep learning. Physiological and Molecular Plant Pathology. 2022;117:101781

Contributors

  • Krishna Dubey (Data Collection / Machine Learning / API Development / Web App Development)
  • Pankaj Kumar Giri (API Code Help)

About

🥔Potato Disease Detection 📸Image Processing 🧮Custom CNN 🌐FastAPI & Streamlit

Topics

Resources

Stars

Watchers

Forks