Einstein Platform Services

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.

  1. 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.

curl -X POST -H "Authorization: Bearer <TOKEN>" -H "Cache-Control: no-cache" -H "Content-Type: multipart/form-data" -F "sampleLocation=http://einstein.ai/images/546212389.jpg" -F "modelId=<YOUR_MODEL_ID>" https://api.einstein.ai/v2/vision/predict

The model returns results similar to the following.

{
  "probabilities": [
    {
      "label": "Beaches",
      "probability": 0.97554934
    },
    {
      "label": "Mountains",
      "probability": 0.024450686
    }
  ],
  "object": "predictresponse"
}

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.

Caution

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.

Tell Me More

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.

curl -X POST -H "Authorization: Bearer <TOKEN>" -H "Cache-Control: no-cache" -H "Content-Type: multipart/form-data" -F "[email protected]:\Mountains vs Beach\Beaches\546212389.jpg" -F "modelId=<YOUR_MODEL_ID>" https://api.einstein.ai/v2/vision/predict

See Prediction with Image File and Prediction with Image Base64 String.

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.

Updated 3 months ago

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.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.