Skip to content

Commit 55d2c0a

Browse files
committed
Revert "chore!: remove OVMSAdapter (#425)"
This reverts commit 6b54085.
1 parent 4ef786b commit 55d2c0a

17 files changed

Lines changed: 2047 additions & 544 deletions

File tree

.github/workflows/pre_commit.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,4 @@ jobs:
121121
- name: Some tests failed
122122
if: ${{ contains(needs.*.result, 'failure') }}
123123
run: exit 1
124+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,4 @@ docs/source/_build/
145145
.vscode/
146146

147147
data/
148+
ovms_models/

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
## Introduction
1313

14-
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. The Model API is based on the OpenVINO inference API.
14+
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.
1515

1616
## How it works
1717

@@ -29,6 +29,7 @@ Training Extensions embed all the metadata required for inference into model fil
2929

3030
- Python API
3131
- Synchronous and asynchronous inference
32+
- Local inference and serving through the rest API
3233
- Model preprocessing embedding for faster inference
3334

3435
## Installation
@@ -41,6 +42,7 @@ Training Extensions embed all the metadata required for inference into model fil
4142
from model_api.models import Model
4243

4344
# Create a model wrapper from a compatible model generated by OpenVINO Training Extensions
45+
# Use URL to work with OVMS-served model, e.g. "localhost:9000/models/ssdlite_mobilenet_v2"
4446
model = Model.create_model("model.xml")
4547

4648
# Run synchronous inference locally
@@ -52,7 +54,7 @@ print(f"Inference result: {result}")
5254

5355
## Prepare a model for `InferenceAdapter`
5456

55-
There are usecases when it is not possible to modify an internal `ov::Model` and it is hidden behind `InferenceAdapter`. `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:
57+
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](https://github.com/openvinotoolkit/model_server). `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:
5658

5759
```python
5860
model = DetectionModel.create_model("~/.cache/omz/public/ssdlite_mobilenet_v2/FP16/ssdlite_mobilenet_v2.xml")

docs/source/adapters/index.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
[todo]
1212
:::
1313

14+
:::{grid-item-card} Ovms Adapter
15+
:link: ./ovms_adapter
16+
:link-type: doc
17+
1418
[todo]
1519
:::
1620
:::{grid-item-card} Onnx Adapter
@@ -41,5 +45,6 @@
4145
./inference_adapter
4246
./onnx_adapter
4347
./openvino_adapter
48+
./ovms_adapter
4449
./utils
4550
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Ovms Adapter
2+
3+
```{eval-rst}
4+
.. automodule:: model_api.adapters.ovms_adapter
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
8+
```

examples/serving_api/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Serving API example
2+
3+
This example demonstrates how to use a Python API of OpenVINO Model API for a remote inference of models hosted with [OpenVINO Model Server](https://docs.openvino.ai/latest/ovms_what_is_openvino_model_server.html). This tutorial assumes that you are familiar with Docker subsystem and includes the following steps:
4+
5+
- Run Docker image with
6+
- Instantiate a model
7+
- Run inference
8+
- Process results
9+
10+
## Prerequisites
11+
12+
- Install Model API from source. Please refer to the main [README](../../../README.md) for details.
13+
- Install Docker. Please refer to the [official documentation](https://docs.docker.com/get-docker/) for details.
14+
- Install OVMS client into the Python environment:
15+
16+
```bash
17+
pip install ovmsclient
18+
```
19+
20+
- Download a model by running a Python code with Model API, see Python [exaple](../../synchronous_api/README.md) and resave a configured model at OVMS friendly folder layout:
21+
22+
```python
23+
from model_api.models import DetectionModel
24+
25+
DetectionModel.create_model("ssd_mobilenet_v1_fpn_coco").save("/home/user/models/ssd_mobilenet_v1_fpn_coco/1/ssd_mobilenet_v1_fpn_coco.xml")
26+
```
27+
28+
- Run docker with OVMS server:
29+
30+
```bash
31+
docker run -d -v /home/user/models:/models -p 8000:8000 openvino/model_server:latest --model_path /models/ssd_mobilenet_v1_fpn_coco --model_name ssd_mobilenet_v1_fpn_coco --rest_port 8000 --nireq 4 --target_device CPU
32+
```
33+
34+
## Run example
35+
36+
To run the example, please execute the following command:
37+
38+
```bash
39+
python run.py <path_to_image>
40+
```

examples/serving_api/run.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright (C) 2020-2024 Intel Corporation
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
import sys
8+
9+
import cv2
10+
11+
from model_api.models import DetectionModel
12+
13+
14+
def main():
15+
if len(sys.argv) != 2:
16+
usage_message = f"Usage: {sys.argv[0]} <path_to_image>"
17+
raise RuntimeError(usage_message)
18+
19+
image = cv2.cvtColor(cv2.imread(sys.argv[1]), cv2.COLOR_BGR2RGB)
20+
if image is None:
21+
error_message = f"Failed to read the image: {sys.argv[1]}"
22+
raise RuntimeError(error_message)
23+
24+
# Create Object Detection model specifying the OVMS server URL
25+
model = DetectionModel.create_model(
26+
"localhost:8000/v2/models/ssd_mobilenet_v1_fpn_coco",
27+
model_type="ssd",
28+
)
29+
detections = model(image)
30+
print(f"Detection results: {detections}")
31+
32+
33+
if __name__ == "__main__":
34+
main()

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ dependencies = [
3131
]
3232

3333
[project.optional-dependencies]
34+
ovms = [
35+
"tritonclient[http]<2.59",
36+
]
3437
tests = [
3538
"httpx",
3639
"pytest",

src/README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,25 @@ The following tasks can be solved with wrappers usage:
7979

8080
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.
8181

82-
Currently, `OpenvinoAdapter` and `ONNXRuntimeAdapter` are supported.
82+
Currently, `OpenvinoAdapter` and `OVMSAdapter` are supported.
8383

8484
### OpenVINO Adapter
8585

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

89+
### OpenVINO Model Server Adapter
90+
91+
`OVMSAdapter` hides the OpenVINO Model Server python client API, which allows Model API wrappers launching with models served by OVMS.
92+
93+
Refer to **[`OVMSAdapter`](adapters/ovms_adapter.md)** to learn about running demos with OVMS.
94+
95+
For using OpenVINO Model Server Adapter you need to install the package with extra module:
96+
97+
```sh
98+
pip install <omz_dir>/demos/common/python[ovms]
99+
```
100+
89101
### ONNXRuntime Adapter
90102

91103
`ONNXRuntimeAdapter` hides the ONNXRuntime, which Model API wrappers launching with models represented in ONNX format.

src/model_api/adapters/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55

66
from .onnx_adapter import ONNXRuntimeAdapter
77
from .openvino_adapter import OpenvinoAdapter, create_core, get_user_config
8+
from .ovms_adapter import OVMSAdapter
89
from .utils import INTERPOLATION_TYPES, RESIZE_TYPES, InputTransform, Layout
910

1011
__all__ = [
1112
"create_core",
1213
"get_user_config",
1314
"Layout",
1415
"OpenvinoAdapter",
16+
"OVMSAdapter",
1517
"ONNXRuntimeAdapter",
1618
"RESIZE_TYPES",
1719
"InputTransform",

0 commit comments

Comments
 (0)