Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
fabianl
Product and Topic Expert
Product and Topic Expert
To continue the entire blog series about SAP Leonardo Foundation:

In this blog we want now coverin one of the interesting parts for me.

 

How to bring your own model up an running with SAP Leonardo ML Foundation.

In detail we will execute the following:

  • Adding a Tensorflow model to SAP Leonardo ML Foundation

  • Deploy the model

  • Create the python app an run it

    • a) local,

    • b) on cloud foundry





Prerequisite


As documented here we need:

  • The Cloud Foundry CLI (link)

  • Important: The Postman "native" app (not the chrome plugin)

  • Python, version 2 >=2.7.9 or Python 3 >=3.4


Additional i'am using Docker to to run my "local" app in a container.

 

Download the Tensorflow Model Archive


The first thing is an Tensorflow as described in the docu, the model supports currently Tensorflow 1.3 (EU10).

Futhermore we expect that the model is exported in the "Saved_Model format".

We are using here as well as in the official docu the Google inception model.

A suitable version which works u can get from here: https://s3-ap-southeast-1.amazonaws.com/i305731/teched/inception.zip

 

Add the model to the repository


Execute a new request with the "Postman" nativ application.





















HTTP Method POST
URL <MODEL_REPO_URL>
Path api/v1/models/sap_community_example/versions
HEADER Authorization (OAuth2 Access Token)


Body (form-data):







file inception.zip


Response:
{
"id": "<id>",
"uploadDate": "16 Mar 2018 08:36:36 UTC",
"modelStatus": "INACTIVE",
"fileName": "inception.zip",
"metaData": null,
"trainingInfo": null,
"version": "5",
"checkSum": null,
"namespace": "<namespace>",
"modelName": "sap_community_example"
}

 

Deploy your model


Next we deploy the model.





















HTTP Method POST
URL <MODEL_REPO_URL>
Path api/v1/deployments
HEADER Authorization (OAuth2 Access Token)


Body (JSON):
{"modelName": "sap_community_example"}

 

Check the deployment


Afterwards (after some minutes) we can check the deployment and get the required information.





















HTTP Method GET
URL <MODEL_REPO_URL>
Path api/v1/deployments
HEADER Authorization (OAuth2 Access Token)


Body (JSON):
{
"id": "da776432-e468-4ce0-822d-d21dcc0ab559",
"namespace": "8dd19b31-7dc5-4620-be78-8d5ebbfa5d61",
"modelName": "sap_community_example",
"modelVersion": "2",
"placeholderName": "sap_community_example",
"resourcePlan": "model-container-cpu-tfs",
"deploymentStatus": {
"state": "SUCCEEDED",
"description": "Service [tfs-c74e4047-ef93-4b93-9b0e-2aa5a923d23e] is ready."
},
"modelContainer": {
"host": "<host>.eu-central-1.aws.ml.hana.ondemand.com",
"port": "80"
}
}
],
"caCrt": "<certificate>",
"last": true,
"totalElements": 3,
"totalPages": 1,
"sort": null,
"first": true,
"numberOfElements": 3,
"size": 10,
"number": 0
}

We need now from the response the following data:

  • host

  • port

  • caCRT




Create the application and execute the API


A complete guide how to create the application is already documented in the SAP help.

Additional u can find it in my git repository

After we´ve build our app wen can run this by entering:

 
> docker run -p 5000:5000 sap_ml
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)

 To verify if the API works, we can now execute create an new Postman request:

 













HTTP Method POST
URL http://localhost:5000

 


Body (form-data):







file <e.g. a image from a cat or dog>




 


Response:



 

It looks like it works.....

Let´s provide now a "real" API endpoint on SCP Cloud Foundry.

This API can the e.g. used from other applications.


Push you application to SAP CP Cloud Foundry


First of all we need to creat the follwing structure (git link😞



In difference to the local api before we have now a new file called:

 

Procfile:
web: python app.py 

And the deployment descriptor where we need to define the application details:

manifest.yml:
applications:
- name: <you appname>
host: <your app host>
memory: 512M
timeout: 30
buildpack: python_buildpack
env:
MODEL_NAME: <model name>
MODEL_SERVER_HOST: <deployed model host>
MODEL_SERVER_PORT: 80
ROOT_CERT: '<caCert>'

Afterwards we can now push this app to cf:
> cf push -f manifest.yml


looks fine after a minute or two:



And if we now recheck this app on the SCP CF cockpit, we see already a successfully started application:



 

The las step today is now to execute this API and we should get hopefully the same result:



 

Perfect.....it works ;o)

 

Conclusion


 

I think and hope u can see, the SAP Leonard ML Foundation BYOM functionality can be really easy.

For me ist was sometimes hard, because the docu was in the beginning not perfect.

In the meantime this has been improved (step by step) and hopefully this process should be continue to provide a central point of information for this kind of new fancy stuff ;o)

Comments and questions are welcome.

 

cheers,

fabian

 

 

 
21 Comments
Labels in this area