Model API: model wrappers and pipelines for inference with OpenVINO
Project description
OpenVINO Model API
Introduction
Model API 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.). It is aimed at simplifying end-to-end model inference for different deployment scenarios, including local execution and serving. The Model API is based on the OpenVINO inference API.
How it works
Model API searches for additional information required for model inference, data, pre/postprocessing, label names, etc. directly in OpenVINO Intermediate Representation. This information is used to prepare the inference data, process and output the inference results in a human-readable format.
Currently, ModelAPI supports models trained in OpenVINO Training Extensions framework. Training Extensions embed all the metadata required for inference into model file. For models coming from other than Training Extensions frameworks metadata generation step is required before using ModelAPI.
Supported model formats
Features
- Python API
- Synchronous and asynchronous inference
- Local inference and serving through the REST API
- Model preprocessing embedding for faster inference
Installation
pip install openvino-model-api
Usage
from model_api.models import Model
# Create a model wrapper from a compatible model generated by OpenVINO Training Extensions
# To work with an OVMS-served model, pass its endpoint instead of a file path, e.g. "localhost:8000/v2/models/ssdlite_mobilenet_v2"
model = Model.create_model("model.xml")
# Run synchronous inference locally
result = model(image) # image is numpy.ndarray
# Print results in model-specific format
print(f"Inference result: {result}")
Prepare a model for InferenceAdapter
There are usecases when it is not possible to modify an internal ov::Model and it is hidden behind InferenceAdapter. For example the model can be served using OVMS. create_model() can construct a model from a given InferenceAdapter. That approach assumes that the model in InferenceAdapter was already configured by create_model() called with a string (a path or a model name). It is possible to prepare such model:
model = DetectionModel.create_model("~/.cache/omz/public/ssdlite_mobilenet_v2/FP16/ssdlite_mobilenet_v2.xml")
model.save("serialized.xml")
Usage with generic OpenVINO models
ModelAPI uses custom field in rt_info/model_info section of OpenVINO IR to store metadata required for preprocessing and postprocessing. If you have a generic OpenVINO model without such metadata, you can provide that metadata in configuration argument of create_model() method:
from model_api.models import Model
# Create a model wrapper from a compatible model generated by OpenVINO Training Extensions
model = Model.create_model(
"model.xml",
configuration={
"model_type": "Segmentation",
"blur_strength": 1,
"labels": ["object"],
"soft_threshold": 0.5,
}
)
# Run synchronous inference locally
result = model(image) # image is numpy.ndarray
# Print results in model-specific format
print(f"Inference result: {result}")
# Save the model with metadata already embedded (passing configuration is not required anymore)
model.save("serialized_with_metadata.xml")
For more details please refer to the examples of this project.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openvino_model_api-0.4.2.tar.gz.
File metadata
- Download URL: openvino_model_api-0.4.2.tar.gz
- Upload date:
- Size: 524.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7fbed2c72fe2280a9c8d325f8b61a3f66f748fa1db3910366597aacaa6306a4
|
|
| MD5 |
ecf6c7ad29ac949acac11b682ff5db4c
|
|
| BLAKE2b-256 |
396ff9b5c544663795936414577ebf069e3c4537390aff5aa7f4cca63f227b0c
|
Provenance
The following attestation bundles were made for openvino_model_api-0.4.2.tar.gz:
Publisher:
publish.yaml on open-edge-platform/model_api
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openvino_model_api-0.4.2.tar.gz -
Subject digest:
f7fbed2c72fe2280a9c8d325f8b61a3f66f748fa1db3910366597aacaa6306a4 - Sigstore transparency entry: 1449512869
- Sigstore integration time:
-
Permalink:
open-edge-platform/model_api@a272f60a00f235da31c671ef208dec4f8756dce1 -
Branch / Tag:
refs/tags/0.4.2 - Owner: https://github.com/open-edge-platform
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@a272f60a00f235da31c671ef208dec4f8756dce1 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file openvino_model_api-0.4.2-py3-none-any.whl.
File metadata
- Download URL: openvino_model_api-0.4.2-py3-none-any.whl
- Upload date:
- Size: 139.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28d5c959cbb05f3c9f2e54a4fbe600e1609268e55ca37efd277a386ecf3fa0bf
|
|
| MD5 |
cc2e9e01a0998bfe2108c7acec13392c
|
|
| BLAKE2b-256 |
b99b8a958503efe154bc676eec32b7d2cc7fe8253271512427a0bc4c86190d76
|
Provenance
The following attestation bundles were made for openvino_model_api-0.4.2-py3-none-any.whl:
Publisher:
publish.yaml on open-edge-platform/model_api
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openvino_model_api-0.4.2-py3-none-any.whl -
Subject digest:
28d5c959cbb05f3c9f2e54a4fbe600e1609268e55ca37efd277a386ecf3fa0bf - Sigstore transparency entry: 1449512871
- Sigstore integration time:
-
Permalink:
open-edge-platform/model_api@a272f60a00f235da31c671ef208dec4f8756dce1 -
Branch / Tag:
refs/tags/0.4.2 - Owner: https://github.com/open-edge-platform
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@a272f60a00f235da31c671ef208dec4f8756dce1 -
Trigger Event:
workflow_dispatch
-
Statement type: