Skip to content
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

RT-DETR r50 demo #562

Merged
merged 6 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,9 @@ Sample location: [kafka_redis_adapter](./kafka_redis_adapter)
A sample demonstrating the use of pass-through mode in Savant.

Sample location: [pass_through_processing](./pass_through_processing)

### RT-DETR R50 Demo

A sample demonstrating the use of RT-DETR model in Savant.

Sample location: [rtdetr](./rtdetr/)
55 changes: 55 additions & 0 deletions samples/rtdetr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# RT-DETR R50 Demo

The sample shows how RT-DETR model can be used in a Savant module.

The detector model was prepared in the ONNX format using instructions from [DeepStream-Yolo repo](https://github.com/marcoslucianops/DeepStream-Yolo/blob/master/docs/RTDETR.md).

Weights used: `v0.1/rtdetr_r50vd_6x_coco_from_paddle.pth` from the [RT-DETR releases](https://github.com/lyuwenyu/storage/releases).

Tested on platforms:

- Nvidia Turing.

Demonstrated operational modes:

- real-time processing: RTSP streams.

Demonstrated adapters:

- RTSP source adapter;
- Always-ON RTSP sink adapter.

## Prerequisites

```bash
git clone https://github.com/insight-platform/Savant.git
cd Savant
git lfs pull
./utils/check-environment-compatible
```

**Note**: Ubuntu 22.04 runtime configuration [guide](https://insight-platform.github.io/Savant/develop/getting_started/0_configure_prod_env.html) helps to configure the runtime to run Savant pipelines.

## Build Engines

The demo uses models that are compiled into TensorRT engines the first time the demo is run. This takes time. Optionally, you can prepare the engines before running the demo by using the command:

```bash
# you are expected to be in Savant/ directory

./samples/rtdetr/build_engines.sh
```

## Run Demo

```bash
# you are expected to be in Savant/ directory

# if x86
docker compose -f samples/rtdetr/docker-compose.x86.yml up

# open 'rtsp://127.0.0.1:554/stream' in your player
# or visit 'http://127.0.0.1:888/stream/' (LL-HLS)

# Ctrl+C to stop running the compose bundle
```
12 changes: 12 additions & 0 deletions samples/rtdetr/build_engines.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
# you are expected to be in Savant/ directory

MODULE_CONFIG=samples/rtdetr/module.yml

if [ "$(uname -m)" = "aarch64" ]; then
echo "aarch64 not supported for this demo."
else
docker compose -f samples/rtdetr/docker-compose.x86.yml build module
fi

./scripts/run_module.py -i rtdetr-module --build-engines $MODULE_CONFIG
68 changes: 68 additions & 0 deletions samples/rtdetr/docker-compose.x86.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
version: "3.3"
services:

video-loop-source:
image: ghcr.io/insight-platform/savant-adapters-gstreamer:latest
restart: unless-stopped
volumes:
- zmq_sockets:/tmp/zmq-sockets
- /tmp/video-loop-source-downloads:/tmp/video-loop-source-downloads
environment:
- LOCATION=https://eu-central-1.linodeobjects.com/savant-data/demo/leeds_1080p.mp4
- DOWNLOAD_PATH=/tmp/video-loop-source-downloads
- ZMQ_ENDPOINT=dealer+connect:ipc:///tmp/zmq-sockets/input-video.ipc
- SOURCE_ID=leeds
- SYNC_OUTPUT=True
entrypoint: /opt/savant/adapters/gst/sources/video_loop.sh
depends_on:
module:
condition: service_healthy

module:
build:
context: .
dockerfile: docker/Dockerfile.x86
volumes:
- zmq_sockets:/tmp/zmq-sockets
- ../../models/rtdetr:/models
- ../../downloads/rtdetr:/downloads
- .:/opt/savant/samples/rtdetr
command: samples/rtdetr/module.yml
environment:
- ZMQ_SRC_ENDPOINT=router+bind:ipc:///tmp/zmq-sockets/input-video.ipc
- ZMQ_SINK_ENDPOINT=pub+bind:ipc:///tmp/zmq-sockets/output-video.ipc
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]

always-on-sink:
image: ghcr.io/insight-platform/savant-adapters-deepstream:latest
restart: unless-stopped
ports:
- "554:554" # RTSP
- "1935:1935" # RTMP
- "888:888" # HLS
- "8889:8889" # WebRTC
volumes:
- zmq_sockets:/tmp/zmq-sockets
- ../assets/stub_imgs:/stub_imgs
environment:
- ZMQ_ENDPOINT=sub+connect:ipc:///tmp/zmq-sockets/output-video.ipc
- SOURCE_ID=leeds
- STUB_FILE_LOCATION=/stub_imgs/smpte100_1920x1080.jpeg
- DEV_MODE=True
command: python -m adapters.ds.sinks.always_on_rtsp
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]

volumes:
zmq_sockets:
27 changes: 27 additions & 0 deletions samples/rtdetr/docker/Dockerfile.x86
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# build nvinfer custom library for yolo models (create engine and parse bbox functions)
# https://github.com/marcoslucianops/DeepStream-Yolo
FROM nvcr.io/nvidia/deepstream:6.3-triton-multiarch as builder

ENV CUDA_VER=12.1
ARG DS_YOLO_VER=5af9da189d91fa8808695c488a417f9f1c920b77
ARG DS_YOLO_PATH=/opt/yolo
ARG NVDSINFER_PATH=/opt/nvidia/deepstream/deepstream/sources/libs/nvdsinfer

RUN git clone https://github.com/marcoslucianops/DeepStream-Yolo.git $DS_YOLO_PATH \
&& cd $DS_YOLO_PATH \
&& git checkout $DS_YOLO_VER \
&& make -C nvdsinfer_custom_impl_Yolo

# patch nvdsinfer_model_builder.cpp: use engine path to place created engine
COPY nvdsinfer_model_builder.patch $NVDSINFER_PATH/
RUN cd $NVDSINFER_PATH && \
patch nvdsinfer_model_builder.cpp < nvdsinfer_model_builder.patch && \
make

FROM ghcr.io/insight-platform/savant-deepstream:latest

ARG DS_YOLO_PATH=/opt/yolo
ARG NVDSINFER_PATH=/opt/nvidia/deepstream/deepstream/sources/libs/nvdsinfer

COPY --from=builder $DS_YOLO_PATH/nvdsinfer_custom_impl_Yolo/libnvdsinfer_custom_impl_Yolo.so /opt/savant/lib/
COPY --from=builder $NVDSINFER_PATH/libnvds_infer.so /opt/nvidia/deepstream/deepstream/lib/
42 changes: 42 additions & 0 deletions samples/rtdetr/module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: rtdetr_r50_demo

parameters:
frame:
width: 1920
height: 1080
output_frame:
codec: ${oc.env:CODEC, 'h264'}
draw_func: {}
batch_size: 1

model_name: rtdetr_r50
model_ver: 5af9da1

model: ${parameters.model_name}_${parameters.model_ver}

pipeline:

elements:
- element: nvinfer@detector
name: ${parameters.model_name}
model:
remote:
url: s3://savant-data/models/${parameters.model}/${parameters.model}.zip
checksum_url: s3://savant-data/models/${parameters.model}/${parameters.model}.md5
parameters:
endpoint: https://eu-central-1.linodeobjects.com
format: onnx

workspace_size: 6144
model_file: ${parameters.model_name}.onnx
label_file: labels.txt
custom_lib_path: /opt/savant/lib/libnvdsinfer_custom_impl_Yolo.so
parse_bbox_func_name: NvDsInferParseYolo
engine_create_func_name: NvDsInferYoloCudaEngineGet

input:
scale_factor: 0.0039215697906911373
maintain_aspect_ratio: False

output:
num_detected_classes: 80
14 changes: 14 additions & 0 deletions samples/rtdetr/nvdsinfer_model_builder.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- nvdsinfer_model_builder.cpp 2023-04-20 13:36:23.753901493 +0700
+++ nvdsinfer_model_builder_new.cpp 2023-04-20 13:44:18.230221914 +0700
@@ -830,6 +830,11 @@
suggestedPathName =
modelPath + "_b" + std::to_string(initParams.maxBatchSize) + "_" +
devId + "_" + networkMode2Str(networkMode) + ".engine";
+ /* Workaround for predictable engine file path. */
+ if (!string_empty(initParams.modelEngineFilePath))
+ {
+ suggestedPathName = initParams.modelEngineFilePath;
+ }
return engine;
}