Skip to Content
Author's profile photo Fabian Lehmann

Getting started with SAP Leonard ML Foundation on SAP Cloud Platform Cloud Foundry

Introducing

In this blog i want to cover a little “hands on” how to enable an configure SAP Leonardo ML Foundation at your SAP Cloud Platform Acc. for the Cloud Foundry Environment.

Please haave also a look at Abdel DADOUCHE intro to his blog to ML series: Introducing “Project: Machine Learning in a Box”

For Details about the Features pls check the official docu here.

And the official SAP Cloud Platform Page for mor details e.g. pricing here.

I want talking here abut SAP Leonardo ML Foundation “production”, this is not available in the “trial” SCP Cloud Foundry Environment.

To get your hand´s dirty, you can try SAP Leonardo Ml Foundation for free at the SAP API Business Hub

In the Upcoming blogs we’ll cover futher topics like:

 

* subject to changed

Enter the Cockpit

After we´ve successfully logged in to the “SAP Cloud Platform Cockpit” and select the correct region (in my case Europe (Frankfurt))  we enter our “Global Acc.”:

Enable the elastic plan

Afterwards lets verify the “elastic plan” by choosing the “Entitlements” entry:

And enable the standar plan:

Now we can use “hopefully” SAP Leonard ML Foundation in our space.

I just create therefore the following objects:

Object Name
Space ml
Quota Plan ml

An finally assign the “plan” to our “space”

 

Create the ml-foundation instance

Now we switch to our space and selecting in the service section the “Service Marketplace” entry.

We can now see there is now our “ml-foundation” service available:

As described in the SAP Help documentation we creating now the new “instance” and select the previous create plan:

Before we complete the creation process we enter a name of our instance:

Finally can now find our previously created instance:

Create a service key

Inside our instance we need now to create our service key to get our requeired data (credentilals / url´s)

In detail we got the following information which we need later to exute the different ML API´s:

 

Credentials:

name description
clientid OAuth client ID
appname App name
identityzone Name of your identity zone
identityzoneid Id of your identity zone
clientsecret OAuth client secret

 

API URL´s:

Service Name URL
TOPIC_DETECTION https:/<TOPIC_DETECTION API Path>.cfapps.eu10.hana.ondemand.com
DEPLOYMENT_API_URL https:/<DEPLOYMENT_API_Path>.cfapps.eu10.hana.ondemand.com
IMAGE_CLASSIFICATION https://<IMAGE_CLASSIFICATION API Path>*.cfapps.eu10.hana.ondemand.com
SIMILARITY_SCORING https://<SIMILARITY_SCORING API Path>.cfapps.eu10.hana.ondemand.com
TIME_SERIES_CHANGE_POINT https://<TIME_SERIES_CHANGE_POINT API Path>.cfapps.eu10.hana.ondemand.com
IMAGE_FEATURE_EXTRACTION https://<IMAGE_FEATURE_EXTRACTION API Path>.cfapps.eu10.hana.ondemand.com
RETRAIN_API_URL https://<RETRAIN_API_Path>.cfapps.eu10.hana.ondemand.com
MODEL_REPO_URL https://<MODEL_REPO_API_Path.cfapps.eu10.hana.ondemand.com
JOB_SUBMISSION_API_URL https://<JOB_SUBMISSION_API_Path>.cfapps.eu10.hana.ondemand.com

 

 OAuth API URL:

URL: https://<SAP CP subdomain>.authentication.eu10.hana.ondemand.com

 

Prepare Postman

To access our API endpoints wen need as described here an acces token.

For this i´am using here the Postman Chrome plugin.

After we successfully launched Postman, we need to add an new environment:

Add now a new “Environment” by entering a name:

In the parameter (key, value) section we specify now the details which we got during the creation of the “Service Key”:

Key Value
token
clientid <clientid from the service key>
appname <appnamefrom the service key>
identityzone <identityzonefrom the service key>
identityzoneid <identityzoneidfrom the service key>
clientsecret <clientsecretfrom the service key>

Additional to these parmeters i just define another one to acces later my “tenant” in Postman via a variable.

Key Value
tenant_id <you tenant id = SAP CP subaccount name>

 

Request the token

To fetch now our token we create the follwoing GET request via Postman by using our “variable” which we create earlier:

https://{{tenant_id}}.authentication.eu10.hana.ondemand.com/oauth/token?grant_type=client_credentials

Tip: To save our token directly in the used environment you can defne the following in the “Tests” section of Postman:

Important: The script which is defined in the official documentation did not work for me:

But if we use this modified script we can store the token in the right format:

postman.setEnvironmentVariable("token",
"Bearer " + JSON.parse(responseBody).access_token);

 

If we recheck our environment, we can detect the successfully stored value for our “token”:

If we check this against the response body from our request, we can see the indetical token value:

 

Execute e.g. the “Image Classifier” API

As final step in this blog we want now test the Image Classifier API with the usage of our token and by executing the following URL via HTTP POST:

https://<IMAGE_CLASSIFICATION API Path>.cfapps.eu10.hana.ondemand.com/inference_sync

Header definition:

Important: Also at this point in the documentation i´ve found a litte error. The sample code is only valid for the usage by calling the API via the API Business Hub (APIKey):

For  the productive environment we need (Authorization):

Key Value
Accept application/json
tenantName {{tenant_id}}
Authorization {{token}}

Body definition:

Type Key Value
form-data files <file or archive>

We now provide an zip archive with the following images (pls check the docu about the allowed size and dormat):

Postman request definition:

And our response:

{
    "_id": "2dd79e88-db66-4f1e-7f60-f368be417314",
    "predictions": [
        {
            "name": "2_and this.jpg",
            "results": [
                {
                    "label": "drake",
                    "score": 0.8697558045387268
                },
                {
                    "label": "traffic light, traffic signal, stoplight",
                    "score": 0.0033478103578090668
                },
                {
                    "label": "American coot, marsh hen, mud hen, water hen, Fulica americana",
                    "score": 0.002334733260795474
                },
                {
                    "label": "lakeside, lakeshore",
                    "score": 0.002084329491481185
                },
                {
                    "label": "goose",
                    "score": 0.002050255425274372
                }
            ]
        },
        {
            "name": "1_what is this.jpg",
            "results": [
                {
                    "label": "chimpanzee, chimp, Pan troglodytes",
                    "score": 0.8176430463790894
                },
                {
                    "label": "siamang, Hylobates syndactylus, Symphalangus syndactylus",
                    "score": 0.013287714682519436
                },
                {
                    "label": "file, file cabinet, filing cabinet",
                    "score": 0.003327875630930066
                },
                {
                    "label": "orangutan, orang, orangutang, Pongo pygmaeus",
                    "score": 0.0030073353555053473
                },
                {
                    "label": "patas, hussar monkey, Erythrocebus patas",
                    "score": 0.0018851504428312182
                }
            ]
        }
    ],
    "processedTime": "2018-01-29T12:30:29.078824",
    "status": "DONE"
}

 

Conclusion:

In this blog we have covered the initial step how to enable SAP Leonardo ML Foundation in the SAP CP Cloud Foundry Environment.

Futhermore we have verified our authetication credentials and finally sucessfully tested one of the availble API´s (here the Image Classification).

In one of the nex blogs we want cover how we can retrain our model and how to bring your own model (BYOM) in SAP Leonardo ML Foundation.

 

Cheers,

Fabian

 

 


Helpful links:

SAP Help: SAP Leonardo ML Foundation

Chrome Postman Plugin

SAP API Business Hub

Official SAP Cloud Platform Page – SAP Leonardo ML Foundation

 

 

Assigned Tags

      24 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Hi Fabian,

      Thanks for sharing such valuable information in this blog, this is really helpful. But looks like ml-foundation is not available in trial accounts. I tried with my trial account but i couldn't find any place from where i could add the ml-foundation. While creating the cloud foundry account it automatically assign the services from sap marketplace and there was no ml-foundation available. I searched the service marketplace as well. Appreciate if you can confirm if this service is only available for paid accounts or not and if its available in trial how to enable it. That would be helpful for most of the users here.

      Thank you.

      Regards,

      Sarabjeet

      Author's profile photo Former Member
      Former Member

      Hi Sarabjeet,

      Many thanks for your interest. We are currently working on getting a limited Trial Access on the way. The pretained, ready-to-use services can be tried out on the API Business Hub. For additional Information, you can also check out this blog.

      Best regards,
      Hannah

       

      Author's profile photo Fabian Lehmann
      Fabian Lehmann
      Blog Post Author

      Hi Former Member,

      i thought with this one, its clear we´re talking about the "productive" usage:

       

      And additional to get your hand´s dirty, you can try SAP Leonardo Ml Foundation for free at the SAP API Business Hub

      But anyway i can put this info in this blog.

       

      br,

      fabian

      Author's profile photo Rainer Betrich
      Rainer Betrich

      Hi Fabian,

       

      great blog (as always) – without your valuable input I would have to spend days to get the right http headers (for using the ml subscriptions in CF), as this hasn’t been documented so far – so great input.

      Just one remark: Authentication type needs to be bearer :-).

      It was a pleasure to follow your blog and get an up an running sample.

      Have a nice day,

      Rainer

       

      Author's profile photo Fabian Lehmann
      Fabian Lehmann
      Blog Post Author

      Hi Rainer,

       

      yes of course the docu (sap help) can/must be improved it was also for me in the begging tricky.....but now all works.

      Oh and yes right it´s berarer......my mistake.

       

      br,

      fabian

      Author's profile photo Santosh Kumar
      Santosh Kumar

      Hi Fabian,

      Thank you for the wonderful blog series. This is exactly what I wanted to get started in Leonardo ML in CF.

      I have tried SAP Canary CF instance for this, for which the image classification URL becomes : https://mlfinternalproduction-image-classifier.cfapps.sap.hana.ondemand.com/api/v2/image/classification

      I was able to generate the access token from the above mentioned method. But, when I POST image content with the required header values, I receive below error :

      Unable to authorize the request.: Error code 401: Invalid scope: ['ml-foundation-xsuaa-std!b313.functionalservice.all'] 

      I'm not sure why it would look for standard scope when I'm actually looking at internal scope. The response I received while generating access token had one of scope values as 'ml-foundation-xsuaa-int!b313.functionalservice.all' .  My best guess is that the issue is with scope. I am trying internal whereas the scope verified is standard. Is this actually possible in internal scope ?Any pointers on how to change scope and resolve this issue ?

      Thank you & Regards,

      Santosh

      Author's profile photo Fabian Lehmann
      Fabian Lehmann
      Blog Post Author

      Hi Former Member,

      i think you should rise 1st of all an ticket.

      Do u have check the sap cp cf "application role builder"?

      For me the following scopes are defined:

      br,

      fabian

      Author's profile photo Konstantin Chernega
      Konstantin Chernega

      Hello,

       

      I also ran into this issue. I get a token from Auth URL with scope parameter set to foundation-int-ml… etc, but the error message is related to std scope:

       

      {
      “error”: {
      “code”: “401”,
      “message”: “Unable to authorize the request.: Error code 401: Invalid scope: [‘foundation-std-mlfpreproduction!b164.functionalservice.all’]”,
      “requestId”: “1b8c6ebb-c2df-44af-50e5-d6d86da9c352”
      }
      }

       

      I’m also internal user. Could it be the issue?

      How can ticket be submitted?

       

      Regards,

      Konstantin

      Author's profile photo Fabian Lehmann
      Fabian Lehmann
      Blog Post Author

      Hi Konstantin,

       

      you can rise a ticket via: https://launchpad.support.sap.com/

      As component u can use: CA-ML-PLT

       

      best regards,

      fabian

      Author's profile photo Sudarshan Survepalli
      Sudarshan Survepalli

      Hi Santosh - have run into the exact same issue. Were you able to resolve this? Please can you throw some light.

       

      Thanks

      Sudarshan

      Author's profile photo Sudarshan Survepalli
      Sudarshan Survepalli

      Just tried this alternative and it works for me:

      To the Token Generation URL, also add the parameter scope with available values for your tenant.  Now I got a token that is accepted by SWAGGER for making read calls.

      "scope": "ml-foundation-xsuaa-std!b540.datamanagement.read ml-foundation-xsuaa-std!b540.datamanagement.write ml-foundation-xsuaa-std!b540.functionalservice.all ml-foundation-xsuaa-std!b540.inference ml-foundation-xsuaa-std!b540.modeldeployment.all ml-foundation-xsuaa-std!b540.modelmetering.read ml-foundation-xsuaa-std!b540.modelrepo.read ml-foundation-xsuaa-std!b540.modelrepo.write ml-foundation-xsuaa-std!b540.modelservice.read ml-foundation-xsuaa-std!b540.retrainservice.read ml-foundation-xsuaa-std!b540.retrainservice.write ml-foundation-xsuaa-std!b540.storageapi.all uaa.resource",

      Author's profile photo Jude Regy
      Jude Regy

      Hello Fabian,

      Looks like I cannot enable the cloud foundry as creation of the organization fails. I also do not see if I can see any global accounts available that I can use.

      Can we get accounts so that we can try out the tutorial?

      Thanks,

      Jude

      Author's profile photo Fabian Lehmann
      Fabian Lehmann
      Blog Post Author

      Hi Jude,

       

      as mentioned in the blog:

      I want talking here abut SAP Leonardo ML Foundation “production”, this is not available in the “trial”SCP Cloud Foundry Environment.

      Do u have a subscription to SAP Leonardo ML Foundation?

      If yes u should get an "welcome mail" with the details.

      Futhermore u need SAP CP Cf "Global Acc." as well (no trial).

       

      br,

      fabian

       

      Author's profile photo Michal Keidar
      Michal Keidar

      Hi Fabian,

      Really great blog, thanks for that.

      I went through it step by step, but in the request of the image classification I get 401 response with this message:

      "Unable to authorize the request.: Error('Incorrect padding',)"

      Any idea what have I done wrong?

      Thanks!
      Michal.

      Author's profile photo Fabian Lehmann
      Fabian Lehmann
      Blog Post Author

      Hi Michal Keidar,

      is this problem still present?

      Which API Version u are using, this blogs describes v1.

      V2 is also available but with some changes?

       

      br,

      fabian

       

      Author's profile photo Michal Keidar
      Michal Keidar

      So the problem was because the ZIP file contained 2 images.

      When I used a ZIP with only one file I also got an error, this time 400.

      This was because I used Mac OS compression method. When I compressed the file via the terminal it was successful.

      Thanks,
      Michal.

      Author's profile photo gabriel ash
      gabriel ash

      Hi In windows , when i tried to add the images in ZIP. it says

      {
      "error": {
      "code": "400",
      "message": "Invalid request: This service requires at least 1 file. Please put your file(s) into the `files` field of the POST request",
      "requestId": "2dc18a26-7ccb-4720-42ac-64e0d24f095e"
      }
      }

      Even if i add images directly in file and and files in zip.

      Author's profile photo Mohammed zahid
      Mohammed zahid

      Hi All,

       

      I am also getting the same error in Window :

       

      {
      "error": {
      "code": "401",
      "message": "Unable to authorize the request.: Token error: Access token was not prefixed with token type: Bearer",
      "requestId": "76ffd57c-3737-4d61-7f0f-d0cd62a2fe66"
      }
      }

       

      Any resolution to this ?

      I am doing below steps

      1. Set to Post
      2. Paste the Image Classifier URL and click on Send button
      Author's profile photo Mohammed zahid
      Mohammed zahid

      I am also getting the same error in Window :

       

      {
      “error”: {
      “code”: “401”,
      “message”: “Unable to authorize the request.: Token error: Access token was not prefixed with token type: Bearer”,
      “requestId”: “76ffd57c-3737-4d61-7f0f-d0cd62a2fe66”
      }
      }

       

      Any resolution to this ?

      I am doing below steps

      1. Set to Post
      2. Paste the Image Classifier URL and click on Send button
      Author's profile photo Mohammed zahid
      Mohammed zahid

      Hi All,

       

      On the step of image classifier api path, what is the path ?? I am abe to connect the access token via postman,

      can anyone provide me the API path

      Author's profile photo Praveena Subramani
      Praveena Subramani

      Hello All,

       

      Even I got this error.

      {
      “error”: {
      “code”: “401”,
      “message”: “Unable to authorize the request.: Token error: Access token was not prefixed with token type: Bearer”,
      “requestId”: “76ffd57c-3737-4d61-7f0f-d0cd62a2fe66”
      }
      }

       

      Solved by providing below two key values in Headers

      Authorization : Bearer <access token generated>

      Accept:application/json

      and

       

      provided key as files and values as the attachment  and selected form-data as data type in body

       

      Regards

      Praveena

       

       

       

       

      Author's profile photo Sabahattin Orasen
      Sabahattin Orasen

      Hi Community,

      you may have issues to request the token as I did.
      I would recommend you guys to have a look at the latest tutorial from the SAP Hana Academy.

      I hope I was able to help your headache. 🙂

      "Leonardo ML Foundation: Inference - Image Classification"
      https://www.youtube.com/watch?v=ozKp4dlZW5g&index=5&list=PLkzo92owKnVzGkWq8Ge2q1lOWeYcBoK0q

      Author's profile photo Mohammed zahid
      Mohammed zahid

      Dear expert .

       

      I am able to connect my ML to swagger and test it , which is working perfect.

      But when it comes to postman - it gives me error as " Invalid file format" tho everything ( image) is same . but when I am trying to use via post man is it not working .

       

      Can you tell me which one to use ??

      I have build my account - activated the service and follow this blog completely and things are working fine now .

       

      I want to know weather we really need to use postman ? or not ? or swagger will be sufficient ?

      What I understand is we use postman to get the token ( Oauth2) and we use this in Swagger .  ?? Is it correct??

       

      Thanks and regards,

      ZAHID

      Author's profile photo anurag satapathy
      anurag satapathy

      Hi, Thanks for the guidance in ML,

      In token parameter am getting ''Bearer undefined".

      Please help