Skip to Content

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

 

 

To report this post you need to login first.

13 Comments

You must be Logged on to comment or reply to a post.

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

    (0) 
    1. 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

       

      (0) 
  2. Fabian Lehmann 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

    (0) 
  3. 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

     

    (1) 
    1. Fabian Lehmann 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

      (0) 
  4. Former Member

    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

    (0) 
    1. Fabian Lehmann 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

      (0) 
      1. 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

        (0) 
        1. Fabian Lehmann 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

          (0) 
    2. Former Member

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

       

      Thanks

      Sudarshan

      (0) 
      1. Former Member

        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”,

        (1) 
  5. 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

    (0) 
    1. Fabian Lehmann 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

       

      (0) 

Leave a Reply