Using TensorFlow to create an image classification for plant diseases in Python.
- TensorFlow
- numpy
- matplotlib
- fast API
- uvicorn
- IO
- PIL
to convert image byte data to an array
conda install numpy
for creating models
conda install tensorflow
for visualizing model
conda install matplotlib
for creating web API
conda install fastapi
for creating ASGI web server implementation in Python
pip install uvicorn
to deal with the bytes data
pip install Python-IO
for cleaning the CSV file data
pip install pillow
9. install npm in the "frontend" directory. 1
npm install
Important
a. Run the file "step_6.py" in the 'api' directory.
- Open the "Postman" application.
- Select the "POST" method.
- Use this URL to send the data "http://localhost:8000/predict". (The port can be changed by you)
- Select "File" as the 'Key' and name it "file" and Select the image of your choice as 'Value' in the 'Body' label. 2
- It should display the Class of the Disease and the Confidence in the answer.
like this
{ "class": "Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot", "confidence": 0.9990307092666626 }
- Open the docs page for your API "http://localhost:8000/docs".
- Expand the "POST" tab.
- Click "Try it out" and Select the image of your choice and the "File" input. 2
- Click "Execute"
- It should display the Class of the Disease and the Confidence in the answer. (as a response)
like this
{ "class": "Apple___Apple_scab", "confidence": 0.9999998807907104 }
- Start the website.
npm run start
- drag and drop the image of your choice 2
- It should display the Class of the Disease and the Confidence in the answer. (as a response)
Note
- Remember to perform the initial setup before test-driving.
- Your API program should always run when test-driving.
- Your testing and training machine should be the same.
NVIDIA Trained model will not run on the AMD machine
Footnotes
-
I had to do this for running the website. in the "Frontend" directory {where npm is installed}
set NODE_OPTIONS=--openssl-legacy-provider. if this doesn't work then manually change"start": "react-scripts start"to"start": "react-scripts --openssl-legacy-provider start"In your "package.json" file ↩ -
I would suggest that you use an image from the "DATA/test/Apple___Apple_scab" directory 😅 The model is still weak and it cannot identify complex images 😅😅 ↩ ↩2 ↩3