A machine learning architecture that enables the simple deployment of containerized pre-trained models. Easily plug in a trained model to the predefined architecture, deploy to Kyma runtime and create a flexible prediction endpoint to solve business-critical problems.
- SAP BTP account
- SAP Kyma environment is enabled
- Docker environment and a Docker Hub account is required.
- Install Docker on Mac link
- Install Docker on Windows link
- Create Docker Hub account (dockerID) at link
-
Commands are run in Mac terminal, but if you are using Windows please execute in your Windows Terminal.
-
Verify cURL is working in Mac terminal. Usually it is pre-installed in Mac OS. Type curl -V in Mac terminal and you should be able to see its help information. If it’s not installed, refer to online information, or follow these steps:
In Mac terminal, run: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
Enter your Mac's user password (if required during installation) then wait for the installation to finish.
Run the following command in the terminal: brew install curl
Curl should also be preinstalled on Windows but if not refer to the official documentation for installation instructions.
- Download the source code and unzip it locally.
- This example is a python flask application providing prediction service using a linear regression model. It runs on port 8888 and serves a post request to the service. We will discuss more details later, but for now, let's create a folder called kyma_ml_example and put all the source files inside.
-
Open Mac terminal and make sure you are in the kyma_ml_example directory (since we will run all the commands from there).
-
Make sure Docker is installed and Docker Desktop is running. You should be able to see the Docker version with the following command:
docker -v
-
Build a Docker image with this command:
docker build -t kyma-ml-example .
- Please notice there is a dot at the end of the command.
-
Run command
docker images
to make sure the image is already in the repository. -
Run command
docker login
to login to Docker Hub using your Docker Hub account (dockerID and password). -
Tag your image with your dockerID :
docker tag kyma-ml-example [your dockerId]/kyma-ml-example
-
And then push to your own public image repository:
docker push [your dockerId]/kyma-ml-example
You can go to hub.docker.com, log in and check if your image is already uploaded.
- Now we are going to run our machine learning service on SAP Kyma where you can easily monitor the health of your service, benefit from auto-scaling, load balancing, and more.
- Please make sure you have a BTP account and get Kyma enabled as mentioned in the prerequisites.
- Open SAP BTP Cockpit (link) and open your subaccount page. Find Kyma console URL under Kyma Environment tab.
-
Click "link to dashboard" to open Kyma dashboard and then add dev namespace.
-
Open deployment.yaml file with a text editor and replace ‘your-dockerID’ with your real dockerID(docker hub account) at line 31. Save the file.
-
Enter your dev space and choose Deploy new workload->Upload YAML->Browse your deployment.yaml file. Then click Deploy.
-
Go back to your dev space, you should be able to see two running pods after deployment.
-
On Kyma dashboard, go to Discover and Network->API Rules.
- We will create an API rule since we want to expose a restful API to accept POST requests. For our case, we can just simply set value ‘kymamlexample’ for fields Name and Hostname. Then click create.
- Note down the full url (which will look like the following 'kymamlexample.d4d833f.kyma.shoot.live.k8s-hana.ondemand.com'.
- Now open your API url in browser.
-
We will test our prediction service using the machine learning model in our source code.
-
We will send a post request with some json data to our API using a curl command. The command looks like this:
curl -H "Content-Type: application/json" -X POST -d ‘your_json_data’ API_URL/predict
- You can copy the content from file ‘sample_data.json’ in our source folder and replace your_json_data in the command. You will also need to replace API_URL with the one we created earlier.
If everything is OK, you should be able to see the predicted result after the predictions attribute.
Create an issue in this repository if you find a bug or have questions about the content.
For additional support, ask a question in SAP Community.
If you wish to contribute code, offer fixes or improvements, please send a pull request. Due to legal reasons, contributors will be asked to accept a DCO when they create the first pull request to this project. This happens in an automated fashion during the submission process. SAP uses the standard DCO text of the Linux Foundation.
Copyright (c) 2022 SAP SE or an SAP affiliate company. All rights reserved. This project is licensed under the Apache Software License, version 2.0 except as noted otherwise in the LICENSE file.