DeepStream 3D 动作识别应用#

示例应用程序 deepstream-3d-action-recognition 位于 app/sample_apps/deepstream-3d-action-recognition 供您参考。此示例演示了基于序列批处理的 3D 或 2D 模型推理流水线,用于动作识别。下图显示了此参考应用的架构。

DeepStream 3D Action Recognition Application Architecture

Gst-nvdspreprocess 插件重新处理 Gst-nvinfer 插件的输入张量。Gst-nvdspreprocess 加载 custom_sequence_preprocess lib (子文件夹) 以执行时间序列批处理和 ROI 空间批处理。它将预处理的批处理张量缓冲区传递到下游插件 Gst-nvinfer 以进行推理。此应用程序探测张量数据和动作分类结果,将其转换为显示元数据以在屏幕上打印。此 3D/2D 模型由 NVIDIA TAO 工具包预训练。3D 模型具有 NCDHW (NCSHW) 输入,2D 模型具有 NSHW 形状。

N: Max batch size of total number of ROIs in all streams, value > 0.
C: Channel numbers, must be 3.
D/S: sequence length of consecutive frames, value > 1
H: height, value > 0
W: width, value > 0
2D S: channels x sequence_length, reshaped from [C, D]

自定义序列预处理库:libnvds_custom_sequence_preprocess.so 也位于 sources/apps/sample_apps/deepstream-3d-action-recognition/custom_sequence_preprocess,用于演示如何使用 Gst-nvdspreprocess 插件实现序列批处理和预处理方法。此自定义库标准化每个传入的 ROI 裁剪图像,并将数据累积到缓冲区序列中以进行时间批处理。当时间批处理准备就绪时,它继续对多 ROI 和多流执行空间批处理。最后,它将时间和空间批处理的缓冲区(张量)返回给 Gst-nvdspreprocess 插件,该插件会将缓冲区作为预处理输入元数据附加并传递到下游 Gst-nvinfer 插件以进行推理。

入门#

先决条件#

  • 转到文件夹 sources/apps/sample_apps/deepstream-3d-action-recognition

  • 从 NGC https://ngc.nvidia.com/catalog/models/nvidia:tao:actionrecognitionnet (版本 5) 搜索并下载基于 3D 和 2D RGB 的 tao_iva_action_recognition_pretrained 模型

    • resnet18_3d_rgb_hmdb5_32

    • resnet18_2d_rgb_hmdb5_32

  • 这些模型支持以下类别:push; fall_floor; walk; run; ride_bike

  • 在动作识别配置文件 deepstream_action_recognition_config.txt 中更新源流 uri-list

    uri-list=file:///path/to/sample_action1.mov;file:///path/to/sample_action2.mov;file:///path/to/sample_action3.mov;file:///path/to/sample_action4.mov;
    
  • 导出 DISPLAY 环境变量以进行正确的显示。例如 export DISPLAY=:0.0

运行 3D 动作识别示例#

  • 确保在 deepstream_action_recognition_config.txt 中启用 3D 预处理配置和 3D 推理配置。

    # Enable 3D preprocess and inference
    preprocess-config=config_preprocess_3d_custom.txt
    infer-config=config_infer_primary_3d_action.txt
    
  • 运行以下命令

    $ deepstream-3d-action-recognition -c deepstream_action_recognition_config.txt
    
  • 使用 DS-Triton 运行,更新应用程序配置文件 deepstream_triton_action_recognition_config.txt

    preprocess-config=config_preprocess_3d_custom.txt
    triton-infer-config=config_triton_infer_primary_3d_action.txt
    
  • 使用 DS-Triton 运行 3D 测试

    $ ./deepstream-3d-action-recognition -c deepstream_triton_action_recognition_config.txt
    

    查看 sources/TritonOnnxYolo/README 以了解有关如何在 CAPI 和 gRPC 之间切换动作识别 DS-Triton 测试的更多详细信息。

运行 2D 动作识别示例#

  • 确保在 deepstream_action_recognition_config.txt 中启用 2D 预处理配置和 2D 推理配置。

    # Enable 2D preprocess and inference
    preprocess-config=config_preprocess_2d_custom.txt
    infer-config=config_infer_primary_2d_action.txt
    
  • 运行以下命令

    $ deepstream-3d-action-recognition -c deepstream_action_recognition_config.txt
    
  • 使用 DS-Triton 运行,更新应用程序配置文件 deepstream_triton_action_recognition_config.txt

    preprocess-config=config_preprocess_2d_custom.txt
    triton-infer-config=config_triton_infer_primary_2d_action.txt
    
  • 使用 DS-Triton 运行 2D 测试

    $ ./deepstream-3d-action-recognition -c deepstream_triton_action_recognition_config.txt
    

    查看 sources/TritonOnnxYolo/README 以了解有关如何在 CAPI 和 gRPC 之间切换动作识别 DS-Triton 测试的更多详细信息。

DeepStream 3D 动作识别应用配置规范#

deepstream-3d-action-recognition [action-recognition] 群组设置#

下表演示了 deepstream_action_recognition_config.txt 的群组设置示例。

3D 动作识别支持的设置#

属性

含义

类型和范围

示例

uri-list

源视频文件或流列表

分号分隔的字符串列表

file:///path/to/sample_action1.mp4;file:///path/to/sample_action2.mp4;

display-sync

指示是否在时间戳上显示同步

布尔值

display-sync=1

preprocess-config

Gst-nvdspreprocess 插件配置文件路径

字符串

preprocess-config=config_preprocess_3d_custom.txt

infer-config

Gst-nvinfer 插件配置文件路径

字符串

infer-config=config_infer_primary_2d_action.txt

muxer-height

Gst-nvstreammux 高度

无符号整数

muxer-height=720

muxer-width

Gst-nvstreammux 宽度

无符号整数

muxer-width=1280

muxer-batch-timeout

Gst-nvstreammux 批处理推送超时(微秒)

无符号整数

muxer-batch-timeout=40000

tiler-height

Gst-nvmultistreamtiler 高度

无符号整数

tiler-height=720

tiler-width

Gst-nvmultistreamtiler 宽度

无符号整数

tiler-width=1280

debug

日志打印调试级别

整数,0:禁用。1:调试。2:详细

debug=0

enable-fps

指示是否在屏幕上打印 fps

布尔值

enable-fps=1

gst-nvdspreprocess 的自定义序列预处理库用户设置 [user-configs]#

下表演示了 libnvds_custom_sequence_preprocess.soconfig_preprocess_3d_custom.txt 设置示例。

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

属性

含义

类型和范围

示例

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

用于动作识别的自定义 lib`gst-nvdspreprocess` 设置#

  • 您需要将输入顺序设置为 CUSTOM network-input-order=2 以用于此自定义序列预处理库。

  • 3D 模型 NCDHW(NCSHW) 需要具有 5 维形状的 network-input-shape。例如

       network-input-shape= 4;3;32;224;224
    
    It means max_batch_size: 4, channels 3, sequence_len: 32, height 224, width 224.
    
  • 2D 模型 NSHW 需要具有 4 维形状的 network-input-shape。例如

       network-input-shape= 4;96;224;224
    
    It means max_batch_size: 4, channels 3, sequence_len: 32, height 224, width 224. where 96 = channels x sequence_len.
    
  • 假设传入帧编号为 1、2、3、4、5、6、7、8、9、10、11、12、13、14、15… 当 subsample=1 时,预处理自定义库将拾取帧编号:1、3、5、7、9… 依次进行预处理,并将其作为下一步传递给推理。

  • 假设与上述相同的传入帧编号,例如,当 subsample=0, stride=1 时,2 个连续的滑动序列是

    Batch A: [1,2,3,4,5...]
    Batch B: [2,3,4,5,6...]
    

    subsample=0, stride=2 时,2 个连续的滑动序列是

    Batch A: [1,2,3,4,5...]
    Batch B: [3,4,5,6,7...]
    

    subsample=1, stride=2 时,首先执行子采样,滑动序列位于子采样结果之上。子采样后的处理帧编号为:1、3、5、7、9、11、13、15、17、19… 其上的连续滑动序列是

    Batch A: [1,3,5,7,9...]
    Batch B: [5,7,9,11,13...] # 1st frame sliding from frame 1 of Batch A to frame 5
    Batch C: [9,11,13,15,17...] # 1st frame sliding from frame 5 of Batch C to frame 9
    

下图显示了具有不同子采样和步幅设置的帧批次。

3D Action Sequence batching

从源代码构建自定义序列预处理库和应用程序#

  • 转到文件夹 sources/apps/sample_apps/deepstream-3d-action-recognition

  • 运行以下命令

    $ make
    $ make install
    
  • 检查源代码和注释,了解其他顺序格式的实现,例如 NSCHW (NDCHW)。