This classifier is built with CNN models, and can be deployed both by a website application and a mobil application. It has the functionality of determine around 10 different diseases of pomato/tomato based on a photo of their leaf. The trained models have average accuracy around 95% and confidence above 97% for most cases.
Code reference: https://github.com/codebasics/potato-disease-classification
Tutorial reference: https://www.youtube.com/playlist?list=PLeo1K3hjS3ut49PskOfLnE6WUoOp_2lsD
-
Install Python3.8 (https://www.python.org/downloads/release/python-380/)
-
Install Python packages
pip3 install -r training/requirements.txt
pip3 install -r api/requirements.txt
- Install Tensorflow Serving (Setup instructions)
- Install Nodejs (Setup instructions)
- Install NPM (Setup instructions)
- Install dependencies
cd frontend
npm install --from-lock-json
npm audit fix
- Change API url in
.env
is needed.
-
Go to the React Native environment setup, then select
React Native CLI Quickstart
tab. -
Install dependencies
cd mobile-app-potato
yarn install
- 2.1 Only for mac users
cd ios && pod install && cd ../
- Change API url in
.env
is needed.
We use a convolutional neural network with data resizing and rescaling in the input layer, and Softmax activation function in the output layer. We also implemented data augumentation to imporve the performance. You can change the CNN architecture in the middle layers for a better performance if needed.
models/1 is the trained model for potato disease classification, and models/2 is the trained model for tomamto disease classification. If you want to train the model by yourself, you can follow the steps below.
- Download the data from kaggle.
- Only keep folders related to Potatoes/Tomato.
- Run Jupyter Notebook in Browser.
jupyter notebook
- Open
training/potato-disease-training.ipynb
ortraining\potato-disease-classification-model-using-image-data-generator.ipynb
in Jupyter Notebook. - In cell #2, update the path to dataset.
- Follow the instructions in the notebook. Change variables values (i.e. n_classes) for potato/tomate respectively.
- Run all the Cells one by one.
- Copy the model generated and save it with the version number in the
models
folder.
- Get inside
api
folder
cd api
- Run the TF Serve
docker run -t --rm -p 8501:8501 -v C:/Code/potato-disease-classification:/potato-disease-classification tensorflow/serving --rest_api_port=8501 --model_config_file=/potato-disease-classification/model.config.a
- Run the FastAPI Server using uvicorn For this you can directly run it from your main.py using pycharm run option (as shown in the video tutorial) OR you can run it from command prompt as shown below,
uvicorn main:app --reload --host 0.0.0.0
- Your API is now running at
0.0.0.0:8000
- Get inside
api
folder
cd frontend
- Run the frontend
npm run start
- On the homepage, you can select to predict potato disease or tomato disease. Then you can upload the image on the website to get the predictions. Showcase as below:
https://us-central1-crafty-dynamics-328022.cloudfunctions.net/predict_potato
https://us-central1-crafty-dynamics-328022.cloudfunctions.net/predict_tomato
- 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.
cd gcp
gcloud functions deploy predict_potato --runtime python38 --trigger-http --memory 512 --project project_id
cd gcp
gcloud functions deploy predict_tomato --runtime python38 --trigger-http --memory 512 --project project_id
- Your model is now deployed.
- Use Postman to test the GCF using the Trigger URL.
- Get inside
mobile-app-potato
folder
cd mobile-app-potato
-
Update
URL
to API URL in.env
if needed. -
Run the app (android/iOS)
npm run android
or
npm run ios
-
Creating public (signed APK)
-
Run the same steps for tomato disease classification in
mobile-app-tomato
folder
Note: currently still facing some compile errors on my local machine, the showcase is from https://www.youtube.com/watch?v=mSf0j8qkkFI&list=PLeo1K3hjS3ut49PskOfLnE6WUoOp_2lsD&index=8
For future improvement, I will fix the compile errors for the mobile app and combine the two mobile apps for tomato and potato into one.
I will also collect dataset and train the models to detect more kinds of plant diseases.