An Interest In:
Web News this Week
- April 19, 2024
- April 18, 2024
- April 17, 2024
- April 16, 2024
- April 15, 2024
- April 14, 2024
- April 13, 2024
Paddy Disease Classification using Azure AI
Rice (Oryza sativa) is one of the staple foods worldwide.
Paddy, the raw grain before removal of husk, is cultivated in tropical climates, mainly in Asian countries. Paddy cultivation requires consistent supervision because several diseases and pests might affect the paddy crops, leading to up to 70% yield loss. Expert supervision is usually necessary to mitigate these diseases and prevent crop loss. With the limited availability of crop protection experts, manual disease diagnosis is tedious and expensive. Thus, it is increasingly important to automate the disease identification process by leveraging computer vision-based techniques that achieved promising results in various domains.
Data
Data is taken from Paddy Disease Classification Dataset from Kaggle We have taken a subset of the data provided in the dataset to demonstrate the power of Azure Cognitive Services
I have made a small dataset from the parent dataset in Kaggle mentioned above for quick experimentation. The data has around 100 images of each of the classes bacterial_leaf_blight, bacterial_leaf_streak , bacterial_panicle_blight , blast , brown spot , dead heart , downy mildew , hispa , normal and tungro
The steps to model and predict for this problem are as follows:
- Create a Custom Vision AI project
- Add Images to the project
- Train on the images and create the model
- Publish the model and expose the endpoint for use by other clients
- Use the exposed endpoint and predict using new images
Create a Custom Vision AI project
Navigate to https://www.customvision.ai/projects to create a custom vision project.
We created a project with
Name - paddy
Project Type - Classification. Since we are classifying whether the image is having bacterial_leaf_blight, bacterial_leaf_streak , bacterial_panicle_blight , blast , brown spot , dead heart , downy mildew , hispa , normal and tungro
Classification Type - Multiclass. There are 2 choices here, Multiclass and Multilabel. We choose Multiclass since the image is associated with only one class ( bacterial_leaf_blight, bacterial_leaf_streak , bacterial_panicle_blight , blast , brown spot , dead heart , downy mildew , hispa , normal and tungro ). A single image is not associated with multiple classes.
If a single image was associated with multiple classes, then we had to choose the Classification type as Multilabel.
Add Images
We upload the bacterial_leaf_blight images and also tag them.
We also add images of other classes
bacterial_leaf_streak , bacterial_panicle_blight , blast , brown spot , dead heart , downy mildew , hispa , normal and tungro
# Train the images
We train the images by clicking the Train button in the portal
Training
We can select Quick Training or Advanced Training for training the images
We choose Advanced Training to train the images. Each of the 10 classess have around 100 images .
We do model training and we can see the various iterations
This is the output of the 4th Iteration [ Advanced Training ] . In Advanced Training, we can limit the budget by specifying the time duration
Publish
We can now Publish the model so that we can use the endpoint of the model for the prediction of unseen images.
Project details
We display the Azure Cognitive project which has the project id, the published endpoint. This will be used for predicting the unseen test images.
Prediction
Import the libraries
from azure.cognitiveservices.vision.customvision.training import CustomVisionTrainingClientfrom azure.cognitiveservices.vision.customvision.prediction import CustomVisionPredictionClientfrom azure.cognitiveservices.vision.customvision.training.models import ImageFileCreateBatch, ImageFileCreateEntry, Regionfrom msrest.authentication import ApiKeyCredentialsimport os, time, uuid
Set the parameters
ENDPOINT = "https://eastus.api.cognitive.microsoft.com/"training_key = "17eebfa6efd94be791052ff85de02409"prediction_key = "17eebfa6efd94be791052ff85de02409"prediction_resource_id = "paddy"project_id = "2f447d24-e99b-4e72-83be-08467a43d4d0"publish_iteration_name = "paddy_model"
Complete the prediction
base_image_location = os.path.join (os.path.dirname(__file__), "train_images")# Now there is a trained endpoint that can be used to make a predictionprediction_credentials = ApiKeyCredentials(in_headers={"Prediction-key": prediction_key})predictor = CustomVisionPredictionClient(ENDPOINT, prediction_credentials)with open(os.path.join (base_image_location, "blast/110406.jpg"), "rb") as image_contents: results = predictor.classify_image( project_id, publish_iteration_name, image_contents.read()) # Display the results. for prediction in results.predictions: print("" + prediction.tag_name + ": {0:.2f}%".format(prediction.probability * 100))
References
Original Link: https://dev.to/ambarishg/paddy-doctor-paddy-disease-classification-1b7i
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To