Artificial Intelligence and Machine Learning Blogs
Explore AI and ML blogs. Discover use cases, advancements, and the transformative potential of AI for businesses. Stay informed of trends and applications.
Showing results for 
Search instead for 
Did you mean: 
Hello Everyone ,

In this blog we are going to learn how to leverage capabilities of machine learning foundation offered by SAP . In the below use case we will show step by step approach of uploading data to cloud foundry by cloud foundry CLI and testing via postman.

What is SAP Leonardo Platform ?

SAP Leonardo Machine Learning foundation provides a platform for machine learning models, applications and services.

Background :

There is a large amount of enterprise data within SAP systems. Currently, there are many solutions focused on providing analytical results based on this data. With SAP Leonardo Machine Learning foundation, you can smartly utilize this enterprise data as training data for the implementation of Machine Learning services, in order to enable business applications to be intelligent in their purpose. This means they learn from historical data of manual tasks in order to automate them.

The Machine Learning technology can be quickly incorporated into existing SAP or non-SAP solutions using the Machine Learning services provided by SAP Leonardo Machine Learning. SAP Leonardo Machine Learning foundation provides the core components that are the basic building blocks required to create new Machine Learning services

Retraining Image Classifier Model

SAP Leonardo has 2 API’s related to Image: Image classification and Image feature extraction. In the following use case we have retrained the Image classification API. Retraining any API involves mainly 5 processes:

  1. Creation of your Service Instance

  2. Uploading the data to file system

  3. Retrain the model using the uploaded data.

  4. Deploy the Retrained model to your service instance.

  5. Testing from postman


Prerequisites :


Global Account with Machine Learning Services enabled .

Log on to SAP Cloud Platform and navigate to the following cloud foundry environment.

Click on your global account .

Click on the Sub account/Organization

Here you can see some your Cloud Foundry details like the name of your Organization, the number of Spaces and the API endpoint. Click on the number of Spaces

Click on the space tile , In our case it is training .

Once you are inside the space, you will find service marketplace on your left under services  .

Here we need to enable ml-foundation for the global account .

Data Preparation :

  • The data set will be a folder which consists of 3 folders inside: test, training, validation.

  • The whole dataset should be divided into the proportion 80-10-10 among training, test and validation folders respectively.

  • All the categories among which you want to divide your dataset should be there in all 3 folders. For eg: if flowers are to be categorized among 4 categories, lily, roses, orchids and carnations then test, training and validation folders should have all 4 folders inside it.


For pushing the data into the cloud foundry we need to have following .

SAPML CF CLI plugin must be installed on your local desktop.

CLI plugin is an extension of standard CF plugin. We have added a subcommand called sapml to easily interact with our ML Foundation APIs. Download the plugin file related to your platform from the below links and save it in a proper location on your machine.


Uploading  the data into the Cloud Foundry:


Step 1: Open command prompt.

Step 2 : Login into Cloud foundry CLI by using command cf login  and enter your ID and System Credentials . Once you are logged in successfully , It will ask you to select organisation in case if you have multiple org inside your global account.


Step 3 : Run the following command

This command will get available API’s .

Step 4 :  Once we get available configurations in your global account , Now we have to set the correct values for your SAPML configuration.

Example  :  For retraining the image classifier model we need auth_server , job api , retraining api .These details are can be retrieved from “cf sapml config get “ command or from service key tab from cloud foundry as shown above.

Run the following the commands in order to set the respective API for retraining the model

Step 5 : Initialize the cloud filesystem with the command by running following command .

 cf sapml fs init


Step 6 : Uploading the data to the cloud foundry by running the following command .

In our case it was Upload_dataset folder which has 3 sub folders(training ,testing ,validation) inside it , So we navigate to the location where Upload_dataset is available and run the below command by giving new folder name .

Note: folder is created in the cloud foundry with name which is suggested by you in the place of <NewFolderName>.

cf sapml fs put Upload_Dataset <NewFoldername>


Step 7: List the root directory with the command.

Cf sapml fs list will show all the available list of file systems in the respective cloud foundry account .



Step 8 : Display the subfolders of the already available "<new Folder>" training data in the cloud foundry .

cf sapml fs list <newfolder>/

Deploy the Retrained model to your service instance

Step 9 :  Now  prepare a configuration file for retraining. Open your favourite text editor and create a new file name dataset.json

Let me give you a bit of explanation about the content of this file. Mode "image" means, that we retrain the pre-trained Image Classification service. There are other retrainable services in the future, where this mode value needs to be set accordingly. You need to specify the data set name and a model name. As our folder structure has the root name "Brands", we choose the value "Brands" for our dataset. Give it a new model name of your choice and save it (e.g. brands-xx). You can add optional retrain parameters (e.g. learning rate). Once finished editing, remember to save the file.


Step 10: Start the retrain process using the SAPML CLI command

Command for submitting job :  cf sapml retraining job_submit -m image  <json folder location>

Example : In our case , we pointed to json location and executed the command as shown below


cf sapml retraining job_submit -m image C:\Users\test\Documents\Learnings\TrendingTechnologies\ML\dataset.json


C:\Users\test\Documents\Learnings\TrendingTechnologies\ML>cf sapml retraining job_submit -m image C:\test\I310562\Documents\Learnings\TrendingTechnologies\ML\dataset.json

After command is executed, Job success message comes with id .

Job submitted successfully with id "innventpoc-2018-09-01t1055z046763".


Step 11 : Checking retraining service :


Step 12: Checking the Job Status by executing the following command.

cf sapml retraining job -m image

Try executing the same command till you get success message .


Step 13 : Checking FS list to check job id


Step 14 : Downloading the retraining log.

Execute the following command to get retraining log on to your local machine .

Step 15 : Checking downloaded retraining log

Downloaded successfully


Step 16 :Now  deploy the retraining model by specifying the model name

Step 17 : Checking the deployment status

C:\Users\test\Documents\Learnings\TrendingTechnologies\ML>cf sapml retraining model_deployments -m image

ID                                       MODEL NAME  MODEL VERSION  HOST                                                                                             PORT  STATUS     DESCRIPTION

ms-286125d9-8692-448b-a155-6bd22471471c  Innvent     1      443   SUCCEEDED  Model is deployed and ready to serve


Step 18  : Enter the command cf service-key <instance name> <service key> to display your service key and make sure that everything is available.

Copy the

"clientid": "sb-3be33a65-7afa-43a9-9275-2728c40de5cd!b3191|ml-foundation-xsuaa-std!b313",

"clientsecret": "pi+B18+xEQJnLQYPe20BVTz/7a8=",


Copying the rest of the part


"appname": "3be33a65-7afa-43a9-9275-2728c40de5cd!b3191|ml-foundation-xsuaa-std!b313",

"clientid": "sb-3be33a65-7afa-43a9-9275-2728c40de5cd!b3191|ml-foundation-xsuaa-std!b313",

"clientsecret": "pi+B18+xEQJnLQYPe20BVTz/7a8=",

"identityzone": "i310562",

"identityzoneid": "b8514e90-92ca-4a69-94fc-8afe29bf4400",

"serviceurls": {
















"url": ""



You should have following parameters for testing your model

Authentication URL  :

Client ID :

Client Secret

Classification URL :


Step 19 :

Generating Token & Testing from postman


We can either use below link or it is also possible via postman



Step 20 : Generating token through post man

Setup environment


Header data comes automatically

Authorization - > Select basic authorization

Give Client id , ClientSecret ( As shown in above steps)

Username - Clientid

Password -Client Secret key



Following Token is generated as shown below.




Step 21 : Testing the api through post man


Once we have token generated , now next step is to test the image classification API by posting image through postman. In the header add authorization column and give bearer followed by the token . Also add the content type is equal to application/json as shown below .


Classification api url :


output :

Hope this helps in leveraging the capabilities of SAP Leonardo Machine Learning Foundation.