Path: blob/master/site/en-snapshot/hub/tutorials/cropnet_cassava.ipynb
25118 views
CropNet: Cassava Disease Detection
This notebook shows how to use the CropNet cassava disease classifier model from TensorFlow Hub. The model classifies images of cassava leaves into one of 6 classes: bacterial blight, brown streak disease, green mite, mosaic disease, healthy, or unknown.
This colab demonstrates how to:
Load the https://tfhub.dev/google/cropnet/classifier/cassava_disease_V1/2 model from TensorFlow Hub
Load the cassava dataset from TensorFlow Datasets (TFDS)
Classify images of cassava leaves into 4 distinct cassava disease categories or as healthy or unknown.
Evaluate the accuracy of the classifier and look at how robust the model is when applied to out of domain images.
Imports and setup
Dataset
Let's load the cassava dataset from TFDS
Let's take a look at the dataset info to learn more about it, like the description and citation and information about how many examples are available
The cassava dataset has images of cassava leaves with 4 distinct diseases as well as healthy cassava leaves. The model can predict all of these classes as well as sixth class for "unknown" when the model is not confident in it's prediction.
Before we can feed the data to the model, we need to do a bit of preprocessing. The model expects 224 x 224 images with RGB channel values in [0, 1]. Let's normalize and resize the images.
Let's take a look at a few examples from the dataset
Model
Let's load the classifier from TF Hub and get some predictions and see the predictions of the model is on a few examples
Evaluation & robustness
Let's measure the accuracy of our classifier on a split of the dataset. We can also look at the robustness of the model by evaluating its performance on a non-cassava dataset. For image of other plant datasets like iNaturalist or beans, the model should almost always return unknown.
Learn more
Learn more about the model on TensorFlow Hub: https://tfhub.dev/google/cropnet/classifier/cassava_disease_V1/2
Learn how to build a custom image classifier running on a mobile phone with ML Kit with the TensorFlow Lite version of this model.