Skip to Content

Processing Image Data with SAP Leonardo Machine Learning Foundation services on the API Business Hub

Previous

Processing Image Data with SAP Leonardo Machine Learning Foundation services on the API Business Hub

By Abdel DADOUCHE

Discover the SAP Leonardo Machine Learning Functional Service consuming images content on the SAP API Business Hub

Details

You will learn

In this tutorial, you will learn where to find and test the SAP Leonardo Machine Learning Functional Services published on the SAP API Business Hub that consumes images content.

This service allows you to calculates and returns a list of classifications/labels along with their probabilities for a given image.

The Image Classification Machine Learning Functional Services will be used as an example to demonstrate how to consume image content, but you will be able to transpose this tutorial to other services which also consume images content like :

  • the Image Feature Extraction API
  • the Product Image Classification API
Step 1: Search the SAP API Business Hub

In order to consume the Image Classification Machine Learning Functional Services, you will first need to get the service URI, request and response parameters.

Go to https://api.sap.com/ and click on the Browse tile.

SAP API Business Hub

Then you will be able to search for the SAP Leonardo Machine Learning - Functional Services, then click on the package found.

SAP API Business Hub
Please log in to access this content.
Step 2: Analyze the service

Click on Artifacts, then click on the Image Classification API.

SAP API Business Hub

As you can notice the Image Classifier Service has only one resource (or service): /inference_sync.

Now click on the /inference_sync link to expand the section.

Note: the term inference refers to the application phase (scoring) an existing model (as opposed to the training or inception phase) and sync for synchronous.

SAP API Business Hub

As stated in the description, the service accepts either an archive file with a zip/tar extensions containing multiple image files, a single image or a list of image as input and returns a classification list with its scores (confidence). The supported image formats are “JPEG”, “PNG”, “TIF” or “BMP” (the actual content format is validated, so renaming files may simply not work).

The input file, files or archive file will be sent as a FormData query parameter in the service request.

And the response model schema is the following:

{
  "_id": "string",
  "error": "string",
  "request": "string",
  "predictions": [
    {
      "name": "string",
      "results": [
        {
          "label": "string",
          "score": 0
        }
      ]
    }
  ],
  "status": "QUEUED",
  "tenantName": "string",
  "error_description": "string"
}
Please log in to access this content.
Step 3: Test the service

Now, scroll down a bit further and click on login-to-try-out. You will be prompted for your SAP Cloud Platform credentials.

Scroll up a little for the Query Parameters section and click on the Browse button next to files parameter.

SAP API Business Hub

Select any image file on your local machine (and if you are missing some inspiration, use Google Search to search for duck images and make sure you pick a “JPEG”, “PNG”, “TIF” or “BMP” format with a resolution below 1024 pixels else you will receive a 400 error response).

Now scroll down a bit further and click on try-out.

Please take a note of the Request URL which we will use later:

https://sandbox.api.sap.com/ml/imageclassifier/inference_sync

In the Response Body, you will get the top 5 classes/label with an associated score (that sums up to 1).

{
  "_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "predictions": [
    {
      "name": "Duck.jpeg",
      "results": [
        {
          "label": "drake",
          "score": 0.999675
        },
        {
          "label": "goose",
          "score": 0.000313
        },
        {
          "label": "European gallinule",
          "score": 0.000004
        },
        {
          "label": "toucan",
          "score": 0.000003
        },
        {
          "label": "red-breasted merganser",
          "score": 0.000002
        }
      ]
    }
  ],
  "processed_time": "Mon, 31 Jul 2017 13:03:29 GMT",
  "request": {
    "files": [
      "Duck.jpeg"
    ],
    "options": {},
    "tenantName": "imgclassif-tech-user",
    "texts": []
  },
  "status": "DONE",
  "tenantName": "imgclassif-tech-user"
}
Please log in to access this content.
Step 4: Validation

Provide an answer to the question below then click on Validate.

Based on the provided documentation, which file archive format are supported by the service from the
following list?
×

Optional

Step 5: Investigate similar services

You can also try the following Machine Learning Functional Services consuming images:

  • the Image Feature Extraction API
  • the Product Image Classification API

Alternatively, you can try to compress into a zip a series of images and call the service.

For more information, you can also check the online SAP Leonardo Machine Learning Foundation documentation

Please log in to access this content.

Next Steps

Updated 03/27/2018

Time to Complete

10 Min

Beginner

Next Steps

Next
Back to top