Skip to content

Commit

Permalink
feat: add capi yolov5 implementation and docs (intel-retail#337)
Browse files Browse the repository at this point in the history
* feat: add capi yolov5 implementation and docs

closes: intel-retail#323

Signed-off-by: Valina Li <[email protected]>
  • Loading branch information
vli11 authored Nov 10, 2023
1 parent 617ed05 commit e46cf46
Show file tree
Hide file tree
Showing 16 changed files with 1,280 additions and 34 deletions.
16 changes: 11 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Copyright © 2023 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

.PHONY: build-dlstreamer build-dlstreamer-realsense build-grpc-python build-grpc-go build-python-apps build-telegraf build-gst-capi
.PHONY: build-dlstreamer build-dlstreamer-realsense build-grpc-python build-grpc-go build-python-apps build-telegraf build-capi_face_detection build-capi_yolov5
.PHONY: run-camera-simulator run-telegraf
.PHONY: clean-grpc-go clean-segmentation clean-ovms-server clean-ovms clean-all clean-results clean-telegraf clean-models clean-webcam
.PHONY: clean clean-simulator clean-object-detection clean-classification clean-gst clean-capi_face_detection
.PHONY: clean clean-simulator clean-object-detection clean-classification clean-gst clean-capi_face_detection clean-capi_yolov5
.PHONY: list-profiles
.PHONY: unit-test-profile-launcher build-profile-launcher profile-launcher-status clean-profile-launcher webcam-rtsp
.PHONY: clean-test
Expand Down Expand Up @@ -49,7 +49,7 @@ build-ovms-server:
HTTPS_PROXY=${HTTPS_PROXY} HTTP_PROXY=${HTTP_PROXY} docker pull openvino/model_server:2023.1-gpu
sudo docker build --build-arg HTTPS_PROXY=${HTTPS_PROXY} --build-arg HTTP_PROXY=${HTTP_PROXY} -f configs/opencv-ovms/models/2022/Dockerfile.updateDevice -t update_config:dev configs/opencv-ovms/models/2022/.

clean-profile-launcher: clean-grpc-python clean-grpc-go clean-segmentation clean-object-detection clean-classification clean-gst clean-capi_face_detection clean-test
clean-profile-launcher: clean-grpc-python clean-grpc-go clean-segmentation clean-object-detection clean-classification clean-gst clean-capi_face_detection clean-test clean-capi_yolov5
@echo "containers launched by profile-launcher are cleaned up."
@pkill -9 profile-launcher || true

Expand Down Expand Up @@ -86,6 +86,9 @@ clean-ovms: clean-profile-launcher clean-ovms-server
clean-capi_face_detection:
./clean-containers.sh capi_face_detection

clean-capi_yolov5:
./clean-containers.sh capi_yolov5

clean-telegraf:
./clean-containers.sh influxdb2
./clean-containers.sh telegraf
Expand Down Expand Up @@ -131,8 +134,11 @@ build-grpc-go: build-profile-launcher
build-python-apps: build-profile-launcher
cd configs/opencv-ovms/demos && make build

build-gst-capi: build-profile-launcher
cd configs/opencv-ovms/gst_capi && $(MAKE) build
build-capi_face_detection: build-profile-launcher
cd configs/opencv-ovms/gst_capi && $(MAKE) build_face_detection

build-capi_yolov5: build-profile-launcher
cd configs/opencv-ovms/gst_capi && $(MAKE) build_capi_yolov5

clean-docs:
rm -rf docs/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ OvmsClient:
- "$RUN_PATH/configs/opencv-ovms/gst_capi/extensions:/home/intel/gst-ovms/extensions"
- "$RUN_PATH/results:/tmp/results"
- "$RUN_PATH/configs/opencv-ovms/models/2022/:/home/intel/gst-ovms/models"
PipelineScript: ./run_face_detection.sh
PipelineScript: ./run_gst_capi.sh
PipelineInputArgs: "" # space delimited like we run the script in command and take those input arguments
EnvironmentVariableFiles:
- capi_face_detection.env
17 changes: 17 additions & 0 deletions configs/opencv-ovms/cmd_client/res/capi_yolov5/configuration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
OvmsSingleContainer: true
OvmsClient:
DockerLauncher:
Script: docker-launcher.sh
DockerImage: openvino/model_server-capi-gst-ovms:latest
ContainerName: capi_yolov5
Volumes:
- "$cl_cache_dir:/home/intel/gst-ovms/.cl-cache"
- /tmp/.X11-unix:/tmp/.X11-unix
- "$RUN_PATH/sample-media/:/home/intel/gst-ovms/vids"
- "$RUN_PATH/configs/opencv-ovms/gst_capi/extensions:/home/intel/gst-ovms/extensions"
- "$RUN_PATH/results:/tmp/results"
- "$RUN_PATH/configs/opencv-ovms/models/2022/:/models"
PipelineScript: ./run_gst_capi.sh
PipelineInputArgs: "" # space delimited like we run the script in command and take those input arguments
EnvironmentVariableFiles:
- capi_yolov5.env
11 changes: 11 additions & 0 deletions configs/opencv-ovms/envs/capi_yolov5.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
RENDER_PORTRAIT_MODE=0
GST_DEBUG=0
USE_ONEVPL=1
PIPELINE_EXEC_PATH=pipelines/capi_yolov5/capi_yolov5
GST_VAAPI_DRM_DEVICE=/dev/dri/renderD128
TARGET_GPU_DEVICE=--privileged
LOG_LEVEL=0
RENDER_MODE=1
cl_cache_dir=/home/intel/gst-ovms/.cl-cache
WINDOW_WIDTH=1920
WINDOW_HEIGHT=1080
5 changes: 2 additions & 3 deletions configs/opencv-ovms/grpc_go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ func main() {
func runModelServer(client *grpc_client.GRPCInferenceServiceClient, webcam *gocv.VideoCapture, img *gocv.Mat, modelname string,
modelVersion string, stream *mjpeg.Stream, camWidth float32, camHeight float32) {
var aggregateLatencyAfterInfer float64
var aggregateLatencyAfterFinalProcess float64
var frameNum float64

initTime := float64(time.Now().UnixMilli())
for webcam.IsOpened() {
if ok := webcam.Read(img); !ok {
// retry once after 1 millisecond
Expand Down Expand Up @@ -135,8 +135,7 @@ func runModelServer(client *grpc_client.GRPCInferenceServiceClient, webcam *gocv
// Print after processing latency
afterFinalProcess := float64(time.Now().UnixMilli())
processTime := afterFinalProcess - start
aggregateLatencyAfterFinalProcess += processTime
avgFps := frameNum / (aggregateLatencyAfterFinalProcess / 1000.0)
avgFps := frameNum / ((afterFinalProcess - initTime) / 1000.0)
averageFPSStr := fmt.Sprintf("%v\n", avgFps)
fmt.Printf("Processing time: %v ms; fps: %s", processTime, averageFPSStr)

Expand Down
5 changes: 3 additions & 2 deletions configs/opencv-ovms/gst_capi/Dockerfile.ovms-capi-gst
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ RUN DEBIAN_FRONTEND=noninteractive apt install -y jq -y && \
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
COPY gst_capi/pipelines /home/intel/gst-ovms/pipelines
COPY gst_capi/launch-pipeline.sh /home/intel/gst-ovms/launch-pipeline.sh
COPY gst_capi/run_face_detection.sh /home/intel/gst-ovms/run_face_detection.sh
RUN cd /home/intel/gst-ovms/pipelines; chmod +x build-demos.sh; ./build-demos.sh
COPY gst_capi/run_gst_capi.sh /home/intel/gst-ovms/run_gst_capi.sh
ARG PIPELINE_NAME
RUN echo $PIPELINE_NAME; cd /home/intel/gst-ovms/pipelines/$PIPELINE_NAME; make build

USER ovms
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
Expand Down
16 changes: 14 additions & 2 deletions configs/opencv-ovms/gst_capi/Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
# Copyright © 2023 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

.PHONY: build
.PHONY: build_face_detection build_capi_yolov5

OVMS_CPP_DOCKER_IMAGE ?= openvino/model_server
OVMS_CPP_IMAGE_TAG ?= latest

build:
build_face_detection:
# Build CAPI docker image
docker build $(NO_CACHE_OPTION) -f Dockerfile.ovms-capi-gst ../ \
--build-arg http_proxy=$(HTTP_PROXY) \
--build-arg https_proxy="$(HTTPS_PROXY)" \
--build-arg no_proxy=$(NO_PROXY) \
--build-arg BASE_IMAGE=ubuntu:22.04 \
--build-arg PIPELINE_NAME=face_detection \
--progress=plain \
-t $(OVMS_CPP_DOCKER_IMAGE)-capi-gst-ovms:$(OVMS_CPP_IMAGE_TAG)

build_capi_yolov5:
# Build CAPI docker image
docker build $(NO_CACHE_OPTION) -f Dockerfile.ovms-capi-gst ../ \
--build-arg http_proxy=$(HTTP_PROXY) \
--build-arg https_proxy="$(HTTPS_PROXY)" \
--build-arg no_proxy=$(NO_PROXY) \
--build-arg BASE_IMAGE=ubuntu:22.04 \
--build-arg PIPELINE_NAME=capi_yolov5 \
--progress=plain \
-t $(OVMS_CPP_DOCKER_IMAGE)-capi-gst-ovms:$(OVMS_CPP_IMAGE_TAG)
6 changes: 4 additions & 2 deletions configs/opencv-ovms/gst_capi/launch-pipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ INPUTSRC=$2
USE_ONEVPL=$3
RENDER_MODE=$4
RENDER_PORTRAIT_MODE=$5
WINDOW_WIDTH=$6
WINDOW_HEIGHT=$7

# Obtaining codec_type (avc or hevc)
is_avc=`gst-discoverer-1.0 "$INPUTSRC" | grep -i h.264 | wc -l`

echo "./$PIPELINE_EXEC_PATH $INPUTSRC $USE_ONEVPL $RENDER_MODE $RENDER_PORTRAIT_MODE $is_avc"
./"$PIPELINE_EXEC_PATH" "$INPUTSRC" "$USE_ONEVPL" "$RENDER_MODE" "$RENDER_PORTRAIT_MODE" "$is_avc"
echo "./$PIPELINE_EXEC_PATH $INPUTSRC $USE_ONEVPL $RENDER_MODE $RENDER_PORTRAIT_MODE $is_avc $WINDOW_WIDTH $WINDOW_HEIGHT"
./"$PIPELINE_EXEC_PATH" "$INPUTSRC" "$USE_ONEVPL" "$RENDER_MODE" "$RENDER_PORTRAIT_MODE" "$is_avc" "$WINDOW_WIDTH" "$WINDOW_HEIGHT"
16 changes: 0 additions & 16 deletions configs/opencv-ovms/gst_capi/pipelines/build-demos.sh

This file was deleted.

23 changes: 23 additions & 0 deletions configs/opencv-ovms/gst_capi/pipelines/capi_yolov5/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# Copyright (c) 2023 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.
#

.PHONY: build

CV_LIBS = -L/usr/lib/x86_64-linux-gnu/ -L/usr/local/lib/x86_64-linux-gnu/ -L/ovms/lib/
CV_INCLUDES = -I/usr/lib/include/opencv4

build:
g++ 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/usr/include/gstreamer-1.0/ -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_videoio -lopencv_core -lopencv_videoio_gstreamer -lovms_shared -lopencv_highgui -lpthread -fPIC --std=c++17 -o capi_yolov5
Loading

0 comments on commit e46cf46

Please sign in to comment.