Skip to main content

Model API: model wrappers and pipelines for inference with OpenVINO

Project description

Python* Model API package

Model API package is a set of wrapper classes for particular tasks and model architectures, simplifying data preprocess and postprocess as well as routine procedures (model loading, asynchronous execution, etc...) An application feeds model class with input data, then the model returns postprocessed output data in user-friendly format.

Package structure

The Model API consists of 3 libraries:

  • adapters implements a common interface to allow Model API wrappers usage with different executors. See Model API adapters section
  • models implements wrappers for Open Model Zoo models. See Model API Wrappers section
  • pipelines implements pipelines for model inference and manage the synchronous/asynchronous execution. See Model API Pipelines section

Prerequisites

The package requires

  • one of OpenVINO supported Python version (see OpenVINO documentation for the details)
  • OpenVINO™ toolkit

If you build Model API package from source, you should install the OpenVINO™ toolkit. See the options:

Use installation package for Intel® Distribution of OpenVINO™ toolkit or build the open-source version available in the OpenVINO GitHub repository using the build instructions.

Also, you can install the OpenVINO Python* package via the command:

pip install openvino

Installing Python* Model API package

Use the following command to install Model API from source:

pip install <omz_dir>/demos/common/python

Alternatively, you can generate the package using a wheel. Follow the steps below:

  1. Build the wheel.
python <omz_dir>/demos/common/python/setup.py bdist_wheel

The wheel should appear in the dist folder. Name example: openmodelzoo_modelapi-0.0.0-py3-none-any.whl

  1. Install the package in the clean environment with --force-reinstall key.
pip install openmodelzoo_modelapi-0.0.0-py3-none-any.whl --force-reinstall

To verify the package is installed, you might use the following command:

python -c "from openvino.model_zoo import model_api"

Model API Wrappers

The Model API package provides model wrappers, which implement standardized preprocessing/postprocessing functions per "task type" and incapsulate model-specific logic for usage of different models in a unified manner inside the application.

The following tasks can be solved with wrappers usage:

Task type Model API wrappers
Background Matting
  • VideoBackgroundMatting
  • ImageMattingWithBackground
  • PortraitBackgroundMatting
Classification
  • ClassificationModel
Deblurring
  • Deblurring
Human Pose Estimation
  • HpeAssociativeEmbedding
  • OpenPose
Instance Segmentation
  • MaskRCNNModel
  • YolactModel
Monocular Depth Estimation
  • MonoDepthModel
Named Entity Recognition
  • BertNamedEntityRecognition
Object Detection
  • CenterNet
  • DETR
  • CTPN
  • FaceBoxes
  • NanoDet
  • NanoDetPlus
  • RetinaFace
  • RetinaFacePyTorch
  • SSD
  • UltraLightweightFaceDetection
  • YOLO
  • YoloV3ONNX
  • YoloV4
  • YOLOF
  • YOLOX
Question Answering
  • BertQuestionAnswering
Salient Object Detection
  • SalientObjectDetectionModel
Semantic Segmentation
  • SegmentationModel
Action Classification
  • ActionClassificationModel

Model API Adapters

Model API wrappers are executor-agnostic, meaning it does not implement the specific model inference or model loading, instead it can be used with different executors having the implementation of common interface methods in adapter class respectively.

Currently, OpenvinoAdapter and OVMSAdapter are supported.

OpenVINO Adapter

OpenvinoAdapter hides the OpenVINO™ toolkit API, which allows Model API wrappers launching with models represented in Intermediate Representation (IR) format. It accepts a path to either xml model file or onnx model file.

OpenVINO Model Server Adapter

OVMSAdapter hides the OpenVINO Model Server python client API, which allows Model API wrappers launching with models served by OVMS.

Refer to OVMSAdapter to learn about running demos with OVMS.

For using OpenVINO Model Server Adapter you need to install the package with extra module:

pip install <omz_dir>/demos/common/python[ovms]

ONNXRuntime Adapter

ONNXRuntimeAdapter hides the ONNXRuntime, which Model API wrappers launching with models represented in ONNX format. It accepts a path to onnx file. This adapter's functionality is limited: it doesn't support model reshaping, asynchronous inference and was tested only on limited scope of models. Supported model wrappers: SSD, MaskRCNNModel, SegmentationModel, and ClassificationModel.

To use this adapter, install extra dependencies:

pip install onnx onnxruntime

Model API Pipelines

Model API Pipelines represent the high-level wrappers upon the input data and accessing model results management. They perform the data submission for model inference, verification of inference status, whether the result is ready or not, and results accessing.

The AsyncPipeline is available, which handles the asynchronous execution of a single model.

Ready-to-use Model API solutions

To apply Model API wrappers in custom applications, learn the provided example of common scenario of how to use Model API.

In the example, the SSD architecture is used to predict bounding boxes on input image "sample.png". The model execution is produced by OpenvinoAdapter, therefore we submit the path to the model's xml file.

Once the SSD model wrapper instance is created, we get the predictions by the model in one line: ssd_model(input_data) - the wrapper performs the preprocess method, synchronous inference on OpenVINO™ toolkit side and postprocess method.

import cv2
# import model wrapper class
from model_api.models import SSD
# import inference adapter and helper for runtime setup
from model_api.adapters import OpenvinoAdapter, create_core


# read input image using opencv
input_data = cv2.imread("sample.png")

# define the path to mobilenet-ssd model in IR format
model_path = "public/mobilenet-ssd/FP32/mobilenet-ssd.xml"

# create adapter for OpenVINO™ runtime, pass the model path
inference_adapter = OpenvinoAdapter(create_core(), model_path, device="CPU")

# create model API wrapper for SSD architecture
# preload=True loads the model on CPU inside the adapter
ssd_model = SSD(inference_adapter, preload=True)

# apply input preprocessing, sync inference, model output postprocessing
results = ssd_model(input_data)

To study the complex scenarios, refer to Open Model Zoo Python* demos, where the asynchronous inference is applied.

Project details


Download files

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

Source Distribution

openvino_model_api-0.2.5.tar.gz (97.8 kB view details)

Uploaded Source

Built Distribution

openvino_model_api-0.2.5-py3-none-any.whl (132.2 kB view details)

Uploaded Python 3

File details

Details for the file openvino_model_api-0.2.5.tar.gz.

File metadata

  • Download URL: openvino_model_api-0.2.5.tar.gz
  • Upload date:
  • Size: 97.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for openvino_model_api-0.2.5.tar.gz
Algorithm Hash digest
SHA256 26a12d73d83f1b23c9640e4ccf2d2ccfdc866a3b2dce612e0c99a81bff2d06a7
MD5 97e4cfc1409d5cc42d1ac1d4e1182dbc
BLAKE2b-256 77332825699fcce3197b9d3136612a58f65503faa90955c9ac5e41992422b50f

See more details on using hashes here.

File details

Details for the file openvino_model_api-0.2.5-py3-none-any.whl.

File metadata

File hashes

Hashes for openvino_model_api-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 758f51059aecdc26ba8b903079f2fcafa208441bbebd8b82483eb045dc04dd6f
MD5 4507aafc3e03105da5ba08286cedf63d
BLAKE2b-256 0fe07217125a4c0dac00bc8a33b433fa6cdbe3d7bf1b0c8b56766d05d86fda52

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page