Plant Disease Classifier with Azure AI Custom Vision and Blazor


In the realm of agriculture, early detection and treatment of plant diseases are crucial for maintaining the health of crops and ensuring food security. With the advent of artificial intelligence (AI), particularly Azure AI Custom Vision service, farmers and agronomists now have a powerful tool at their disposal to identify and manage plant diseases more efficiently than ever before.


Azure AI Custom Vision is a cognitive service that enables users to build custom image classifiers using machine learning. It is particularly well-suited for applications such as a plant disease classifier due to its robust feature set and ease of use.

Step 1. Data collection

The first step in building a classifier model is to collect a dataset of plant images. These images should include a variety of plants, both healthy and diseased, under different conditions and stages of infection.

For this example we collected the images from Kaggle, you can download them here.

Step 2. Data tagging

Once the dataset is collected, each image must be tagged with labels indicating whether the plant is healthy or specifying the type of disease present. This step is critical as it serves as the foundation for training the AI model.

The images from Kaggle are already tagged by folder, also there are images for training and validation.

Step 3. Azure AI service creation

From the Azure Portal, search the Azure AI multi-service account and create an account.

Azure AI service multi-service


For this example, the instance name is ccoronado-multi-services.

Create Azure AI services


Step 4. Model training

With the data prepared, the next step is to upload it to the Custom Vision portal and train the model. Azure AI provides a user-friendly interface to upload images and train the model without the need for deep technical knowledge in machine learning.

Open another tab and go to the Custom Vision Portal. You must sign in with the Microsoft account that you used earlier. Click on New Project.

Type the project name and select the resource. Pick Classification as Project Type, then Multiclass and General [A2] as Domain, then Create Project.

Custom vision

Click on Add Images to upload the plant images. We uploaded 70 images per tag for this example.


You must add the tag of the uploaded images.


Repeat the same for all the tags you want your model to classify and click on Train.

Image upload

Trainning images

Choose Quick Training and click on Train.

Choose quick trainning

This can take between 10 and 15 minutes, based on the number of images you tagged.

Step 5. Model evaluation and iteration

After training, the model’s performance must be evaluated using a separate set of test images. Based on the results, further iterations may be necessary to improve accuracy by adjusting parameters or adding more data.


You will see three metrics

  • Precision: It's the percentage of identified classifications that were correct. For example, if the model identified 100 images as apples and 99 of them were apples, then the precision is 99 percent
  • Recall: It's the percentage of actual classifications that were correctly identified. For example, if there were 100 images of apples, and the model identified 80 as apples, the recall is 80 percent.
  • Average precision (AP): AP is the area under the precision/recall curve (precision plotted against recall for each prediction made).

The Probability Threshold is the desired level of confidence that a prediction needs to have to be considered correct. When you interpret prediction calls with a high probability threshold, they tend to return results with high precision at the expense of recall. That is, the detected classifications are correct, but many remain undetected. A low probability threshold does the opposite: most of the actual classifications are detected, but there are more false positives within that set. With this in mind, you should set the probability threshold according to the specific needs of your project. By default, the probability threshold is 50% and can be set between 0% and 100%.

You can test the model by clicking on Quick Test. Upload any plant image (from the valid folder and tags you used for training) to test the model.

Browse local files

Using model trained in

Browse local files

Step 6. Deployment and Integration

Once satisfied with the model’s performance, it can be deployed and integrated into applications or systems used by farmers and agricultural experts. The Custom Vision service allows for easy integration via APIs.

Click on Publish and type the model name, then select the prediction resource. Finally, click on Publish.

Click on publish model

Click on the Prediction URL and copy the Prediction Key.

Plant diseases classifier

How to use the prediction API

Now, we are going to integrate this model into a Blazor web app. Clone this repository.

Open the appsettings.json file and paste the settings.

"AzureVisionSettings": {
  "PredictionKey": "",
  "Endpoint": "",
  "ProjectId": "",
  "PublishedModelName": ""
  • Endpoint: For this example is
  • ProjectId: From the Custom Vision portal click on Settings. You can get it from the URL as well.
  • PublishedModelName: The name you typed before to publish the model. For this example it is Iteration1

Once you added the settings, you can run the app and test it. Use the images from the valid folder, for each test you can see the resulting tag and the probability for all the tags included in the training.

Upload image

Plant diseases predictions

Classify image


The Azure AI Custom Vision service offers a transformative approach to tackling plant diseases. By leveraging AI for image classification, it is possible to build a Plant Diseases Classifier model that can significantly aid in the early detection and treatment of crop diseases. This not only contributes to healthier crops but also promotes sustainable farming practices and food security on a global scale.

Thanks for reading

Thank you very much for reading. I hope you found this article interesting and may be useful in the future. If you have any questions or ideas you need to discuss, it will be a pleasure to collaborate and exchange knowledge.

Similar Articles