Gst-nvdspreprocess (Alpha)#

Gst-nvdspreprocess 插件是一个可定制的插件,它为输入流上的预处理提供了一个自定义库接口。每个流都可以有自己的预处理需求。(例如,每个流的 ROI - 感兴趣区域处理)具有相同预处理需求的流被分组并一起处理。这些需求可以通过配置文件指定。有关更多详细信息,请参阅下面的Gst-nvdspreprocess 文件配置规范部分。

默认插件实现提供了两个功能。

  1. 具有预定义 ROI(感兴趣区域)的流按照网络推理要求进行缩放和格式转换。每个流的 ROI 在配置文件中指定。

  2. 它从缩放和转换后的 ROI 准备一个原始张量。它通过用户元数据传递到下游插件。下游插件可以访问此张量以进行推理。

插件提供的默认自定义库 (nvdspreprocess_lib) 实现了这些功能。它包含组转换(每个组的缩放和转换功能)和 2d 卷积 NCHW/NHWC 模型的张量准备函数。用户可以根据需求使用组转换函数和张量准备函数实现自己的库。

此插件可以在两种模式下运行:PGIE 和 SGIE。PGIE 模式下的预处理用于处理我们要执行主要推理的给定 ROI/帧。SGIE 模式下的预处理用于处理我们要执行辅助推理的给定 ROI/帧中检测到的对象。

Gst-nvdspreprocess

输入和输出#

  • 输入

    • 输入视频 Gst 缓冲区

    • 元数据 (NvDsBatchMeta)

  • 控制参数

    • config-file

  • 输出

    • 输出视频 Gst 缓冲区

    • 元数据 (NvDsBatchMeta) + 批处理级别的用户元数据 (NvDsPreProcessBatchMeta)

功能#

下表总结了插件的功能。

Gst-nvdspreprocess 功能#

功能

描述

发布版本

每个流/流组 ROI 处理

在组内具有相同处理算法的预定义 ROI 上进行处理

DS 6.0

对完整帧/ROI 进行处理

在 [group-*] 内启用 process-on-roi 以对 ROI 进行处理

DS 6.0

自定义库接口

使用组转换和张量准备函数的自定义功能

DS 6.0

自定义组转换函数

对于每个组,可以从自定义库提供单独的自定义转换函数(例如,缩放和转换)

DS 6.0

自定义张量准备函数

来自自定义库的自定义张量准备函数,用于从已转换的 ROI/完整帧准备原始张量

DS 6.0

在批处理级别附加用户元数据

具有原始张量以及缩放和转换后的 ROI 的用户元数据 (NvDsPreProcessBatchMeta)

DS 6.0

支持 SGIE 模式

支持处理 PGIE 模型检测到的对象

DS 6.2

自定义库接口#

  • custom_transform => 用于为不同流组实现自定义转换的接口。默认实现提供了配置文件中指定的 ROI 的组转换功能。

  • custom_tensor_function => 用于提供自定义张量准备函数的接口。默认实现从转换后的 ROI 准备原始张量

Gst-nvdspreprocess 文件配置规范#

Gst-nvdspreprocess 配置文件使用 https://specifications.freedesktop.org/desktop-entry-spec/latest 中描述的“Key File”格式。请参阅 /opt/nvidia/deepstream/deepstream/sources/gst-plugins/gst-nvdspreprocess/config_preprocess.txt 中的 config_preprocess.txt[property] 组配置插件的常规行为。 [group-<id>] 组为一组具有来自自定义库的 src-idscustom-input-transformation-function 的流配置 ROI/完整帧。 [user-configs] 组配置自定义库所需的参数,这些参数通过 <string,string> 键值对的映射传递到自定义库。自定义库需要相应地解析这些值。

以下两个表分别描述了 [property] 组和 [group-<id>] 组支持的键。

Gst-nvdspreprocess 属性组支持的键#

属性

含义

类型和范围

示例

enable

如果设置,则启用插件,否则处于直通模式

布尔值

enable=1

unique-id

唯一标识此元素生成的元数据

整数,| 0 到 4,294,967,295

unique-id=1

gpu-id

用于预处理的 GPU 设备 ID(仅限 dGPU)

整数,0-4,294,967,295

gpu-id=1

process-on-frame

预处理模式 1=PGIE 模式 0=SGIE 模式

布尔值

process-on-frame=1

target-unique-ids

为其准备张量的组件 gie-id 列表

分号分隔的整数 (gie-ids) 值数组 >=0

target-unique-ids=3;4;5

operate-on-gie-id

要预处理其元数据的唯一 gie-id(如果启用 process-on-frame,则忽略)

整数,0 到 4,294,967,295

operate-on-gie-id=1

network-input-order

网络输入层的顺序

整数 0=NCHW 1=NHWC 2=CUSTOM

network-input-order=0

network-input-shape

根据 network-input-order 的网络输入层张量形状

分号分隔的整数值数组 > 0

network-input-shape=60;3;368;640

maintain-aspect-ratio

如果设置,则在缩放时保持宽高比

布尔值

maintain-aspect-ratio

symmetric-padding

如果设置,则对称填充(如果禁用 maintain-aspect-ratio,则忽略)

布尔值

symmetric-padding

processing-width

ROI 缩放到的宽度

整数>0

processing-width=640

processing-height

ROI 缩放到的高度

整数>0

processing-height=368

scaling-buf-pool-size

缩放缓冲区池的大小

整数>0

scaling-buf-pool-size=6

tensor-buf-pool-size

张量缓冲区池的大小

整数>0

tensor-buf-pool-size=6

network-color-format

模型的颜色格式

整数 0=RGB 1=BGR 2=GRAY

network-color-format=0

tensor-data-type

推理的数据格式

整数 0=FP32 1=UINT8 2=INT8 3=UINT32 4=INT32 5=FP16

tensor-data-type=0

tensor-name

网络输入层名称

字符串

tensor-name=Input_1

scaling-pool-memory-type

缩放缓冲区池的内存类型

整数 0=NVBUF_MEM_DEFAULT 1=NVBUF_MEM_CUDA_PINNED 2=NVBUF_MEM_CUDA_DEVICE 3=NVBUF_MEM_CUDA_UNIFIED 4=NVBUF_MEM_SURFACE_ARRAY

scaling-pool-memory-type=2

scaling-pool-compute-hw

缩放的计算硬件类型

整数 0=NvBufSurfTransformCompute_Default 1=NvBufSurfTransformCompute_GPU 2=NvBufSurfTransformCompute_VIC

scaling-pool-compute-hw=0

scaling-filter

缩放插值方法

整数 0=NvBufSurfTransformInter_Nearest 1=NvBufSurfTransformInter_Bilinear 2=NvBufSurfTransformInter_Algo 3=NvBufSurfTransformInter_Algo2 4=NvBufSurfTransformInter_Algo3 5=NvBufSurfTransformInter_Algo4 6=NvBufSurfTransformInter_Default

scaling-filter=0

custom-lib-path

自定义库 .so 文件的路径

字符串

custom-lib-path=/opt/nvidia/deepstream/deepstream/lib/gst-plugins/libcustom2d_preprocess.so

custom-tensor-preparation-function

来自自定义库的张量准备函数的名称

字符串

custom-tensor-preparation-function=CustomTensorPreparation

Gst-nvdspreprocess group-<id> 组支持的键#

属性

含义

类型和范围

示例

src-ids

此组应用到的源 ID

分号分隔的整数值数组 >=0

src-ids=0;1;2;3

custom-input-transformation-function

来自自定义库的自定义输入转换函数的名称

字符串

custom-input-transformation-function=CustomTransformation

process-on-roi

如果启用,则对 ROI 进行处理,否则对完整帧进行处理(如果禁用 process-on-frame,则忽略)

布尔值

process-on-roi=1

roi-params-src-<id>

源 <id> 的 ROI 坐标。对于每个 ROI,如果启用 process-on-roi,则指定定义 ROI 的 左;上;宽;高。

分号分隔的整数值数组 >=0

roi-params-0=0;540;900;500;960;0;900;500

operate-on-class-ids

预处理仅对属于这些 class-id 的对象执行(如果启用 process-on-frame,则忽略)

分号分隔的整数 (class-ids) 值数组 >=0

operate-on-class-ids=0;1

process-on-all-objects

如果启用,则处理所有对象,否则处理 ROI 内的对象(如果启用 process-on-frame,则忽略)

布尔值

process-on-all-objects=1

draw-roi

如果启用,则在显示屏上绘制指定的 roi,否则不绘制 roi

布尔值

draw-roi=1

roi-color

要显示的 roi 的颜色

分号分隔的颜色分量值 R;G;B;A

roi_color=0;1;1;1

input-object-min-width

要处理的对象的最小宽度

整数,≥0

input-object-min-width=100

input-object-min-height

要处理的对象的最小高度

整数,≥0

input-object-min-height=100

input-object-max-width

要处理的对象的最大宽度

整数,≥0

input-object-max-width=500

input-object-max-height

要处理的对象的最大高度

整数,≥0

input-object-max-height=500

下表描述了自定义库 nvdspreprocess_lib[user-configs] 组支持的键。

Gst-nvdspreprocess user-configs 组支持的键#

属性

含义

类型和范围

示例

pixel-normalization-factor

像素缩放的因子

浮点数

pixel-normalization-factor=­0.031

offsets

要从每个像素中减去的颜色分量的平均值数组。数组长度必须等于帧中颜色分量的数量。插件将平均值乘以 pixel-normalization-factor

分号分隔的浮点数值数组 ≥0

offsets=77.5;21.2;11.8

mean-file

平均数据文件的路径名 (PPM 格式)

字符串

mean-file=/home/ubuntu/model_meanfile.ppm

下表描述了自定义库 libnvds_custom_sequence_preprocess.so[user-configs] 组支持的键。该库在 deepstream-3d-action-recognition 示例应用程序中使用。

自定义序列预处理的用户配置属性#

属性

含义

类型和范围

示例

channel-scale-factors

每个通道的比例因子列表

分号分隔的浮点数数组

channel-scale-factors= 0.007843137;0.007843137;0.007843137

channel-mean-offsets

每个通道的数据平均偏移量

分号分隔的浮点数数组

channel-mean-offsets=127.5;127.5;127.5

stride

每个批处理序列的序列滑动步幅

无符号整数,值 >= 1

stride=1

subsample

每个序列中推理图像的子采样率

无符号整数,值 >= 0

subsample=0

Gst 属性#

下表描述了 Gst-nvdspreprocess 插件的 Gst 属性。

Gst-nvspreprocess gst 属性#

属性

含义

类型和范围

示例注释

unique-id

唯一标识此元素生成的元数据

整数,| 0 到 4,294,967,295

unique-id=1

gpu-id

用于预处理的 GPU 设备 ID(仅限 dGPU)

整数,0-4,294,967,295

gpu-id=1

config-file

Gst-nvdspreprocess 元素的配置文件路径

字符串

config-file=config_preprocess.txt

enable

启用 gst-nvdspreprocess 插件或设置为直通模式

布尔值

enable=1

process-on-frame

预处理模式 1=PGIE 模式 0=SGIE 模式

布尔值

process-on-frame=1

target-unique-ids

为其准备张量的组件 gie-id 列表

分号分隔的整数 (gie-ids) 值数组 >=0

target-unique-ids=3;4;5

operate-on-gie-id

要预处理其元数据的唯一 gie-id(如果启用 process-on-frame,则忽略)

整数,0 到 4,294,967,295

operate-on-gie-id=1

示例管线#

下面是一些示例管线,用于演示预处理插件的用法,请设置适当的配置文件和库路径。

单流 PGIE 模式下的预处理 (dGPU)

gst-launch-1.0 filesrc location = /opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h264.mp4 ! qtdemux ! \
h264parse ! nvv4l2decoder ! m.sink_0 nvstreammux name=m batch-size=1 width=1920 height=1080 ! nvvideoconvert ! \
nvdspreprocess config-file= /opt/nvidia/deepstream/deepstream/sources/gst-plugins/gst-nvdspreprocess/config_preprocess.txt  ! \
nvinfer config-file-path= /opt/nvidia/deepstream/deepstream/samples/configs/deepstream-app/config_infer_primary.txt \
input-tensor-meta=1 batch-size=7  ! nvmultistreamtiler width=1920 height=1080 ! nvvideoconvert ! nvdsosd ! nveglglessink

单流 PGIE 模式下的预处理 (Jetson)

gst-launch-1.0 filesrc location = /opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h264.mp4 ! qtdemux ! \
h264parse ! nvv4l2decoder ! m.sink_0 nvstreammux name=m batch-size=1 width=1920 height=1080 ! nvvideoconvert ! \
nvdspreprocess config-file= /opt/nvidia/deepstream/deepstream/sources/gst-plugins/gst-nvdspreprocess/config_preprocess.txt  ! \
nvinfer config-file-path= /opt/nvidia/deepstream/deepstream/samples/configs/deepstream-app/config_infer_primary.txt \
input-tensor-meta=1 batch-size=2 ! nvmultistreamtiler width=1920 height=1080 ! nvvideoconvert ! nvdsosd ! nv3dsink

多流 PGIE 模式下的预处理 (dGPU)

gst-launch-1.0 filesrc location = /opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h264.mp4 ! qtdemux ! \
h264parse ! nvv4l2decoder ! m.sink_0 nvstreammux name=m batch-size=4 width=1920 height=1080 ! nvvideoconvert ! \
nvdspreprocess config-file= /opt/nvidia/deepstream/deepstream/sources/gst-plugins/gst-nvdspreprocess/config_preprocess.txt  ! \
nvinfer config-file-path= /opt/nvidia/deepstream/deepstream/samples/configs/deepstream-app/config_infer_primary.txt \
input-tensor-meta=1 batch-size=8 ! nvmultistreamtiler width=1920 height=1080 ! nvvideoconvert ! nvdsosd ! nveglglessink \
filesrc location = /opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h264.mp4 ! qtdemux ! h264parse ! nvv4l2decoder ! \
m.sink_1 filesrc location = /opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h264.mp4 ! qtdemux ! h264parse ! \
nvv4l2decoder ! m.sink_2 filesrc location = /opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h264.mp4 ! qtdemux ! \
h264parse ! nvv4l2decoder ! m.sink_3

多流 PGIE 模式下的预处理 (Jetson)

gst-launch-1.0 filesrc location = /opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h264.mp4 ! qtdemux ! \
h264parse ! nvv4l2decoder ! m.sink_0 nvstreammux name=m batch-size=4 width=1920 height=1080 ! nvvideoconvert ! \
nvdspreprocess config-file= /opt/nvidia/deepstream/deepstream/sources/gst-plugins/gst-nvdspreprocess/config_preprocess.txt  ! \
nvinfer config-file-path= /opt/nvidia/deepstream/deepstream/samples/configs/deepstream-app/config_infer_primary.txt \
input-tensor-meta=1 batch-size=8 ! nvmultistreamtiler width=1920 height=1080 ! nvvideoconvert ! nvdsosd ! nv3dsink \
filesrc location = /opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h264.mp4 ! qtdemux ! h264parse ! nvv4l2decoder ! \
m.sink_1 filesrc location = /opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h264.mp4 ! qtdemux ! h264parse ! \
nvv4l2decoder ! m.sink_2 filesrc location = /opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h264.mp4 ! qtdemux ! \
h264parse ! nvv4l2decoder ! m.sink_3

单流 PGIE 和 SGIE 模式下的预处理 (dGPU)

gst-launch-1.0 filesrc location = /opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h264.mp4 ! qtdemux ! \
h264parse ! nvv4l2decoder ! m.sink_0 nvstreammux name=m batch-size=1 width=1920 height=1080 ! nvvideoconvert ! \
nvdspreprocess config-file= /opt/nvidia/deepstream/deepstream/sources/gst-plugins/gst-nvdspreprocess/config_preprocess.txt  ! \
nvinfer config-file-path= /opt/nvidia/deepstream/deepstream/samples/configs/deepstream-app/config_infer_primary.txt unique-id=1 \
batch-size=2 input-tensor-meta=1 ! nvdspreprocess config-file= /opt/nvidia/deepstream/deepstream/sources/gst-plugins/gst-nvdspreprocess/config_preprocess_sgie.txt ! \
nvinfer config-file-path= /opt/nvidia/deepstream/deepstream/samples/configs/deepstream-app/config_infer_secondary_vehicletypes.txt input-tensor-meta=1 unique-id=3 ! \
nvmultistreamtiler width=1920 height=1080 ! nvvideoconvert ! nvdsosd ! nveglglessink

单流 PGIE 和 SGIE 模式下的预处理 (Jetson)

gst-launch-1.0 filesrc location = /opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h264.mp4 ! qtdemux ! \
h264parse ! nvv4l2decoder ! m.sink_0 nvstreammux name=m batch-size=1 width=1920 height=1080 ! nvvideoconvert ! \
nvdspreprocess config-file= /opt/nvidia/deepstream/deepstream/sources/gst-plugins/gst-nvdspreprocess/config_preprocess.txt  ! \
nvinfer config-file-path= /opt/nvidia/deepstream/deepstream/samples/configs/deepstream-app/config_infer_primary.txt unique-id=1 \
batch-size=2 input-tensor-meta=1 ! nvdspreprocess config-file= /opt/nvidia/deepstream/deepstream/sources/gst-plugins/gst-nvdspreprocess/config_preprocess_sgie.txt ! \
nvinfer config-file-path= /opt/nvidia/deepstream/deepstream/samples/configs/deepstream-app/config_infer_secondary_vehicletypes.txt input-tensor-meta=1 unique-id=3 ! \
nvmultistreamtiler width=1920 height=1080 ! nvvideoconvert ! nvdsosd ! nv3dsink

多流 PGIE 和 SGIE 模式下的预处理 (dGPU)

gst-launch-1.0 filesrc location = /opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h264.mp4 ! qtdemux ! \
h264parse ! nvv4l2decoder ! m.sink_0 nvstreammux name=m batch-size=1 width=1920 height=1080 ! nvvideoconvert ! \
nvdspreprocess config-file= /opt/nvidia/deepstream/deepstream/sources/gst-plugins/gst-nvdspreprocess/config_preprocess.txt  ! \
nvinfer config-file-path= /opt/nvidia/deepstream/deepstream/samples/configs/deepstream-app/config_infer_primary.txt unique-id=1 \
batch-size=8 input-tensor-meta=1 ! nvdspreprocess config-file= /opt/nvidia/deepstream/deepstream/sources/gst-plugins/gst-nvdspreprocess/config_preprocess_sgie.txt ! \
nvinfer config-file-path= /opt/nvidia/deepstream/deepstream/samples/configs/deepstream-app/config_infer_secondary_vehicletypes.txt input-tensor-meta=1 unique-id=3 ! \
nvmultistreamtiler width=1920 height=1080 ! nvvideoconvert ! nvdsosd ! nveglglessink filesrc location = /opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h264.mp4 ! \
qtdemux ! h264parse ! nvv4l2decoder ! m.sink_1 filesrc location = /opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h264.mp4 ! qtdemux ! h264parse ! nvv4l2decoder ! \
m.sink_2 filesrc location = /opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h264.mp4 ! qtdemux ! h264parse ! nvv4l2decoder ! m.sink_3

多流 PGIE 和 SGIE 模式下的预处理 (Jetson)

gst-launch-1.0 filesrc location = /opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h264.mp4 ! qtdemux ! \
h264parse ! nvv4l2decoder ! m.sink_0 nvstreammux name=m batch-size=1 width=1920 height=1080 ! nvvideoconvert ! \
nvdspreprocess config-file= /opt/nvidia/deepstream/deepstream/sources/gst-plugins/gst-nvdspreprocess/config_preprocess.txt  ! \
nvinfer config-file-path= /opt/nvidia/deepstream/deepstream/samples/configs/deepstream-app/config_infer_primary.txt unique-id=1 \
batch-size=8 input-tensor-meta=1 ! nvdspreprocess config-file= /opt/nvidia/deepstream/deepstream/sources/gst-plugins/gst-nvdspreprocess/config_preprocess_sgie.txt ! \
nvinfer config-file-path= /opt/nvidia/deepstream/deepstream/samples/configs/deepstream-app/config_infer_secondary_vehicletypes.txt input-tensor-meta=1 unique-id=3 ! \
nvmultistreamtiler width=1920 height=1080 ! nvvideoconvert ! nvdsosd ! nv3dsink filesrc location = /opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h264.mp4 ! \
qtdemux ! h264parse ! nvv4l2decoder ! m.sink_1 filesrc location = /opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h264.mp4 ! qtdemux ! h264parse ! nvv4l2decoder ! \
m.sink_2 filesrc location = /opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h264.mp4 ! qtdemux ! h264parse ! nvv4l2decoder ! m.sink_3