This project is a comprehensive Deep Learning solution designed to detect and classify plant diseases from leaf images. It consists of a training pipeline using TensorFlow/Keras and a deployment API for serving predictions.
The project is divided into two main components:
- Model Training (
Train_plant_disease_model.ipynb): A Jupyter Notebook that handles data ingestion, augmentation, and training of a Convolutional Neural Network (CNN). - Inference API (
plant-apiRepo): A backend service that serves the trained model to make real-time predictions.
The model is trained using the New Plant Diseases Dataset.
- Source: Kaggle - New Plant Diseases Dataset
- Classes: The model is trained to recognize 38 unique classes, including healthy and diseased states of Apple, Corn, Grape, Potato, Tomato, and more.
- Image Size: Images are resized to
128x128pixels.
- Data Loading & Preprocessing:
- Dataset is downloaded using
opendatasets. - Images are loaded into training and validation splits with a batch size of 32.
- Dataset is downloaded using
- Data Augmentation:
- To improve generalization, the following augmentations are applied:
RandomFlip,RandomRotation(0.1), andRandomContrast(0.1).
- To improve generalization, the following augmentations are applied:
- Model Architecture:
- A custom CNN architecture is used, consisting of 5 blocks of
Conv2D,BatchNormalization,ReLU, andMaxPooling2Dlayers. - The head of the network includes a
Flattenlayer, aDenselayer (1024 units), and a finalDenseoutput layer with Softmax activation for 38-class classification.
- A custom CNN architecture is used, consisting of 5 blocks of
- Artifacts:
- Model: Saved as
plant_disease_classification.keras. - Class Labels: Saved as
class.json.
- Model: Saved as
The deployment code is hosted in the plant-api repository.
- Python 3.x
- TensorFlow
- FastAPI (or the framework defined in the repo)
- Pillow, NumPy
-
Clone the API repository:
git clone [https://github.com/biswajr/plant-api.git](https://github.com/biswajr/plant-api.git) cd plant-api -
Prepare Model Artifacts:
- Copy the trained model
plant_disease_classification.kerasfrom the training output to the API directory. - Copy the
class.jsonfile to the API directory.
- Copy the trained model
-
Install Dependencies:
pip install -r requirements.txt
-
Run the Server: (Assuming FastAPI/Uvicorn)
uvicorn main:app --reload or python -m uvicorn main:app --reload --host 0.0.0.0 --port 3000
Endpoint: /predict
Method: POST
Request:
Upload an image file via multipart/form-data.
Example using cURL:
curl -X 'POST' \
'http://localhost:8000/predict' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'file=@test_leaf.jpg;type=image/jpeg'Feel free to open issues or submit pull requests if you have suggestions for improving the model architecture or API performance.
This project is open-source. Please check the specific license files in the repository for details.