Bell pepper is one of the most important crops globally, and bell pepper plants are susceptible to various diseases, which can lead to significant economic loss for farmers. Traditional methods for disease detection are often time-consuming and require expert knowledge. The aim of this project is to develop a mobile application that can quickly and accurately detect bell pepper plant diseases using image classification with deep learning, to help farmers identify and treat diseases in their crops.
The proposed solution is to use deep learning techniques, specifically convolutional neural networks (CNNs), to classify images of bell pepper plants as either healthy or diseased. The model will be trained on a dataset of labeled images of bell pepper plants, using techniques such as data augmentation to increase the size of the dataset and improve the model's accuracy. The trained model will be deployed on a mobile application, which farmers can use to take a picture of a bell pepper plant and get an instant diagnosis of whether the plant is healthy or diseased. The application will be built using React JS and React Native for the frontend, with a backend server using FastAPI and TensorFlow Serving for ML ops. The model will also be optimized using techniques such as quantization and TensorFlow Lite to improve its performance on mobile devices.
- Python
- FastAPI
- TensorFlow Serving
- Machine learning algorithms
- TensorFlow
- Front End: JavaScript, CSS, HTML, React JS, React Native
- Google Cloud Platform (GCP) account
- Access to Google Cloud Functions (GCF) for deployment
- Labeled dataset of images of bell pepper plants
- Mobile device or simulator to test the application
Before we run the project, make sure you have Google Cloud account to access the service like Google Cloud Platform (GCP) and Google Cloud Functions (GCF).
git clone https://github.com/sverma1999/BellPepper_Classification.git
conda create -n pepper_dl python=3.8.15 -y
conda activate pepper_dl
pip install -r training/requirements.txt
pip install -r api/requirements.txt
- Download the data from kaggle.
- Only keep folders related to Bell Pepper.
- Run Jupyter Notebook in Browser.
jupyter notebook
- Open training/model-training-second.ipynb in Jupyter Notebook.
- Update all the paths.
- Run all the Cells one by one.
- Copy the model generated and save it with the version number in the models folder.
- Run the API locally using FastAPI
cd api
python main.py
Go to Postman application and send a POST request to http://localhost:8659/predict with the image in the body.
You should get a response like this:
{
"class": "Bacterial_spot",
"confidence": 0.9955774545669556
}
-
Run the API locally using Docker for tf serving and FastAPI
TensorFlow Serving is a key tool in the machine learning deployment pipeline that allows you to easily and efficiently serve your models at scale with high performance and reliability.
First, run the docker image of tensorflow serving
cd BellPepper_Classification
docker run -t --rm -p 8550:8550 -v <full path to BellPepper_Classification>:/BellPepper_Classification tensorflow/serving --rest_api_port=8550 --model_config_file=/BellPepper_Classification/models.config
then, run the FastAPI
cd api
python main_tfServing.py
Go to Postman application and send a POST request to http://localhost:8659/predict with the image in the body.
You should get a response like this:
{
"class": "Bacterial_spot",
"confidence": 0.9955774545669556
}
- Install Nodejs
- Install NPM
- Install dependencies
cd frontend
npm install --from-lock-json
npm audit fix
- Copy .env.example as .env.
- Change API url in .env.
- Get inside frontend folder
cd frontend
- Copy the .env.example as .env and update REACT_APP_API_URL to API URL if needed.
- Run the frontend
npm run start
- Go to the React Native environment setup, then select React Native CLI Quickstart tab.
- Install dependencies
cd mobile-app
yarn install
cd ios && pod install && cd ../
- Copy .env.example as .env.
- Change API url in .env.
Make sure you have latest Xcode installed and simulator "iPhone 12" with iOS 16.2 or 16.4 is available.
- Click on the "mlDemo.xcworkspace"
- Open mlDemo
- Click Products -> Product (from the menu bar) -> Clean Build Folder
- Once clean build is done, click on Products -> Product (from the menu bar) -> Build
It should open "Metro Bundler" terminal and start building the app. It should ask something like this:
To reload the app press "r"
To open developer menu press "d"
Wait for indexing and initializing datastore process to complete.
- Enter "r" to reload the app.
Click on Podfile, and click Products -> Product (from the menu bar) -> Build
Again, click on Products inside Pods folder, and click Products -> Product (from the menu bar) -> Build
- Go to your VS code terminal and open iOS folder and build the app.
cd ios
npm run ios
Usually it will open the simulator and run the app, but sometimes it doesn't. if you recieve an error like this:
success Successfully built the app
...
...
error Failed to launch the app on simulator, An error was encountered processing the command (domain=com.apple.CoreSimulator.SimError, code=405):
Unable to lookup in current state: Shutdown
Can be done similar with android app.
- Create a GCP account.
- Create a Project on GCP (Keep note of the project id).
- Create a GCP bucket.
- Upload the tf .h5 model generate in the bucket in the path models/potato-model.h5.
- Install Google Cloud SDK Setup instructions.
- Authenticate with Google Cloud SDK.
gcloud auth login
- Run the deployment script inside gcp folder.
cd gcp
gcloud functions deploy predict --runtime python38 --trigger-http --memory 512 --project project_id
- Your model is now deployed.
- Now, go to cloud functions and copy the Trigger URL.
- Use Postman to test the GCF using the Trigger URL.
converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
tflite_quant_model = converter.convert()
I want to aknowledge that I took help from Codebasics (https://www.youtube.com/@codebasicsHindi). This is a guided project.