Skip to content

Commit

Permalink
feat: parameterize batch-size in gst pipelines via environment variable
Browse files Browse the repository at this point in the history
Use env var BATCH_SIZE to parameterize batch-size element in gst pipelines, specifically gvadetect command

CLOSES: intel-retail#29

Signed-off-by: Jim Wang <[email protected]>
  • Loading branch information
jim-wang-intel committed Feb 7, 2024
1 parent b971e6e commit 074adb0
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
3 changes: 2 additions & 1 deletion configs/opencv-ovms/envs/gst.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
COLOR_WIDTH=1920
COLOR_HEIGHT=1080
COLOR_FRAMERATE=15
OCR_SPECIFIED=5
OCR_SPECIFIED=5
BATCH_SIZE=0
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#
# Copyright (C) 2023 Intel Corporation.
# Copyright (C) 2024 Intel Corporation.
#
# SPDX-License-Identifier: Apache-2.0
#
Expand All @@ -16,9 +16,9 @@ else
OUTPUT="${OUTPUT:="! fpsdisplaysink video-sink=fakesink sync=true --verbose"}"
fi

echo "Run yolov5s pipeline"
echo "Run yolov5s pipeline: batch size = $BATCH_SIZE"

gstLaunchCmd="GST_DEBUG=\"GST_TRACER:7\" GST_TRACERS=\"latency_tracer(flags=pipeline,interval=100)\" gst-launch-1.0 $inputsrc ! $DECODE ! gvadetect model-instance-id=odmodel name=detection model=models/yolov5s/FP16-INT8/1/yolov5s.xml model-proc=models/yolov5s/FP16-INT8/1/yolov5s.json threshold=.5 device=$DEVICE $PRE_PROCESS ! $AGGREGATE gvametaconvert name=metaconvert add-empty-results=true ! gvametapublish name=destination file-format=2 file-path=/tmp/results/r$cid_count.jsonl $OUTPUT 2>&1 | tee >/tmp/results/gst-launch_$cid_count.log >(stdbuf -oL sed -n -e 's/^.*current: //p' | stdbuf -oL cut -d , -f 1 > /tmp/results/pipeline$cid_count.log)"
gstLaunchCmd="GST_DEBUG=\"GST_TRACER:7\" GST_TRACERS=\"latency_tracer(flags=pipeline,interval=100)\" gst-launch-1.0 $inputsrc ! $DECODE ! gvadetect batch-size=$BATCH_SIZE model-instance-id=odmodel name=detection model=models/yolov5s/FP16-INT8/1/yolov5s.xml model-proc=models/yolov5s/FP16-INT8/1/yolov5s.json threshold=.5 device=$DEVICE $PRE_PROCESS ! $AGGREGATE gvametaconvert name=metaconvert add-empty-results=true ! gvametapublish name=destination file-format=2 file-path=/tmp/results/r$cid_count.jsonl $OUTPUT 2>&1 | tee >/tmp/results/gst-launch_$cid_count.log >(stdbuf -oL sed -n -e 's/^.*current: //p' | stdbuf -oL cut -d , -f 1 > /tmp/results/pipeline$cid_count.log)"

echo "$gstLaunchCmd"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#
# Copyright (C) 2023 Intel Corporation.
# Copyright (C) 2024 Intel Corporation.
#
# SPDX-License-Identifier: Apache-2.0
#
Expand All @@ -23,8 +23,8 @@ else
OUTPUT="${OUTPUT:="! fpsdisplaysink video-sink=fakesink sync=true --verbose"}"
fi

echo "Run run yolov5s with efficientnet classification pipeline"
gstLaunchCmd="gst-launch-1.0 $inputsrc ! $DECODE ! gvadetect model-instance-id=odmodel name=detection model=/home/pipeline-server/models/yolov5s/FP16-INT8/1/yolov5s.xml model-proc=/home/pipeline-server/models/yolov5s/FP16-INT8/1/yolov5s.json threshold=.5 device=$DEVICE $PRE_PROCESS $DETECTION_OPTIONS ! gvatrack name=tracking tracking-type=zero-term-imageless ! queue max-size-bytes=0 max-size-buffers=0 max-size-time=0 ! gvaclassify model-instance-id=clasifier labels=/home/pipeline-server/models/efficientnet-b0/1/imagenet_2012.txt model=/home/pipeline-server/models/efficientnet-b0/FP32-INT8/1/efficientnet-b0.xml model-proc=/home/pipeline-server/models/efficientnet-b0/efficientnet-b0.json device=$DEVICE inference-region=roi-list name=classification $PRE_PROCESS $CLASSIFICATION_OPTIONS ! gvametaconvert name=metaconvert add-empty-results=true ! gvametapublish name=destination file-format=2 file-path=/tmp/results/r$cid_count.jsonl $OUTPUT 2>&1 | tee >/tmp/results/gst_launch$cid_count.log >(stdbuf -oL sed -n -e 's/^.*current: //p' | stdbuf -oL cut -d , -f 1 > /tmp/results/pipeline$cid_count.log)"
echo "Run run yolov5s with efficientnet classification pipeline: BATCH_SIZE=$BATCH_SIZE"
gstLaunchCmd="gst-launch-1.0 $inputsrc ! $DECODE ! gvadetect batch-size=$BATCH_SIZE model-instance-id=odmodel name=detection model=/home/pipeline-server/models/yolov5s/FP16-INT8/1/yolov5s.xml model-proc=/home/pipeline-server/models/yolov5s/FP16-INT8/1/yolov5s.json threshold=.5 device=$DEVICE $PRE_PROCESS $DETECTION_OPTIONS ! gvatrack name=tracking tracking-type=zero-term-imageless ! queue max-size-bytes=0 max-size-buffers=0 max-size-time=0 ! gvaclassify model-instance-id=clasifier labels=/home/pipeline-server/models/efficientnet-b0/1/imagenet_2012.txt model=/home/pipeline-server/models/efficientnet-b0/FP32-INT8/1/efficientnet-b0.xml model-proc=/home/pipeline-server/models/efficientnet-b0/efficientnet-b0.json device=$DEVICE inference-region=roi-list name=classification $PRE_PROCESS $CLASSIFICATION_OPTIONS ! gvametaconvert name=metaconvert add-empty-results=true ! gvametapublish name=destination file-format=2 file-path=/tmp/results/r$cid_count.jsonl $OUTPUT 2>&1 | tee >/tmp/results/gst_launch$cid_count.log >(stdbuf -oL sed -n -e 's/^.*current: //p' | stdbuf -oL cut -d , -f 1 > /tmp/results/pipeline$cid_count.log)"

echo "$gstLaunchCmd"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#
# Copyright (C) 2023 Intel Corporation.
# Copyright (C) 2024 Intel Corporation.
#
# SPDX-License-Identifier: Apache-2.0
#
Expand All @@ -23,8 +23,8 @@ else
OUTPUT="${OUTPUT:="! fpsdisplaysink video-sink=fakesink sync=true --verbose"}"
fi

echo "Run yolov5s with efficientnet classification, horizontal text detection, and barcode detection pipeline"
gstLaunchCmd="gst-launch-1.0 $inputsrc ! $DECODE $VA_SURFACE ! gvadetect model-instance-id=odmodel name=detection model=/home/pipeline-server/models/yolov5s/FP16-INT8/1/yolov5s.xml model-proc=/home/pipeline-server/models/yolov5s/FP16-INT8/1/yolov5s.json threshold=.5 device=$DEVICE $PRE_PROCESS $DETECTION_OPTIONS gpu-throughput-streams=4 nireq=4 batch-size=1 ! gvatrack name=tracking tracking-type=zero-term-imageless $PARALLEL_PIPELINE ! gvaclassify model-instance-id=clasifier labels=/home/pipeline-server/models/efficientnet-b0/1/imagenet_2012.txt model=/home/pipeline-server/models/efficientnet-b0/FP32-INT8/1/efficientnet-b0.xml model-proc=/home/pipeline-server/models/efficientnet-b0/efficientnet-b0.json reclassify-interval=1 device=$DEVICE inference-region=roi-list name=classification $PRE_PROCESS reclassify_interval=$OCR_RECLASSIFY_INTERVAL batch-size=8 nireq=4 gpu-throughput-streams=1 $PARALLEL_AGGRAGATE ! gvapython class=ObjectFilter module=/home/pipeline-server/extensions/tracked_object_filter.py kwarg=\"{\\\"reclassify_interval\\\": $OCR_RECLASSIFY_INTERVAL}\" name=tracked_object_filter ! gvadetect model-instance-id=ocr threshold=.2 model=/home/pipeline-server/models/horizontal-text-detection-0002/FP16-INT8/1/horizontal-text-detection-0002.xml model-proc=/home/pipeline-server/models/horizontal-text-detection-0002/FP16-INT8/1/horizontal-text-detection-0002.json name=text_detection device=$DEVICE inference-region=roi-list $PRE_PROCESS ! gvainference model-instance-id=ocr2 nireq=4 gpu-throughput-streams=2 batch-size=32 device=$DEVICE model=/home/pipeline-server/models/text-recognition-0012-mod/FP16-INT8/1/text-recognition-0012-mod.xml model-proc=/home/pipeline-server/models/text-recognition-0012-mod/FP16-INT8/1/text-recognition-0012-mod.json inference-region=roi-list name=text_recognition object-class=text ! gvapython class=OCR module=/home/pipeline-server/extensions/OCR_post_processing_0012.py name=ocr_postprocess $AGGREGATE ! gvapython name=barcode class=BarcodeDetection module=/home/pipeline-server/extensions/barcode_nv12_to_gray.py kwarg=\"{\\\"reclassify_interval\\\": $BARCODE_RECLASSIFY_INTERVAL}\" ! gvametaconvert name=metaconvert add-empty-results=true ! gvametapublish name=destination file-format=2 file-path=/tmp/results/r$cid_count.jsonl $OUTPUT 2>&1 | tee >/tmp/results/gst-launch_$cid_count.log >(stdbuf -oL sed -n -e 's/^.*current: //p' | stdbuf -oL cut -d , -f 1 > /tmp/results/pipeline$cid_count.log)"
echo "Run yolov5s with efficientnet classification, horizontal text detection, and barcode detection pipeline: BATCH_SIZE=$BATCH_SIZE"
gstLaunchCmd="gst-launch-1.0 $inputsrc ! $DECODE $VA_SURFACE ! gvadetect batch-size=$BATCH_SIZE model-instance-id=odmodel name=detection model=/home/pipeline-server/models/yolov5s/FP16-INT8/1/yolov5s.xml model-proc=/home/pipeline-server/models/yolov5s/FP16-INT8/1/yolov5s.json threshold=.5 device=$DEVICE $PRE_PROCESS $DETECTION_OPTIONS gpu-throughput-streams=4 nireq=4 batch-size=1 ! gvatrack name=tracking tracking-type=zero-term-imageless $PARALLEL_PIPELINE ! gvaclassify model-instance-id=clasifier labels=/home/pipeline-server/models/efficientnet-b0/1/imagenet_2012.txt model=/home/pipeline-server/models/efficientnet-b0/FP32-INT8/1/efficientnet-b0.xml model-proc=/home/pipeline-server/models/efficientnet-b0/efficientnet-b0.json reclassify-interval=1 device=$DEVICE inference-region=roi-list name=classification $PRE_PROCESS reclassify_interval=$OCR_RECLASSIFY_INTERVAL batch-size=8 nireq=4 gpu-throughput-streams=1 $PARALLEL_AGGRAGATE ! gvapython class=ObjectFilter module=/home/pipeline-server/extensions/tracked_object_filter.py kwarg=\"{\\\"reclassify_interval\\\": $OCR_RECLASSIFY_INTERVAL}\" name=tracked_object_filter ! gvadetect model-instance-id=ocr threshold=.2 model=/home/pipeline-server/models/horizontal-text-detection-0002/FP16-INT8/1/horizontal-text-detection-0002.xml model-proc=/home/pipeline-server/models/horizontal-text-detection-0002/FP16-INT8/1/horizontal-text-detection-0002.json name=text_detection device=$DEVICE inference-region=roi-list $PRE_PROCESS ! gvainference model-instance-id=ocr2 nireq=4 gpu-throughput-streams=2 batch-size=32 device=$DEVICE model=/home/pipeline-server/models/text-recognition-0012-mod/FP16-INT8/1/text-recognition-0012-mod.xml model-proc=/home/pipeline-server/models/text-recognition-0012-mod/FP16-INT8/1/text-recognition-0012-mod.json inference-region=roi-list name=text_recognition object-class=text ! gvapython class=OCR module=/home/pipeline-server/extensions/OCR_post_processing_0012.py name=ocr_postprocess $AGGREGATE ! gvapython name=barcode class=BarcodeDetection module=/home/pipeline-server/extensions/barcode_nv12_to_gray.py kwarg=\"{\\\"reclassify_interval\\\": $BARCODE_RECLASSIFY_INTERVAL}\" ! gvametaconvert name=metaconvert add-empty-results=true ! gvametapublish name=destination file-format=2 file-path=/tmp/results/r$cid_count.jsonl $OUTPUT 2>&1 | tee >/tmp/results/gst-launch_$cid_count.log >(stdbuf -oL sed -n -e 's/^.*current: //p' | stdbuf -oL cut -d , -f 1 > /tmp/results/pipeline$cid_count.log)"

echo "$gstLaunchCmd"

Expand Down
19 changes: 18 additions & 1 deletion configs/opencv-ovms/scripts/run_gst.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
#!/bin/bash
#
# Copyright (C) 2023 Intel Corporation.
# Copyright (C) 2024 Intel Corporation.
#
# SPDX-License-Identifier: Apache-2.0
#

checkBatchSize() {
if [ "$BATCH_SIZE" -lt 0 ]
then
echo "Invalid: BATCH_SIZE should be >= 0: $BATCH_SIZE"
exit 1
elif [ "$BATCH_SIZE" -gt 1024 ]
then
echo "Invalid: BATCH_SIZE should be <= 1024: $BATCH_SIZE"
exit 1
fi
echo "Ok, BATCH_SIZE = $BATCH_SIZE"
}

cid_count="${cid_count:=0}"
cameras="${cameras:=}"
stream_density_mount="${stream_density_mount:=}"
Expand All @@ -15,6 +28,7 @@ COLOR_WIDTH="${COLOR_WIDTH:=1920}"
COLOR_HEIGHT="${COLOR_HEIGHT:=1080}"
COLOR_FRAMERATE="${COLOR_FRAMERATE:=15}"
OCR_SPECIFIED="${OCR_SPECIFIED:=5}"
BATCH_SIZE="${BATCH_SIZE:=0}"

show_help() {
echo "usage: "--pipeline_script_choice" requires an argument yolov5s.sh|yolov5s_effnetb0.sh|yolov5s_full.sh"
Expand Down Expand Up @@ -51,6 +65,8 @@ while :; do

done

checkBatchSize

if [ "$PIPELINE_SCRIPT" != "yolov5s.sh" ] && [ "$PIPELINE_SCRIPT" != "yolov5s_effnetb0.sh" ] && [ "$PIPELINE_SCRIPT" != "yolov5s_full.sh" ]
then
echo "Error on your input: $PIPELINE_SCRIPT"
Expand Down Expand Up @@ -118,6 +134,7 @@ DISPLAY="$DISPLAY" \
RESULT_DIR="/tmp/result" \
DECODE="$DECODE" \
DEVICE="$DEVICE" \
BATCH_SIZE="$BATCH_SIZE" \
PRE_PROCESS="$PRE_PROCESS" \
AGGREGATE="$AGGREGATE" \
OUTPUTFORMAT="$OUTPUTFORMAT" \
Expand Down
1 change: 1 addition & 0 deletions docs_src/dev-tools/environment_variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The table below lists the environment variables (EVs) that can be used as inputs
|`PARALLEL_PIPELINE` | run pipeline in parallel using the tee branch | "", "! tee name=branch ! queue" |
|`PARALLEL_AGGRAGATE` | aggregate parallel pipeline results together, paired use with PARALLEL_PIPELINE | "", "! gvametaaggregate name=aggregate ! gvametaconvert name=metaconvert add-empty-results=true ! gvametapublish name=destination file-format=2 file-path=/tmp/results/r$cid_count.jsonl ! fpsdisplaysink video-sink=fakesink sync=true --verbose branch. ! queue !" |
|`VA_SURFACE` | use video analytics surface from the shared memory if applicable | "", "! "video/x-raw(memory |VASurface)" (GPU only)" |
|`BATCH_SIZE` | number of frames batched together for a single inference to be used in [gvadetect batch-size element](https://dlstreamer.github.io/elements/gvadetect.html) | 0, 1 |

=== "Common EVs"
This list of EVs is common for all profiles.
Expand Down

0 comments on commit 074adb0

Please sign in to comment.