Skip to main content

SAP Computer Vision Package

Project description

SAP Computer Vision Package

This package helps with the implementation of Computer Vision use-cases on top of AI Core. It extends detectron2, a state-of-the-art library for object detection and image segmentation. Our package adds image classification and feature extraction (eg., for image retrieval) capabilities. For a fast development of Computer Vision solutions, the package offers training and evaluation methods and other helpful components, such as a large set of augmentation functions. The package can also be used stand-alone without AI Core, and AI Core integration can be added later to the project.

The functionalities of the package can be used on AI Core without any programming. For this purpose the package offers a command line interface to create AI Core templates for training and serving. From our experience it reduces the time for implementing a Computer Vision use-case on AI Core from several days to several hours.

Supported use-cases

  • Object Detection
  • Image Classification
  • Image Feature Extraction
  • Model Training and Deployment on SAP AI Core

Installation

Prerequisites

Before installation, make sure that PyTorch and detectron2 are installed. Details on how to install PyTroch can be found here. After the installation of PyTorch the matching version of detectron2 has to be installed. Please check the detectron2 installation guide to select the proper version. The package is tested with detectron2=0.6.

Mac OS

On MacOS follwing commands can be used to install both:

pip install torch==1.10 torchvision
pip install https://github.com/facebookresearch/detectron2/archive/refs/tags/v0.6.zip

Linx

For linux pre-builds of detectron2 are available:

pip install torch==1.10 torchvision
pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cpu/torch1.10/index.html

Make sure to select the url matching your torch version and cuda when GPU support is needed. Details can be found in the detectron2 installation guide.

Installation from Source

When building from source normally setup_without_centaur.py is the suitable setup file. It skips the process of building the model serving binary locally, which only works on linux systems. The binary is only needed in the docker images to serve models.

To include local code changes to the installation run:

python setup_with_centaur.py develop

This is similar to pip install -e ., except that setup_without_centaur.py is used instead of setup.py.

Installation using pip

To install this package from pypi run:

pip install sap-computer-vision-package

Installation of metaflow with Argo Support

To use the CLI part of the package metaflow (with the argo plugin) and awscli are needed. To install the correct metaflow version run:

pip install 'git+https://github.com/sappier/metaflow' awscli

This works on MacOS and linux systems.

Getting Started

Using the Python Library Part

If you are interested to use our package as a simple extension to detectron2, we recommend running sap_cv examples <target_dir> to copy our example notebooks to <target_dir> and take a look at those.

Using the Package on AI Core

Before testing the pipelines on AI Core, make sure that the items in the following checklist are fulfilled.

Configure AWS credentials and metaflow

When templates are created metaflow pushes tarballs to the S3 bucket. Those tarballs are loaded during pipeline execution. For this to work metaflow needs writing permissions to the S3 bucket onboarded to AI Core and metaflow has to configured to use this bucket as its datastore.

Details on how to configure an aws profile can be found here. In order to enable metaflow to copy the tarballs into the bucket, the awscli must not ask for a password when starting a copy process. To achieve this either give the default profile the permissions to access the bucket or run export AWS_PROFILE=<profile-with-bucket-access> before creating templates.

Full documentation on how to configure metaflow can be found in the metaflow documentation. We only need to configure the S3 as the storage backend and do not need the configuration for AWS Batch. A mininmal configuration file (~/.metaflowconfig/config.json) looks like this:

{
    "METAFLOW_DATASTORE_SYSROOT_S3": "<path-in-bucket>",
    "METAFLOW_DATATOOLS_SYSROOT_S3": "<path-in-bucket>/data",
    "METAFLOW_DEFAULT_DATASTORE": "s3"
}

AI Core Checklist

Basic Usage

To show all available templates run sap_cv show. The command sap_cv show <pipeline_name> shows detailed information about a specific pipeline and its parameters.

The training pipelines are templates for AI Core execution. To run it under your tenant you need the template and the matching docker image:

  • To create a template execute sap_cv create-template <pipeline_name> -o/--output-file=<choose_name>.json. The template contains several tenant specific entries like imagePullSecrets etc. Please adjust them by hand or use a pipeline config YAML (see section below).
  • To create a docker image execute sap_cv build-docker <pipeline_name> -t <tag/docker-image-target> and push it using docker push <tag/docker-image-target>

The template has to be pushed into the onboarded git repo (consult AI Core documentation to set it up) and the container to the onboarded docker repository.

Templates are built using metaflow using a plugin to create Argo templates. Make sure that a proper metaflow version (for the argo plugin install this fork: https://github.com/sappier/metaflow) is installed and that the storage is configured correctly (check section "Configure AWS credentials and metaflow").

Pipeline Config .yaml

Tenant specific values for the template can either be provided through the CLI through additional options. For more information execute sap_cv create-template <pipeline_name> --argo-help. To simplify the command and make the creation of the template trackable in git it is possible to use a .yaml containing the values.

Example:

labels:
  scenarios.ai.sap.com/id: "<scenario-id>"
  ai.sap.com/version: "<version-number>"
annotations:
  scenarios.ai.sap.com/name: "<scenario-name>"
  executables.ai.sap.com/name: "<executable-name>"
image: <tag/docker-image-target>`
imagePullSecrets:
  - name: "<docker-repo-secret>"
envFrom:
  - secretRef:
      name: "<object-store-secret>"

To use the pipeline config during the creation process use the --pipeline-config options, e.g. sap_cv create-template <pipeline_name> -o/--output-file=<choose_name>.json --pipeline-config=pipeline_cfg.yaml.

Common Issues

Impossible to have multiple templates for the same pipeline in a tenant.

The name for executable specified in the template has to be unique. To overwrite the default name of a pipeline use the --name option when creating the template: sap_cv create-template <pipeline_name> -o/--output-file=<choose_name>.json --name=<executable-name>.

Template creations gets stucked without an error.

When the template creation process gets stuck in this step:

$ sap_cv create-template batch_processing -o test.json
Metaflow 2.4.4 executing BatchProcessing for user:I545048
Validating your flow...
    The graph looks good!
Running pylint...
    Pylint is happy!
Deploying batchprocessing to Argo Workflow Templates...

it is most that the permissions to write to the bucket are missing. Make sure to select the correct AWS profile by running export AWS_PROFILE=<profile-with-bucket-access>. More details can be found in the section "Configure AWS credentials and metaflow".

Giving Feedback and Reporting Bugs

If you are an SAP customer you can give feedback or report bugs by creating an incident via the SAP ONE Support Launchpad using the component ID "CA-ML-CV".

If you are not an SAP customer yet, you can give feedback or report bugs by registering with SAP Community and asking a question using the tag "SAP AI Core" in the field "SAP Managed Tags".

License

This package is distributed under the SAP Developers License, see LICENSE file in the package. The package uses several third party open source components. Please see file DISCLAIMER for more details on their licensing.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Built Distribution

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page