Part 2: Deliver real-life use cases with SAP BTP – Returnable Packaging – SAP AI Core
2023-12-9 05:21:26 Author: blogs.sap.com(查看原文) 阅读量:9 收藏

This blog post is the 2nd part of the Deliver real-life use cases with SAP BTP – Returnable Packaging technical enablement session: 

Check the full set of our Deliver real-life use cases with SAP BTP series calendar here to watch the recordings of past sessions and register for the upcoming ones! 

The heart of our scenario is a smart returnable packaging station, where consumers can drop their empty plastic bottles, to give them a second life. Such a station takes a picture of each returned bottle, to identify the specific bottle type, among a set of predefined categories, so that the consumer can have a refund for the correct value of the bottle. Let’s imagine for instance four categories of bottles, with different volumes, from 250 ml to 1 l. We want the machine to be able to recognize them and associate them to the corresponding material ID registered in the backend system. 

In our prototype, we used SAP AI Core to develop a Machine Learning model to perform this bottle classification.

Computer vision and SAP AI Core

The task of associating images to a certain category, in a list of possible predefined choices, is called image classification, and it is one of the most common applications of computer vision. This technology, enabling computers to make sense of images, flourished in the last decade thanks to development of convolutional neural networks (CNNs), a class of deep learning algorithms that work extremely well in extracting visual features.

CNNs are computationally expensive algorithms, often requiring GPUs and large input datasets for training. Training such models from scratch can be extremely difficult and time consuming. However, various opensource frameworks, such as Tensorflow, Pytorch and others, provide a large set of prebuilt architectures to perform tasks such as image classification, object detection, image segmentation and many others. These models are often pre-trained on large open image datasets, containing millions of images and classes.

A machine learning expert setting off to build a computer vision model for a precise task, think of our bottle classification example, would typically leverage one of such pre-trained opensource models to get started. He would navigate some of the various existing model (you can have a look at Kaggle Models or Pytorch Hub to get a feeling on the variety of content available) and select an appropriate model for image classification. Pretrained models do not match exactly the specific task that the ML expert has in mind. Usually, they can recognise generic classes of objects, such as persons, vehicles, animals, or even bottles, but they are not able to distinguish our four types of bottles from one another. The machine learning expert then needs to get this pre-trained model and train it on his own dataset of bottles to be able to achieve the bottle classification task with satisfying accuracy. Although much easier than starting from scratch, this training still requires some effort: a dataset of images needs to be prepared, the code to train the model needs to be written, and the training phase requires multiple attempts to achieve the desired model performance.

SAP AI Core is the BTP product that allows developing state of the art machine learning models in a code agnostic, scalable way, including Computer Vision models. It can access any kind of input data, including images, it provides adequate computing resources, including GPUs if needed, and it gives users the freedom of writing the code in the preferred machine learning framework, therefore giving the possibility to users to leverage pre-trained models. Additionally, the SAP Computer Vision package can be used to speed-up the machine learning cycle even further, creating ready-to-use code for various computer vision tasks, including image classification.  Let’s see in more detail how it can be used to create our bottle classification model.

Steps for an image classification model with the SAP Computer Vision Library

Prepare the dataset

We need to prepare a dataset of images containing a set of pictures for each bottle category, taken in the same conditions as the camera installed in the smart returnable packaging station would do. The number of images that are required to achieve good performance varies case by case, but a few hundreds images for each class are usually ok to start. The dataset must be uploaded in a cloud storage bucket, for instance in our example we have used Amazon S3. SAP AI Core will retrieve the images from there.

Prepare the training code

Once the dataset is ready, we need to prepare the code to train a CNN on our images. With SAP AI Core, there are two possible ways of doing it, either manually, or using the SAP AI Core Computer vision library.

In the first case, we need to decide which kind of CNN architecture we want to use, and which deep learning framework. Then we need to write the code to train our model, test it locally on few images to make sure it works. Then, to be able to run this code on SAP AI Core we would need to wrap it into a Docker image and write some Argo templates for the executions. It’s outside the scope of this blog to explain step-by-step how SAP AI Core works, but if you need to get started, you will find useful material at the end of the blog.

The alternative to this manual process is using the SAP AI Core computer vision library, which will prepare the Docker images and the Argo templates for you.

Here you can find a notebook that walks you through the process.

Launch the training execution in SAP AI Core

Once the docker image and the Argo Templates are ready, we can launch the execution on SAP AI Core and monitor its status and logs from the AI Core Launchpad.  We might need to launch various execution to tweak the model hyperparameters (number of training epochs, learning rate etc.) or the input dataset, to obtain the desired accuracy for the image classification task.

Create a deployment in SAP AI Core

After reaching a satisfying accuracy, we need to deploy the trained model in SAP AI Core to be able to classify new imaged of bottles as they are dropped by consumers in the smart returnable packaging station. Again, this requires us to write the code for model inferencing. Similarly to the training process, the SAP Computer Vision library can be used generate automatically the docker image and the templates for SAP AI Core, relieving the machine learning expert from the burden of writing the code manually. Once the model is deployed in SAP AI Core, we have access to an URL where we can post new bottle images and get back the predicted bottle class from the model.

In our prototype the deployment URL exposed by SAP AI Core is consumed in a Kyma serverless function. This piece of the architecture is covered in the next blog post of the series.

Other blogs for more details about this use case

Implementation details about each one of the components of our use case are explained in a separated blog, check them to learn more!

Part 1: Deliver real-life use cases with SAP BTP – Returnable Packaging
Part 2: Deliver real-life use cases with SAP BTP – Returnable Packaging – SAP AI Core – this blog
Part 3: Deliver real-life use cases with SAP BTP – Returnable Packaging – SAP Kyma
Part 4: Deliver real-life use cases with SAP BTP – Returnable Packaging – SAP Build Apps

More resources about SAP AI Core


文章来源: https://blogs.sap.com/2023/12/08/part-2-deliver-real-life-use-cases-with-sap-btp-returnable-packaging-sap-ai-core/
如有侵权请联系:admin#unsafe.sh