diff --git a/Makefile b/Makefile index 25d4bb1..d4fd28a 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ ovms-build-image: cd model_server && CHECK_COVERAGE=0 RUN_TESTS=0 make ovms_builder_image build-capi-python: - docker build -f capi_python/Dockerfile -t capi_python_bind:dev . + docker build -f capi-python/Dockerfile -t capi-python_bind:dev --target bin --output=. . run: - docker run -it --rm --entrypoint /bin/bash capi_python_bind:dev \ No newline at end of file + docker run -it --rm -v ./capi-python:/tmp/project --entrypoint /bin/bash capi_python_bind:dev \ No newline at end of file diff --git a/capi_python/BUILD b/capi-python/BUILD similarity index 100% rename from capi_python/BUILD rename to capi-python/BUILD diff --git a/capi-python/Dockerfile b/capi-python/Dockerfile new file mode 100644 index 0000000..ac2308c --- /dev/null +++ b/capi-python/Dockerfile @@ -0,0 +1,18 @@ +# FROM openvino/model_server:2024.1-gpu +FROM openvino/model_server-build:latest AS builder + +USER root + +WORKDIR / +RUN git clone https://github.com/openvinotoolkit/model_server + +WORKDIR /model_server + +COPY capi-python/ /model_server/src/capi-python + +RUN bazel build --jobs=8 //src/capi-python:ovmspybind.so + +RUN mkdir -p /output && find / -name "ovmspybind.so" -exec cp "{}" /output/ovmspybind.so \; + +FROM scratch as bin +COPY --from=builder /output/ovmspybind.so / \ No newline at end of file diff --git a/capi_python/README.md b/capi-python/README.md similarity index 55% rename from capi_python/README.md rename to capi-python/README.md index 2be75bb..489c5f5 100644 --- a/capi_python/README.md +++ b/capi-python/README.md @@ -10,8 +10,8 @@ find / -type f -name "pyovms.so" find / -type f -name "ovmspybind.so" -rm /ovms/src/python/capi_python/ovmspybind.so && cp /root/.cache/bazel/_bazel_root/bc57d4817a53cab8c785464da57d1983/execroot/ovms/bazel-out/k8-opt/bin/src/python/capi_python/ovmspybind.so src/python/capi_python/ +rm /ovms/src/python/capi-python/ovmspybind.so && cp /root/.cache/bazel/_bazel_root/bc57d4817a53cab8c785464da57d1983/execroot/ovms/bazel-out/k8-opt/bin/src/python/capi-python/ovmspybind.so src/python/capi-python/ -python3 src/python/capi_python/ovms-pybind.py +python3 src/python/capi-python/ovms-pybind.py -bazel --output_base=$PWD/output build //src/python/capi_python:ovmspybind.so \ No newline at end of file +bazel --output_base=$PWD/output build //src/python/capi-python:ovmspybind.so \ No newline at end of file diff --git a/capi_python/commands.sh b/capi-python/commands.sh similarity index 56% rename from capi_python/commands.sh rename to capi-python/commands.sh index b530c29..50bf2b2 100644 --- a/capi_python/commands.sh +++ b/capi-python/commands.sh @@ -5,12 +5,12 @@ find / -type f -name "pyovms.so" find / -type f -name "ovmspybind.so" find / -name "mytest.txt" -exec cp "{}" /output/mytest.txt \; -rm /ovms/src/python/capi_python/ovmspybind.so && cp /root/.cache/bazel/_bazel_root/bc57d4817a53cab8c785464da57d1983/execroot/ovms/bazel-out/k8-opt/bin/src/python/capi_python/ovmspybind.so src/python/capi_python/ +rm /ovms/src/python/capi-python/ovmspybind.so && cp /root/.cache/bazel/_bazel_root/bc57d4817a53cab8c785464da57d1983/execroot/ovms/bazel-out/k8-opt/bin/src/python/capi-python/ovmspybind.so src/python/capi-python/ -python3 src/python/capi_python/ovms-pybind.py +python3 src/python/capi-python/ovms-pybind.py -bazel --output_base=$PWD/output build //src/python/capi_python:ovmspybind.so +bazel --output_base=$PWD/output build //src/python/capi-python:ovmspybind.so /model_serve -/root/.cache/bazel/_bazel_root/a249bbdc9c7f020e8d44a19d57754c73/execroot/ovms/bazel-out/k8-opt/bin/src/capi_python/ovmspybind.so +/root/.cache/bazel/_bazel_root/a249bbdc9c7f020e8d44a19d57754c73/execroot/ovms/bazel-out/k8-opt/bin/src/capi-python/ovmspybind.so diff --git a/capi-python/config.json b/capi-python/config.json new file mode 100644 index 0000000..e9c7e6d --- /dev/null +++ b/capi-python/config.json @@ -0,0 +1,18 @@ +{ + "model_config_list": [ + { + "config": { + "name": "yolov5s", + "base_path": "models/yolov5s/FP16-INT8", + "layout": "NHWC:NCHW", + "shape": "(1,416,416,3)", + "nireq": 1, + "batch_size": "1", + "plugin_config": { + "PERFORMANCE_HINT": "LATENCY" + }, + "target_device": "CPU" + } + } + ] +} diff --git a/capi_python/ovms-pybind.cpp b/capi-python/ovms-pybind.cpp similarity index 100% rename from capi_python/ovms-pybind.cpp rename to capi-python/ovms-pybind.cpp diff --git a/capi_python/ovms-pybind.py b/capi-python/ovms-pybind.py similarity index 84% rename from capi_python/ovms-pybind.py rename to capi-python/ovms-pybind.py index dd701e3..6e066bd 100644 --- a/capi_python/ovms-pybind.py +++ b/capi-python/ovms-pybind.py @@ -3,6 +3,7 @@ sys.path.insert(1, './') import ovmspybind +import time serverSet = ovmspybind.ServerSettingsNew() print(serverSet.grpcPort) @@ -11,7 +12,7 @@ modelSet = ovmspybind.ModelSettingsNew() print(modelSet.configPath) -modelSet.configPath = "src/python/capi_python/config.json" +modelSet.configPath = "config.json" print(modelSet.configPath) status = ovmspybind.StatusCode.OK @@ -24,4 +25,8 @@ print(server.isLive()) startStatus = server.start(serverSet, modelSet) print(startStatus.getCode()) -print(server.isLive()) \ No newline at end of file + +while True: + print(server.isLive()) + time.sleep(5) + diff --git a/capi_python/Dockerfile b/capi_python/Dockerfile deleted file mode 100644 index 0dd8670..0000000 --- a/capi_python/Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -# FROM openvino/model_server:2024.1-gpu -FROM openvino/model_server-build:latest - -USER root - -WORKDIR / -RUN git clone https://github.com/openvinotoolkit/model_server - -WORKDIR /model_server - -COPY capi_python/ /model_server/src/capi_python - -RUN bazel --jobs=8 build //src/capi_python:ovmspybind.so - -RUN find / -name "ovmspybind.so" -exec cp "{}" /output/ovmspybind.so \; - -# FROM scratch as bin -# COPY --from=builder /output/ovmspybind.so / \ No newline at end of file diff --git a/capi_python/config.json b/capi_python/config.json deleted file mode 100644 index c25117b..0000000 --- a/capi_python/config.json +++ /dev/null @@ -1,72 +0,0 @@ -{ - "model_config_list": [ - { - "config": { - "name": "resnet_model", - "base_path": "/workspace/resnet50-onnx", - "layout": "NHWC:NCHW", - "shape": "(1,224,224,3)", - "plugin_config": { - "NUM_STREAMS": "1" - } - } - } - ], - "custom_node_library_config_list": [ - {"name": "image_transformation", - "base_path": "/workspace/lib/libcustom_node_image_transformation.so"} - ], - "pipeline_config_list": [ - { - "name": "resnet", - "inputs": ["0"], - "nodes": [ - { - "name": "image_transformation_node", - "library_name": "image_transformation", - "type": "custom", - "params": { - "target_image_width": "224", - "target_image_height": "224", - - "mean_values": "[123.675,116.28,103.53]", - "scale_values": "[58.395,57.12,57.375]", - - "original_image_color_order": "BGR", - "target_image_color_order": "BGR", - - "original_image_layout": "NHWC", - "target_image_layout": "NHWC", - - "debug": "true" - }, - "inputs": [ - {"image": { - "node_name": "request", - "data_item": "0"}}], - "outputs": [ - {"data_item": "image", - "alias": "transformed_image"}] - }, - { - "name": "resnet_node", - "model_name": "resnet_model", - "type": "DL model", - "inputs": [ - {"gpu_0/data_0": {"node_name": "image_transformation_node", - "data_item": "transformed_image"}} - ], - "outputs": [ - {"data_item": "gpu_0/softmax_1", - "alias": "1463"} - ] - } - ], - "outputs": [ - {"1463": { - "node_name": "resnet_node", - "data_item": "1463"}} - ] - } - ] -}