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:
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:
API URL´s:
OAuth API URL:
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":
Additional to these parmeters i just define another one to acces later my "tenant" in Postman via a variable.
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_credential...
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):
Body definition:
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