-
Notifications
You must be signed in to change notification settings - Fork 20
feat: add OVMSAdapter #498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
9e47fc9
Add OVMSAdapter
tybulewicz 6bfd42a
Update src/model_api/adapters/ovms_adapter.py
tybulewicz 7eb4b9e
Update src/model_api/adapters/ovms_adapter.py
tybulewicz a9f6311
Update examples/serving_api/run.py
tybulewicz f3e019f
Update examples/serving_api/README.md
tybulewicz 47af05c
Update README.md
tybulewicz 1a3b083
Update examples/serving_api/README.md
tybulewicz e930631
Update README.md
tybulewicz 37d9b6d
Update src/model_api/models/model.py
tybulewicz 3d6a65f
Update docs/source/adapters/ovms_adapter.md
tybulewicz 1b5afd7
Update src/model_api/adapters/ovms_adapter.md
tybulewicz 8209a42
Update src/README.md
tybulewicz 83868d0
Expose only configured parameters
tybulewicz a857322
code style
tybulewicz 4a90e84
Update src/model_api/adapters/ovms_adapter.py
tybulewicz 20fe947
Remove gRPC mentions
tybulewicz 4a5cb23
Update README.md
tybulewicz 18102d1
Update tests/unit/adapters/test_ovms_adapter.py
tybulewicz 783696d
Reduce code duplication
tybulewicz 11cb10f
Remove gRPC mentions
tybulewicz 65dbdb7
fix whitespace
tybulewicz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -145,3 +145,4 @@ docs/source/_build/ | |
| .vscode/ | ||
|
|
||
| data/ | ||
| ovms_models/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # OVMS Adapter | ||
|
|
||
| ```{eval-rst} | ||
| .. automodule:: model_api.adapters.ovms_adapter | ||
| :members: | ||
| :undoc-members: | ||
| :show-inheritance: | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # Serving API example | ||
|
|
||
| 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: | ||
|
|
||
| - Run Docker image with | ||
| - Instantiate a model | ||
| - Run inference | ||
| - Process results | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Install Model API from source. Please refer to the main [README](../../../README.md) for details. | ||
| - Install Docker. Please refer to the [official documentation](https://docs.docker.com/get-docker/) for details. | ||
| - Install Triton HTTP client (used by the OVMS adapter) into the Python environment: | ||
|
|
||
| ```bash | ||
| pip install 'tritonclient[http]' | ||
| ``` | ||
|
|
||
| - Download a model by running a Python code with Model API, see Python [example](../../synchronous_api/README.md) and resave a configured model at OVMS friendly folder layout: | ||
|
|
||
| ```python | ||
| from model_api.models import DetectionModel | ||
|
|
||
| DetectionModel.create_model("ssd_mobilenet_v1_fpn_coco").save("/home/user/models/ssd_mobilenet_v1_fpn_coco/1/ssd_mobilenet_v1_fpn_coco.xml") | ||
| ``` | ||
|
|
||
| - Run docker with OVMS server: | ||
|
|
||
| ```bash | ||
| 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 | ||
| ``` | ||
|
|
||
| ## Run example | ||
|
|
||
| To run the example, please execute the following command: | ||
|
|
||
| ```bash | ||
| python run.py <path_to_image> | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #!/usr/bin/env python3 | ||
| # | ||
| # Copyright (C) 2020-2024 Intel Corporation | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
|
|
||
| import sys | ||
|
|
||
| import cv2 | ||
|
|
||
| from model_api.models import DetectionModel | ||
|
|
||
|
|
||
| def main(): | ||
| if len(sys.argv) != 2: | ||
| usage_message = f"Usage: {sys.argv[0]} <path_to_image>" | ||
| raise RuntimeError(usage_message) | ||
|
|
||
| image = cv2.imread(sys.argv[1]) | ||
| if image is None: | ||
| error_message = f"Failed to read the image: {sys.argv[1]}" | ||
| raise RuntimeError(error_message) | ||
| image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) | ||
| # Create Object Detection model specifying the OVMS server URL | ||
| model = DetectionModel.create_model( | ||
| "localhost:8000/v2/models/ssd_mobilenet_v1_fpn_coco", | ||
| model_type="ssd", | ||
| ) | ||
| detections = model(image) | ||
| print(f"Detection results: {detections}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # OpenVINO Model Server Adapter | ||
|
|
||
| The `OVMSAdapter` implements `InferenceAdapter` interface. The `OVMSAdapter` makes it possible to use Model API with models hosted in OpenVINO Model Server. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| `OVMSAdapter` enables inference via calls to OpenVINO Model Server, so in order to use it you need two things: | ||
|
|
||
| - OpenVINO Model Server that serves your model | ||
| - [`tritonclient[http]`](https://pypi.org/project/tritonclient/) package installed to enable communication with the model server: `python3 -m pip install tritonclient[http]` | ||
|
|
||
| ### Deploy OpenVINO Model Server | ||
|
|
||
| Model Server is distributed as a docker image and it's available in DockerHub, so you can use it with `docker run` command. See [model server documentation](https://github.com/openvinotoolkit/model_server/blob/main/docs/starting_server.md) to learn how to deploy OpenVINO optimized models with OpenVINO Model Server. | ||
|
|
||
| ## Model configuration | ||
|
|
||
| When using OpenVINO Model Server model cannot be directly accessed from the client application. Therefore any configuration must be done on model server side or before starting the server: see [Prepare a model for `InferenceAdapter`](../../../../../README.md#prepare-a-model-for-inferenceadapter). | ||
|
|
||
| ### Input reshaping | ||
|
|
||
| For some use cases you may want your model to reshape to match input of certain size. In that case, you should provide `--shape auto` parameter to model server startup command. With that option, model server will reshape model input on demand to match the input data. | ||
|
|
||
| ### Inference options | ||
|
|
||
| It's possible to configure inference related options for the model in OpenVINO Model Server with options: | ||
|
|
||
| - `--target_device` - name of the device to load the model to | ||
| - `--nireq` - number of InferRequests | ||
| - `--plugin_config` - configuration of the device plugin | ||
|
|
||
| See [model server configuration parameters](https://github.com/openvinotoolkit/model_server/blob/main/docs/starting_server.md#serving-a-single-model) for more details. | ||
|
|
||
| ### Example OVMS startup command | ||
|
|
||
| ```bash | ||
| docker run -d --rm -v /home/user/models:/models -p 8000:8000 openvino/model_server:latest --model_path /models/model1 --model_name model1 --port 8000 --shape auto --nireq 32 --target_device CPU --plugin_config "{\"CPU_THROUGHPUT_STREAMS\": \"CPU_THROUGHPUT_AUTO\"}" | ||
| ``` | ||
|
|
||
| > **Note**: In demos, while using `--adapter ovms`, inference options like: `-nireq`, `-nstreams` `-nthreads` as well as device specification with `-d` will be ignored. | ||
|
|
||
| ## Running demos with OVMSAdapter | ||
|
|
||
| To run the demo with model served in OpenVINO Model Server, you would have to provide `--adapter ovms` option and modify `-m` parameter to indicate model inference service instead of the model files. Model parameter for `OVMSAdapter` follows this schema: | ||
|
|
||
| `<service_address>/v2/models/<model_name>[/versions/<model_version>[/]]` | ||
|
|
||
| - `<service_address>` - OVMS service address in form `<address>:<port>` | ||
| - `<model_name>` - name of the target model (the one specified by `model_name` parameter in the model server startup command) | ||
| - `<model_version>` _(optional)_ - version of the target model specified in the `/versions/<model_version>` path segment (default: latest) | ||
|
|
||
| Assuming that model server runs on the same machine as the demo, exposes service on port 8000 and serves model called `model1`, the value of `-m` parameter would be: | ||
|
|
||
| - `localhost:8000/v2/models/model1` - requesting latest model version | ||
| - `localhost:8000/v2/models/model1/versions/2` - requesting model version number 2 (an optional trailing slash, e.g. `/versions/2/`, is also accepted) | ||
|
|
||
|
tybulewicz marked this conversation as resolved.
|
||
| ## See Also | ||
|
|
||
| - [OpenVINO Model Server](https://github.com/openvinotoolkit/model_server) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.