Skip to content

Commit

Permalink
Add capi yolov8 docker compose use cases for gst-capi (#22)
Browse files Browse the repository at this point in the history
* fix: resolve the CAPI build issue on dependency changes intel-onevpl

  FIXES: #20

Signed-off-by: Jim Wang <[email protected]>

* feat: add yolov8 docker-compose for gst_capi use cases

Signed-off-by: Jim Wang <[email protected]>

* fix: update copyright year

Signed-off-by: Jim Wang <[email protected]>

* fix: resolve the RENDER_MODE issue setting from make run command

Signed-off-by: Jim Wang <[email protected]>

---------

Signed-off-by: Jim Wang <[email protected]>
  • Loading branch information
jim-wang-intel authored Apr 29, 2024
1 parent df0e788 commit 9a848b5
Show file tree
Hide file tree
Showing 25 changed files with 4,808 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ use-cases/gst_capi/docker-compose_capi_face_detection.yml
use-cases/demos/docker-compose_demo_classification.yml
use-cases/demos/docker-compose_demo_instance_segmentation.yml
use-cases/demos/docker-compose_demo_object_detection.yml
use-cases/gst_capi/docker-compose_capi_yolov8_ensemble.yml
smoke-tests/smoke_tests_output.log
22 changes: 16 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
.PHONY: build-capi_yolov5 run-capi_yolov5 down-capi_yolov5
.PHONY: build-capi_yolov5_ensemble run-capi_yolov5_ensemble down-capi_yolov5_ensemble
.PHONY: build-capi_face_detection run-capi_face_detection down-capi_face_detection
.PHONY: build-capi_yolov8_ensemble run-capi_yolov8_ensemble down-capi_yolov8_ensemble
.PHONY: build-all-capis
.PHONY: build-demos down-demos-all
.PHONY: run-demo-classification down-demo-classification run-demo-instance-segmentation down-demo-instance-segmentation run-demo-object-detection down-demo-object-detection
Expand Down Expand Up @@ -80,7 +81,7 @@ down-grpc_python:
build-capi_yolov5:
@cd ./use-cases/gst_capi && $(MAKE) --no-print-directory build_capi_yolov5

run-capi_yolov5:
run-capi_yolov5: prepare-inputs
@cd ./use-cases/gst_capi && $(MAKE) --no-print-directory DOCKER_COMPOSE=docker-compose_capi_yolov5.yml run_capi_yolov5

down-capi_yolov5:
Expand All @@ -89,7 +90,7 @@ down-capi_yolov5:
build-capi_yolov5_ensemble:
@cd ./use-cases/gst_capi && $(MAKE) --no-print-directory build_capi_yolov5_ensemble

run-capi_yolov5_ensemble:
run-capi_yolov5_ensemble: prepare-inputs
@cd ./use-cases/gst_capi && $(MAKE) --no-print-directory DOCKER_COMPOSE=docker-compose_capi_yolov5_ensemble.yml run_capi_yolov5_ensemble

down-capi_yolov5_ensemble:
Expand All @@ -98,31 +99,40 @@ down-capi_yolov5_ensemble:
build-capi_face_detection:
@cd ./use-cases/gst_capi && $(MAKE) --no-print-directory build_face_detection

run-capi_face_detection:
run-capi_face_detection: prepare-inputs
@cd ./use-cases/gst_capi && $(MAKE) --no-print-directory DOCKER_COMPOSE=docker-compose_capi_face_detection.yml run_capi_face_detection

down-capi_face_detection:
@cd ./use-cases/gst_capi && $(MAKE) --no-print-directory DOCKER_COMPOSE=docker-compose_capi_face_detection.yml down_capi_face_detection

build-capi_yolov8_ensemble:
@cd ./use-cases/gst_capi && $(MAKE) --no-print-directory build_capi_yolov8_ensemble

run-capi_yolov8_ensemble: prepare-inputs
@cd ./use-cases/gst_capi && $(MAKE) --no-print-directory DOCKER_COMPOSE=docker-compose_capi_yolov8_ensemble.yml run_capi_yolov8_ensemble

down-capi_yolov8_ensemble:
@cd ./use-cases/gst_capi && $(MAKE) --no-print-directory DOCKER_COMPOSE=docker-compose_capi_yolov8_ensemble.yml down_capi_yolov8_ensemble

build-all-capis:
@cd ./use-cases/gst_capi && $(MAKE) --no-print-directory build

build-demos:
@cd ./use-cases/demos && $(MAKE) --no-print-directory build

run-demo-classification:
run-demo-classification: prepare-inputs
@cd ./use-cases/demos && $(MAKE) --no-print-directory DOCKER_COMPOSE=docker-compose_demo_classification.yml run_classification

down-demo-classification:
@cd ./use-cases/demos && $(MAKE) --no-print-directory down_classification

run-demo-instance-segmentation:
run-demo-instance-segmentation: prepare-inputs
@cd ./use-cases/demos && $(MAKE) --no-print-directory DOCKER_COMPOSE=docker-compose_demo_instance_segmentation.yml run_instance_segmentation

down-demo-instance-segmentation:
@cd ./use-cases/demos && $(MAKE) --no-print-directory down_instance_segmentation

run-demo-object-detection:
run-demo-object-detection: prepare-inputs
@cd ./use-cases/demos && $(MAKE) --no-print-directory DOCKER_COMPOSE=docker-compose_demo_object_detection.yml run_object_detection

down-demo-object-detection:
Expand Down
22 changes: 22 additions & 0 deletions models-downloader/Dockerfile.bitModel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Copyright (C) 2024 Intel Corporation.
#
# SPDX-License-Identifier: Apache-2.0
#

FROM openvino/ubuntu22_dev:2023.0.0

USER root

RUN apt-get update -y || true; DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
wget && \
rm -rf /var/lib/apt/lists/*

COPY download_mo_bit_models.sh /
RUN chmod +x /download_mo_bit_models.sh

RUN mkdir -p /result

WORKDIR /

ENTRYPOINT [ "/download_mo_bit_models.sh" ]
2 changes: 1 addition & 1 deletion models-downloader/downloadOVMSModels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ downloadBIT64() {
BIT_MODEL_DOWNLOADER=$(docker images --format "{{.Repository}}" | grep "bit_model_downloader")
if [ -z "$BIT_MODEL_DOWNLOADER" ]
then
docker build -f "$MODEL_EXEC_PATH"/../Dockerfile.bitModel -t bit_model_downloader:dev "$MODEL_EXEC_PATH"/../
docker build -f "$MODEL_EXEC_PATH"/Dockerfile.bitModel -t bit_model_downloader:dev "$MODEL_EXEC_PATH"/
fi
docker run --rm -v "$modelDir/$bitModelDirName/$modelPrecisionFP16INT8"/1:/result bit_model_downloader:dev
# make the bitModelDirName owned by local user instead of root
Expand Down
51 changes: 51 additions & 0 deletions use-cases/gst_capi/Dockerfile.yolov8
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#
# Copyright (C) 2023-2024 Intel Corporation.
#
#
# -----------------------------------------------------------

# https://hub.docker.com/r/openvino/model_server
ARG BASE_IMAGE=openvino/model_server:2023.1-gpu
FROM $BASE_IMAGE as release

USER root
WORKDIR /
ENV DEBIAN_FRONTEND=noninteractive
SHELL ["/bin/bash", "-c"]

# Install build tools and media UMD
ARG BUILD_DEPENDENCIES="cmake build-essential git-gui python3 python3-pip flex bison clang libgtk2.0-dev libhdf5-serial-dev libvtk9-dev libtbb2 libxml2 curl libpugixml1v5 intel-media-va-driver-non-free libmfx1 libvpl2 libegl-mesa0 libegl1-mesa libegl1-mesa-dev libgbm1 libgl1-mesa-dev libgl1-mesa-dri libglapi-mesa libgles2-mesa-dev libglx-mesa0 libigdgmm12 libxatracker2 mesa-va-drivers mesa-vdpau-drivers mesa-vulkan-drivers va-driver-all vainfo libcanberra-gtk-module jq libopencv-dev python3-opencv gstreamer1.0-plugins-base-apps"
RUN apt -y update && \
apt install -y ${BUILD_DEPENDENCIES} && \
rm -rf /var/lib/apt/lists/* && rm -rf /tmp/*

# Install GStramer
RUN apt update -y; apt install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio && \
rm -rf /var/lib/apt/lists/* && rm -rf /tmp/*

# Install MSDK/oneAPI oneVPL libs
ARG GPU_TYPE="client"
RUN apt update -y; apt install -y wget curl vim gpg-agent; wget -qO - https://repositories.intel.com/gpu/intel-graphics.key | gpg --dearmor --output /usr/share/keyrings/intel-graphics.gpg; echo "deb [arch=amd64,i386 signed-by=/usr/share/keyrings/intel-graphics.gpg] https://repositories.intel.com/gpu/ubuntu jammy $GPU_TYPE" | tee /etc/apt/sources.list.d/intel-gpu-jammy.list; apt update -y; DEBIAN_FRONTEND=noninteractive apt-get install -y libegl-mesa0 libegl1-mesa libegl1-mesa-dev libgbm1 libgl1-mesa-dev libgl1-mesa-dri libglapi-mesa libgles2-mesa-dev libglx-mesa0 libigdgmm12 libxatracker2 mesa-va-drivers mesa-vulkan-drivers libcanberra-gtk-module libmfx1 libmfxgen1 libvpl2 && \
rm -rf /var/lib/apt/lists/* && rm -rf /tmp/*

# Download OVMS C-API runtime
RUN apt update -y; apt install -y wget curl vim && \
rm -rf /var/lib/apt/lists/* && rm -rf /tmp/*
RUN wget -O ovms.tar.gz https://github.com/openvinotoolkit/model_server/releases/download/v2023.2/ovms_ubuntu22.tar.gz
RUN tar -xf ovms.tar.gz

# Copy C-API sources
ENV LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/:/usr/local/lib/x86_64-linux-gnu/:/usr/local/lib:/ovms/lib:$LD_LIBRARY_PATH
WORKDIR /tmp
RUN mkdir -p /app/gst-ovms/pipelines/

COPY capi_yolov8_ensemble /app/gst-ovms/pipelines/yolov8_ensemble

RUN cd /app/gst-ovms/pipelines/yolov8_ensemble; make build

USER ovms
WORKDIR /app/gst-ovms/pipelines

# Enable HWA decoder for OpenCV using GST use cases
ENV OPENCV_FFMPEG_CAPTURE_OPTIONS="hw_decoders_any;vaapi"
ENTRYPOINT ["/bin/bash", "-c"]
32 changes: 23 additions & 9 deletions use-cases/gst_capi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
.PHONY: run_capi_yolov5 down_capi_yolov5
.PHONY: run_capi_yolov5_ensemble down_capi_yolov5_ensemble
.PHONY: run_capi_face_detection down_capi_face_detection
.PHONY: build_capi_yolov8_ensemble

# initial default values
OVMS_CPP_DOCKER_IMAGE ?= openvino/model_server
OVMS_CPP_IMAGE_TAG ?= latest
DGPU_TYPE ?= arc # arc|flex
DOCKER_COMPOSE ?= docker-compose.yml
PIPELINE_COUNT ?= 1
RENDER_MODE ?= 0
CAMERA_SIMULATOR_COMPOSE ?= add_camera-simulator.yml
RETAIL_USE_CASE_ROOT ?= ../..
RESULTS_DIR ?= ../../results
Expand Down Expand Up @@ -63,35 +65,47 @@ build_capi_yolov5_ensemble:
--progress=plain \
-t $(OVMS_CPP_DOCKER_IMAGE)-capi-gst-ovms-capi_yolov5_ensemble:$(OVMS_CPP_IMAGE_TAG)

build_capi_yolov8_ensemble:
docker build $(NO_CACHE_OPTION) -f Dockerfile.yolov8 -t $(OVMS_CPP_DOCKER_IMAGE)-capi-gst-ovms-capi_yolov8_ensemble:$(OVMS_CPP_IMAGE_TAG) ./pipelines

gen_capi_yolov5:
@PIPELINE_COUNT=${PIPELINE_COUNT} RETAIL_USE_CASE_ROOT="$(RETAIL_USE_CASE_ROOT)" RESULTS_DIR="$(RESULTS_DIR)" docker compose -f $(CAMERA_SIMULATOR_COMPOSE) -f add_gst_capi_yolov5.yml convert > $(DOCKER_COMPOSE)
@PIPELINE_COUNT=${PIPELINE_COUNT} RENDER_MODE=${RENDER_MODE} RETAIL_USE_CASE_ROOT="$(RETAIL_USE_CASE_ROOT)" RESULTS_DIR="$(RESULTS_DIR)" docker compose -f $(CAMERA_SIMULATOR_COMPOSE) -f add_gst_capi_yolov5.yml convert > $(DOCKER_COMPOSE)

run_capi_yolov5: gen_capi_yolov5
@$(call copy_ovms_config,config_capi_yolov5.json)
PIPELINE_COUNT=$(PIPELINE_COUNT) RETAIL_USE_CASE_ROOT=$(RETAIL_USE_CASE_ROOT) docker compose -f $(DOCKER_COMPOSE) up -d
PIPELINE_COUNT=$(PIPELINE_COUNT) RENDER_MODE=${RENDER_MODE} RETAIL_USE_CASE_ROOT=$(RETAIL_USE_CASE_ROOT) docker compose -f $(DOCKER_COMPOSE) up -d

down_capi_yolov5:
PIPELINE_COUNT=$(PIPELINE_COUNT) RETAIL_USE_CASE_ROOT="$(RETAIL_USE_CASE_ROOT)" RESULTS_DIR="$(RESULTS_DIR)" docker compose -f $(DOCKER_COMPOSE) down
PIPELINE_COUNT=$(PIPELINE_COUNT) RENDER_MODE=${RENDER_MODE} RETAIL_USE_CASE_ROOT="$(RETAIL_USE_CASE_ROOT)" RESULTS_DIR="$(RESULTS_DIR)" docker compose -f $(DOCKER_COMPOSE) down
@$(call clean_ovms_config,config_capi_yolov5.json)

gen_capi_yolov5_ensemble:
@PIPELINE_COUNT=${PIPELINE_COUNT} RETAIL_USE_CASE_ROOT="$(RETAIL_USE_CASE_ROOT)" RESULTS_DIR="$(RESULTS_DIR)" docker compose -f $(CAMERA_SIMULATOR_COMPOSE) -f add_gst_capi_yolov5_ensemble.yml convert > $(DOCKER_COMPOSE)
@PIPELINE_COUNT=${PIPELINE_COUNT} RENDER_MODE=${RENDER_MODE} RETAIL_USE_CASE_ROOT="$(RETAIL_USE_CASE_ROOT)" RESULTS_DIR="$(RESULTS_DIR)" docker compose -f $(CAMERA_SIMULATOR_COMPOSE) -f add_gst_capi_yolov5_ensemble.yml convert > $(DOCKER_COMPOSE)

run_capi_yolov5_ensemble: gen_capi_yolov5_ensemble
@$(call copy_ovms_config,config_capi_yolov5_ensemble.json)
PIPELINE_COUNT=$(PIPELINE_COUNT) RETAIL_USE_CASE_ROOT="$(RETAIL_USE_CASE_ROOT)" RESULTS_DIR="$(RESULTS_DIR)" docker compose -f $(DOCKER_COMPOSE) up -d
PIPELINE_COUNT=$(PIPELINE_COUNT) RENDER_MODE=${RENDER_MODE} RETAIL_USE_CASE_ROOT="$(RETAIL_USE_CASE_ROOT)" RESULTS_DIR="$(RESULTS_DIR)" docker compose -f $(DOCKER_COMPOSE) up -d

down_capi_yolov5_ensemble:
PIPELINE_COUNT=$(PIPELINE_COUNT) RETAIL_USE_CASE_ROOT="$(RETAIL_USE_CASE_ROOT)" RESULTS_DIR="$(RESULTS_DIR)" docker compose -f $(DOCKER_COMPOSE) down
PIPELINE_COUNT=$(PIPELINE_COUNT) RENDER_MODE=${RENDER_MODE} RETAIL_USE_CASE_ROOT="$(RETAIL_USE_CASE_ROOT)" RESULTS_DIR="$(RESULTS_DIR)" docker compose -f $(DOCKER_COMPOSE) down
@$(call clean_ovms_config,config_capi_yolov5_ensemble.json)

gen_capi_face_detection:
@PIPELINE_COUNT=${PIPELINE_COUNT} RETAIL_USE_CASE_ROOT="$(RETAIL_USE_CASE_ROOT)" RESULTS_DIR="$(RESULTS_DIR)" docker compose -f $(CAMERA_SIMULATOR_COMPOSE) -f add_gst_capi_face_detection.yml convert > $(DOCKER_COMPOSE)
@PIPELINE_COUNT=${PIPELINE_COUNT} RENDER_MODE=${RENDER_MODE} RETAIL_USE_CASE_ROOT="$(RETAIL_USE_CASE_ROOT)" RESULTS_DIR="$(RESULTS_DIR)" docker compose -f $(CAMERA_SIMULATOR_COMPOSE) -f add_gst_capi_face_detection.yml convert > $(DOCKER_COMPOSE)

run_capi_face_detection: gen_capi_face_detection
@$(call copy_ovms_config,config_capi_face_detection.json)
PIPELINE_COUNT=$(PIPELINE_COUNT) RETAIL_USE_CASE_ROOT="$(RETAIL_USE_CASE_ROOT)" RESULTS_DIR="$(RESULTS_DIR)" docker compose -f $(DOCKER_COMPOSE) up -d
PIPELINE_COUNT=$(PIPELINE_COUNT) RENDER_MODE=${RENDER_MODE} RETAIL_USE_CASE_ROOT="$(RETAIL_USE_CASE_ROOT)" RESULTS_DIR="$(RESULTS_DIR)" docker compose -f $(DOCKER_COMPOSE) up -d

down_capi_face_detection:
PIPELINE_COUNT=$(PIPELINE_COUNT) RETAIL_USE_CASE_ROOT="$(RETAIL_USE_CASE_ROOT)" RESULTS_DIR="$(RESULTS_DIR)" docker compose -f $(DOCKER_COMPOSE) down
PIPELINE_COUNT=$(PIPELINE_COUNT) RENDER_MODE=${RENDER_MODE} RETAIL_USE_CASE_ROOT="$(RETAIL_USE_CASE_ROOT)" RESULTS_DIR="$(RESULTS_DIR)" docker compose -f $(DOCKER_COMPOSE) down
@$(call clean_ovms_config,config_capi_face_detection.json)

gen_capi_yolov8_ensemble:
@PIPELINE_COUNT=${PIPELINE_COUNT} RENDER_MODE=${RENDER_MODE} RETAIL_USE_CASE_ROOT="$(RETAIL_USE_CASE_ROOT)" RESULTS_DIR="$(RESULTS_DIR)" docker compose -f $(CAMERA_SIMULATOR_COMPOSE) -f add_gst_capi_yolov8_ensemble.yml convert > $(DOCKER_COMPOSE)

run_capi_yolov8_ensemble: gen_capi_yolov8_ensemble
PIPELINE_COUNT=$(PIPELINE_COUNT) RENDER_MODE=${RENDER_MODE} RETAIL_USE_CASE_ROOT="$(RETAIL_USE_CASE_ROOT)" RESULTS_DIR="$(RESULTS_DIR)" docker compose -f $(DOCKER_COMPOSE) up -d

down_capi_yolov8_ensemble:
PIPELINE_COUNT=$(PIPELINE_COUNT) RENDER_MODE=${RENDER_MODE} RETAIL_USE_CASE_ROOT="$(RETAIL_USE_CASE_ROOT)" RESULTS_DIR="$(RESULTS_DIR)" docker compose -f $(DOCKER_COMPOSE) down
2 changes: 1 addition & 1 deletion use-cases/gst_capi/add_gst_capi_face_detection.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
- CONTAINER_NAME="capi_face_detection"
- INPUTSRC=rtsp://localhost:8554/camera_2
- DEVICE=GPU
- RENDER_MODE=0 #RENDER_MODE=1 will work only after running xhost +local:docker
- RENDER_MODE=${RENDER_MODE} #RENDER_MODE=1 will work only after running xhost +local:docker
- DISPLAY=$DISPLAY
- OVMS_MODEL_CONFIG_JSON=/models/config_capi_face_detection.json
- PIPELINE_PROFILE=capi_face_detection
Expand Down
2 changes: 1 addition & 1 deletion use-cases/gst_capi/add_gst_capi_yolov5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
- CONTAINER_NAME="capi_yolov5"
- INPUTSRC=rtsp://localhost:8554/camera_0
- DEVICE=CPU
- RENDER_MODE=0 #RENDER_MODE=1 will work only after running xhost +local:docker
- RENDER_MODE=${RENDER_MODE} #RENDER_MODE=1 will work only after running xhost +local:docker
- DISPLAY=$DISPLAY
- OVMS_MODEL_CONFIG_JSON=/models/config_capi_yolov5.json
- PIPELINE_PROFILE=capi_yolov5
Expand Down
2 changes: 1 addition & 1 deletion use-cases/gst_capi/add_gst_capi_yolov5_ensemble.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
- INPUTSRC=rtsp://localhost:8554/camera_1
- DEVICE=CPU
- BARCODE=1
- RENDER_MODE=0 #RENDER_MODE=1 will work only after running xhost +local:docker
- RENDER_MODE=${RENDER_MODE} #RENDER_MODE=1 will work only after running xhost +local:docker
- DISPLAY=$DISPLAY
- OVMS_MODEL_CONFIG_JSON=/ovms_server/config.json
- PIPELINE_PROFILE=capi_yolov5_ensemble
Expand Down
38 changes: 38 additions & 0 deletions use-cases/gst_capi/add_gst_capi_yolov8_ensemble.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# Copyright (C) 2024 Intel Corporation.
#
# SPDX-License-Identifier: Apache-2.0
#

version: '3.7'
services:
CapiYolov8Ensemble:
image: openvino/model_server-capi-gst-ovms-capi_yolov8_ensemble:latest
deploy:
mode: replicated
replicas: ${PIPELINE_COUNT}
network_mode: "host"
user: root
privileged: true
entrypoint: /app/gst-ovms/pipelines/yolov8_ensemble/yolo_efficientnet.sh
env_file:
- ./res/capi_yolov8_ensemble.env
environment:
- CONTAINER_NAME="capi_yolov8_ensemble"
- INPUTSRC=rtsp://localhost:8554/camera_1
- DEVICE=CPU
- BARCODE=0
- RENDER_MODE=${RENDER_MODE} #RENDER_MODE=1 will work only after running xhost +local:docker
- DISPLAY=$DISPLAY
- OVMS_MODEL_CONFIG_JSON=/ovms_server/config-yolov8.json
- PIPELINE_PROFILE=capi_yolov8_ensemble
depends_on:
- camera-simulator1
volumes:
- ${RESULTS_DIR}:/tmp/results
- ~/.Xauthority:/home/dlstreamer/.Xauthority
- /tmp/.X11-unix
- ~/.cl-cache:/home/pipeline-server/.cl-cache
- ./res/:/home/pipeline-server/envs
- ${RETAIL_USE_CASE_ROOT}/models:/models
- ${RETAIL_USE_CASE_ROOT}/use-cases/gst_capi/res/yolov8:/ovms_server
28 changes: 28 additions & 0 deletions use-cases/gst_capi/pipelines/capi_yolov8_ensemble/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Copyright (c) 2024 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

CV_LIBS = -L/usr/lib/x86_64-linux-gnu/ -L/usr/local/lib/x86_64-linux-gnu/ -L/ovms/lib/
CV_INCLUDES = -I/usr/include/opencv4 -I/usr/include/gstreamer-1.0
CUSTOM_NODE_FLAGS = -fpic -O2 -U_FORTIFY_SOURCE -fstack-protector -fno-omit-frame-pointer -D_FORTIFY_SOURCE=1 -fno-strict-overflow -Wall -Wno-unknown-pragmas -Wno-error=sign-compare -fno-delete-null-pointer-checks -fwrapv -fstack-clash-protection -Wformat -Wformat-security

build:
g++ -c -std=c++17 efficientnetb0_node.cpp ${CUSTOM_NODE_FLAGS} ${CV_INCLUDES}

g++ -std=c++17 -shared ${CUSTOM_NODE_FLAGS} -o libcustom_node_efficientnetb0-yolov8.so efficientnetb0_node.o ${CV_LIBS} ${CV_INCLUDES} -lopencv_core -lopencv_dnn -lopencv_imgproc -lopencv_imgcodecs
cp libcustom_node_efficientnetb0-yolov8.so /ovms/lib/

g++ -std=c++17 main.cpp -I/usr/include/gstreamer-1.0/usr/lib/x86_64-linux-gnu/ -I/usr/local/include/gstreamer-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/ovms/include $(CV_INCLUDES) $(CV_LIBS) -L/usr/lib/x86_64-linux-gnu/gstreamer-1.0 -lgstbase-1.0 -lgobject-2.0 -lglib-2.0 -lgstreamer-1.0 -lgstapp-1.0 -lopencv_imgcodecs -lopencv_imgproc -lopencv_core -lovms_shared -lopencv_highgui -lopencv_dnn -lpthread -fPIC --std=c++17 -o capi_yolov8_ensemble

66 changes: 66 additions & 0 deletions use-cases/gst_capi/pipelines/capi_yolov8_ensemble/buffersqueue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//*****************************************************************************
// Copyright 2024 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************

#include "buffersqueue.hpp"

#include <iostream>

namespace ovms {
namespace custom_nodes_common {
BuffersQueue::BuffersQueue(size_t singleBufferSize, int streamsLength) :
Queue(streamsLength),
singleBufferSize(singleBufferSize),
size(singleBufferSize * streamsLength),
memoryPool(std::make_unique<char[]>(size)) {
for (int i = 0; i < streamsLength; ++i) {
inferRequests.push_back(memoryPool.get() + i * singleBufferSize);
}
}

BuffersQueue::~BuffersQueue() {}

void* BuffersQueue::getBuffer() {
// can be easily switched to async version if need arise
auto idleId = tryToGetIdleStream();
if (idleId.has_value()) {
return getInferRequest(idleId.value());
}
return nullptr;
}

bool BuffersQueue::returnBuffer(void* buffer) {
if ((static_cast<char*>(buffer) < memoryPool.get()) ||
((memoryPool.get() + size - 1) < buffer) ||
((static_cast<char*>(buffer) - memoryPool.get()) % singleBufferSize != 0)) {
return false;
}
returnStream(getBufferId(buffer));
return true;
}

int BuffersQueue::getBufferId(void* buffer) {
return (static_cast<char*>(buffer) - memoryPool.get()) / singleBufferSize;
}

const size_t BuffersQueue::getSize() {
return this->size;
}

const size_t BuffersQueue::getSingleBufferSize() {
return this->singleBufferSize;
}
} // namespace custom_nodes_common
} // namespace ovms
Loading

0 comments on commit 9a848b5

Please sign in to comment.