Step 3 - Classify an Image
Now that the data is uploaded and you created a model, you’re ready to use it to make predictions.
You send an image to the model, and the model returns label names and probability values. The probability value is the prediction that the model makes for whether the image matches a label in its dataset. The higher the value, the higher the probability.
You can classify an image in these ways.
- Reference the file by a URL
- Upload the file by its path
- Upload the image in a base64 string
For this example, you’ll reference this picture by the file URL.
- In the following command, replace:
<TOKEN>with your JWT token
<YOUR_MODEL_ID>with the ID of the model that you created when you trained the dataset
Then run the command from the command line.
The model returns results similar to the following.
The model predicts that the image belongs in the beach label, and therefore, is a picture of a beach scene. The numeric prediction is contained in the
probability field, and this value is anywhere from 0 (not at all likely) to 1 (very likely).
In this case, the model is about 98% sure that the image belongs in the beach label. The results are returned in descending order with the greatest probability first.
If you run a prediction against a model that’s still training, you receive an error that the model ID can't be found.
The dataset used for this scenario contains only 99 images, which is considered a small dataset. When you build your own dataset and model, follow the guidance on the Dataset and Model Best Practices page and add a lot of data.
You can also classify a local image by uploading the image or by converting the image to a base64 string. To upload a local image, instead of the
sampleLocation parameter, pass in the
sampleContent parameter, which contains the image file location of the file to upload.
See the Prediction with Image File and Prediction with Image Base64 String sections of Prediction.
Creating the dataset and model are just the beginning. When you create your own model, be sure to test a range of images to ensure that it’s returning the results that you need.
You’ve done it! You’ve gone through the complete process of building a dataset, creating a model, and classifying images using the Einstein Image Classification API. You’re ready to take what you’ve learned and bring the power of deep learning to your users.