Einstein Platform Services

Step 3: Classify an Image

Now that the data is uploaded and you created a model, you’re ready to use the model to make predictions.

You send an image to the model, and for each object the model identifies, the model returns a label, a probability, and the coordinates for a bounding box around the object. The probability value is the prediction that the model makes for whether the identified object matches the label. 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

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/alpine.jpg" -F "modelId=BN2PTZQ6U2F7ORW57ZIZWZWRDQ" https://api.einstein.ai/v2/vision/detect

The model returns results similar to the following.

{
  "probabilities": [
    {
      "label": "Alpine - Oat Cereal",
      "probability": 0.993008,
      "boundingBox": {
        "minX": 2149,
        "minY": 936,
        "maxX": 2896,
        "maxY": 1927
      }
    },
    {
      "label": "Alpine - Corn Flakes",
      "probability": 0.98303485,
      "boundingBox": {
        "minX": 748,
        "minY": 935,
        "maxX": 1440,
        "maxY": 1900
      }
    },
    {
      "label": "Alpine - Bran Cereal",
      "probability": 0.9943381,
      "boundingBox": {
        "minX": 1456,
        "minY": 944,
        "maxX": 2166,
        "maxY": 1914
      }
    },
    {
      "label": "Alpine - Bran Cereal",
      "probability": 0.9913053,
      "boundingBox": {
        "minX": 2848,
        "minY": 854,
        "maxX": 3713,
        "maxY": 1997
      }
    }
  ],
  "object": "predictresponse"
}

The model predicts that there are four objects in the image: one box of oat cereal, one box of corn flakes, and two boxes of bran cereal. For each object, the model returns a high probability that the object matches the label returned.

The model also returns the x and y coordinates for each object identified in the image. This is what the image sent in for prediction looks like with bounding boxes created from the coordinates in the response.

Tell Me More

You can also classify a local image by uploading the image. 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]:\data\alpine.jpg" -F "modelId=<YOUR_MODEL_ID>" https://api.einstein.ai/v2/vision/detect

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 the model 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.