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.
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:
Creation of your Service Instance
Uploading the data to file system
Retrain the model using the uploaded data.
Deploy the Retrained model to your service instance.
Testing from postman
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.
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
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 .