deepstream-sop
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDeepStream SOP Inference Microservice Skill
DeepStream SOP Inference Microservice Skill
This skill guides AI coding assistants in building, extending, and debugging the
NVIDIA DeepStream SOP (Standard Operating Procedure) Inference Microservice —
a GPU-accelerated pipeline for temporal action detection and VLM-based SOP compliance
monitoring on industrial video feeds.
Reference repository: https://github.com/NVIDIA/sop-monitoring-blueprints/tree/main/microservices/sop-inference-bp
Local reference code: directory (from a local clone of the repository)
sop-inference-bp/本skill指导AI编码助手构建、扩展和调试
NVIDIA DeepStream SOP(标准操作流程)推理微服务——
一款用于工业视频流的时序动作检测和基于VLM的SOP合规监控的GPU加速流水线。
参考仓库:https://github.com/NVIDIA/sop-monitoring-blueprints/tree/main/microservices/sop-inference-bp
本地参考代码:目录(仓库本地克隆后的路径)
sop-inference-bp/Models
模型
Model-agnostic at both inference stages — swap via env var (and Triton dir for GEBD).
| Stage | Role | Model class | Default | Swap via |
|---|---|---|---|---|
| Stage 1 (CV) | Per-frame boundary scoring → chunk segmentation | Generic Event Boundary Detection (GEBD) | DDM (MCG-NJU/DDM) via Triton Python backend | Replace |
| Stage 3 (VLM) | Per-chunk action classification | Vision-language model via vLLM | Cosmos Reason 1 7B (Reason 2 also supported) | Set |
"GEBD" = swappable Stage-1 slot; "DDM" = the default architecture (terms used interchangeably).
Chunking is selectable per request (§ 2): default uses GEBD; produces fixed-length chunks and bypasses Stage-1 GEBD (§ 3, § 6). DDM temporal window is configurable via / (§ 4, § 5), with optional TensorRT (§ 5).
ddm-netuniformFRAMES_PER_SIDESEQUENCE_BATCH两个推理阶段均支持模型无关性——通过环境变量(GEBD模型还需配合Triton目录)替换模型。
| 阶段 | 作用 | 模型类别 | 默认模型 | 替换方式 |
|---|---|---|---|---|
| 阶段1(计算机视觉) | 逐帧边界评分 → 视频块分割 | 通用事件边界检测(GEBD) | DDM(MCG-NJU/DDM),通过Triton Python后端部署 | 替换 |
| 阶段3(视觉语言模型) | 视频块动作分类 | 基于vLLM的视觉语言模型 | Cosmos Reason 1 7B(也支持Reason 2) | 将 |
"GEBD"指可替换的阶段1模块;"DDM"是默认架构(两个术语可互换使用)。
视频块分割方式可按请求选择(第2节):默认的使用GEBD;方式生成固定长度的视频块,且绕过阶段1的GEBD(第3、6节)。DDM的时间窗口可通过/配置(第4、5节),还可选择启用TensorRT(第5节)。
ddm-netuniformFRAMES_PER_SIDESEQUENCE_BATCHArchitecture Overview
架构概述
Runs in a Docker container () alongside a Kafka container. Full diagram: .
nvds-action-sopreferences/sop_architecture.svgData flow through the 4-stage pipeline (per-request):
SOPVideoProcessorInput Sources Docker Container: nvds-action-sop
───────────── ──────────────────────────────────────────────────
Video Files ──┐ FastAPI Server (port 8300)
RTSP Streams ─┤── base64/ ├─ /v1/chat/completions → SOPProcessManager
Basler Camera ┘ file/rtsp/ │
camera │ ModelInitializer: VLM first, then DDM dummy pipeline
│ 4 Thread Pools: cv(32), clip(32), vlm(64), vlm_req(64)
│
▼ SOPVideoProcessor (per-request)
┌────────────────────────────────────────────────┐
│ Stage 1: DeepStream Pipeline (GPU) │
│ Source → nvstreammux → tee1 │
│ ├─[inference] queue1 → nvdspreprocess │
│ │ → nvinferserver (Triton CAPI + DDM) │
│ │ → InferOutputTensorParser → score_queue │
│ ├─[frames] queue3 → nvvideoconvert │
│ │ → capsfilter → appsink │
│ │ → DecodedFrameRetriever → frame_queue │
│ └─[RTSP out] queue → convert → H.264 enc │ (optional, § 18)
│ → rtppay → udpsink → RTSPServer (§ 18) │ opt-in only
│ │ boundary scores │
│ ▼ │
│ Stage 2: Clip Post-Process │
│ Boundary detection → chunk segmentation │
│ │ video frames + timestamps │
│ ▼ │
│ Stage 3: VLM Inference │
│ Embedded vLLM (Cosmos Reason 1/2) │
│ Frame sampling at VLM_FPS → classification │
│ │ action labels │
│ ▼ │
│ Stage 4: SOP Checker │
│ Sequence validation → missing/misordered │
│ │ chunk results │
│ ▼ │
│ final_queue │
└────────────────────────────────────────────────┘
│
Output ▼
────── ┌─────────────────┐
SSE Stream (chat.completion.chunk) │ Kafka Messages │
Non-streaming (chat.completion) │ (JSON/Protobuf) │
Prometheus metrics (/v1/metrics) └────────┬────────┘
▼
Docker Container: kafka
(apache/kafka:3.7.0)服务运行在Docker容器()中,与Kafka容器协同工作。完整架构图:。
nvds-action-sopreferences/sop_architecture.svg4阶段流水线的数据流(单请求维度):
SOPVideoProcessor输入源 Docker容器: nvds-action-sop
───────────── ──────────────────────────────────────────────────
视频文件 ──┐ FastAPI服务器(端口8300)
RTSP流 ─┤── base64/ ├─ /v1/chat/completions → SOPProcessManager
Basler相机 ┘ file/rtsp/ │
camera │ ModelInitializer:先预热VLM,再启动DDM虚拟流水线
│ 4个线程池: cv(32), clip(32), vlm(64), vlm_req(64)
│
▼ SOPVideoProcessor(单请求实例)
┌────────────────────────────────────────────────┐
│ 阶段1: DeepStream流水线(GPU加速) │
│ 源 → nvstreammux → tee1 │
│ ├─[推理] queue1 → nvdspreprocess │
│ │ → nvinferserver(Triton CAPI + DDM) │
│ │ → InferOutputTensorParser → score_queue │
│ ├─[帧数据] queue3 → nvvideoconvert │
│ │ → capsfilter → appsink │
│ │ → DecodedFrameRetriever → frame_queue │
│ └─[RTSP输出] queue → convert → H.264 enc │ (可选,第18节)
│ → rtppay → udpsink → RTSPServer(第18节) │ 仅按需启用
│ │ 边界评分 │
│ ▼ │
│ 阶段2: 视频块后处理 │
│ 边界检测 → 视频块分段 │
│ │ 视频帧 + 时间戳 │
│ ▼ │
│ 阶段3: VLM推理 │
│ 内置vLLM(Cosmos Reason 1/2) │
│ 按VLM_FPS采样帧数据 → 分类 │
│ │ 动作标签 │
│ ▼ │
│ 阶段4: SOP检查器 │
│ 序列验证 → 检测缺失/乱序步骤 │
│ │ 视频块结果 │
│ ▼ │
│ final_queue │
└────────────────────────────────────────────────┘
│
输出 ▼
────── ┌─────────────────┐
SSE流(chat.completion.chunk) │ Kafka消息 │
非流式输出(chat.completion) │ (JSON/Protobuf格式) │
Prometheus指标(/v1/metrics) └────────┬────────┘
▼
Docker容器: kafka
(apache/kafka:3.7.0)Section Index
章节索引
Each section is a standalone file in — load only what your task needs.
references/| § | File | Responsibility |
|---|---|---|
| 1 | | FastAPI endpoints, server init, Prometheus metrics |
| 2 | | Request/response Pydantic models ( |
| 3 | | DeepStream pyservicemaker pipeline, tensor parser, dummy pipeline |
| 4 | | nvdspreprocess / nvinferserver config templates + rendering |
| 5 | | Triton model repo, config.pbtxt, model.py, ddm_net.py |
| 5b | | C++ postprocess plugin, Makefile, IOptions API |
| 6 | | SOPProcessManager, SOPVideoProcessor, VLLMInference, Kafka |
| 6b | | SOP sequence and checker compliance: MissingNumberDetector, SopCheckerCache, SopCheckerRequest/Response |
| 7 | | SSE generator, stream response formatting, dummy test mode |
| 8 | | Basler camera support, Pylon SDK, emulation, formats |
| 9 | | Docker build, deploy, .env configuration |
| 10 | | Test suite coverage, assertions, running tests |
| 11 | | All environment variables reference |
| 12 | | End-to-end eval workflow: static checks, build, launch, tests, API/camera/Kafka checks, report |
| 13 | | Verification steps and curl examples |
| 14 | | Implementation checklist: file copy list, generated files, Docker prereqs, verification |
| 15 | | TTFC and C2C latency measurement for file input via SSE streaming |
| 16 | | Kafka message schema selection ( |
| 17 | | Camera / live-stream chunk_e2e latency measurement using internal pipeline timestamps |
| 18 | | OPT-IN RTSP streaming output: |
For end-to-end evaluation, read § 12 first; load build/test/curl/latency/camera/Kafka as needed.
§ 18 is opt-in — generate only when the user explicitly requests RTSP output; otherwise skip § 18 and the rules below.
RTSP_*每个章节对应目录下的独立文件——仅加载任务所需的内容即可。
references/| 章节 | 文件 | 职责 |
|---|---|---|
| 1 | | FastAPI接口、服务器初始化、Prometheus指标 |
| 2 | | 请求/响应Pydantic模型( |
| 3 | | DeepStream pyservicemaker流水线、张量解析器、虚拟流水线 |
| 4 | | nvdspreprocess / nvinferserver配置模板及渲染逻辑 |
| 5 | | Triton模型仓库、config.pbtxt、model.py、ddm_net.py |
| 5b | | C++后处理插件、Makefile、IOptions API |
| 6 | | SOPProcessManager、SOPVideoProcessor、VLLMInference、Kafka集成 |
| 6b | | SOP序列与合规检查:MissingNumberDetector、SopCheckerCache、SopCheckerRequest/Response |
| 7 | | SSE生成器、流响应格式化、虚拟测试模式 |
| 8 | | Basler相机支持、Pylon SDK、仿真、格式适配 |
| 9 | | Docker构建、部署、.env配置 |
| 10 | | 测试套件覆盖范围、断言逻辑、测试运行方法 |
| 11 | | 所有环境变量参考 |
| 12 | | 端到端评估流程:静态检查、构建、启动、测试、API/相机/Kafka校验、报告生成 |
| 13 | | 验证步骤与curl示例 |
| 14 | | 实施检查清单:文件复制列表、生成文件、Docker前置条件、验证步骤 |
| 15 | | 基于SSE流式传输的文件输入TTFC与C2C延迟测量 |
| 16 | | Kafka消息 schema选择(默认 |
| 17 | | 利用内部流水线时间戳测量相机/直播流的chunk_e2e延迟 |
| 18 | | 按需启用RTSP流式输出: |
如需进行端到端评估,请先阅读第12节;按需加载构建/测试/curl/延迟/相机/Kafka相关章节。
第18节为按需内容——仅当用户明确请求RTSP输出时才生成相关内容;否则跳过第18节及以下规则。
RTSP_*Key Files Map
核心文件映射
The full source-to-target file mapping lives in
:
skill_14_implementation_checklist.md- Files copied verbatim from (non-trivial algorithms — cycle detection, qwen_vl_utils preprocessing, DeepStream
references/API, protobuf sources) with the rationale per file.IOptions - Files copied as adaptable templates (Dockerfile, compose.yaml, Triton
config and ,
model.py, Pylon emulation config, etc.).ddm_net.py - Files generated from skill sections — each annotated with the Critical Rules below that the generation must follow exactly.
- Docker build prerequisites and post-build verification checklist.
Config files (, ,
) are used as-is from .
nvds_preprocess_template.txtnvds_inference_template.txtvlm_prompts.txtconfigs/When is loaded, read from the project root and run the
§ 6b-G generation workflow to produce .
If is absent or invalid, fall back to copying the reference file.
skill_06bconfigs/actions.jsonnvds_action_detector/missing_number_detector.pyconfigs/actions.json完整的源文件到目标文件映射请查看
:
skill_14_implementation_checklist.md- 直接复制的文件:来自目录(包含非 trivial 算法——循环检测、qwen_vl_utils预处理、DeepStream
references/API、protobuf源文件),每个文件均附有复制理由。IOptions - 可适配的模板文件:Dockerfile、compose.yaml、Triton配置与、
model.py、Pylon仿真配置等。ddm_net.py - 从skill章节生成的文件——每个文件均标注了生成时必须严格遵循的以下关键规则。
- Docker构建前置条件与构建后验证清单。
配置文件(、、)直接使用目录下的文件。
nvds_preprocess_template.txtnvds_inference_template.txtvlm_prompts.txtconfigs/当加载时,请读取项目根目录下的并执行第6b-G生成流程,生成。若不存在或无效,则回退到复制参考文件。
skill_06bconfigs/actions.jsonnvds_action_detector/missing_number_detector.pyconfigs/actions.jsonCritical Rules
关键规则
Each rule's full detail lives in the linkedreference file.skill_NN_*.md
| Tag | Rule summary | Details in |
|---|---|---|
| | |
| | |
| | |
| | |
| | |
| | |
| VLM warmup needs 3 frames ( | |
| 4 thread pools: | |
| Media info via | |
| | |
| DeepStream lib hide trick: rename lib → lib.tmp during gst-plugin-pylon build | |
| VLM uses real GPU frames via | |
| | |
| | |
| nvstreammux uses original resolution (not 224); pass | |
| | |
| Pipeline cleanup on client disconnect via | |
| Unified | |
| Abort in-flight VLM requests on | |
| | |
| Kafka: use | |
| User request text takes priority over | |
| Eval/latency requests omit request text by default so the VLM uses | |
| Chunk schema: | |
| Drain | |
| | |
| Write | |
| Every | |
| | |
| | |
| | |
| | |
| | |
| Pylon emulation PNGs must be explicit 3-channel RGB (matches | |
| | |
The fourrules below apply only when the optional RTSP streaming-output feature (§ 18) is requested. They do not apply to the default build — skip them if the user did not ask for RTSP output.RTSP_*
| | RTSP output branch links from the existing (added after the main inference link) only when is present. | |
| | RTSP branch queue must be + tiny cap () to prevent backpressure and NVMM pool exhaustion. | |
| | RTSP H.264 encoder must set (and B-frames disabled) to allow downstream seeking. | |
| | Select software/hardware H.264 encoder based on with MJPEG fallback. | |
RTSP_OUTPUT_TAPS_TEE1tee1rtsp_portskill_18_rtsp_streaming_output.mdRTSP_LEAKY_QUEUE_TINYleaky=2max-size-buffers=2skill_18_rtsp_streaming_output.mdRTSP_KEYINT_MAX_30key-int-max=30skill_18_rtsp_streaming_output.mdRTSP_ENCODER_FALLBACKSW_ENCODERskill_18_rtsp_streaming_output.md每条规则的详细说明请查看链接的参考文件。skill_NN_*.md
| 标签 | 规则摘要 | 详细说明位置 |
|---|---|---|
| | |
| | |
| 实时输入(RTSP / 相机)需设置 | |
| 当 | |
| | |
| | |
| VLM预热需要3帧数据( | |
| 4个线程池: | |
| 通过 | |
| 设置 | |
| DeepStream库隐藏技巧:在构建gst-plugin-pylon期间,将库重命名为lib.tmp | |
| VLM通过 | |
| | |
| | |
| nvstreammux使用原始分辨率(而非224);从 | |
| | |
| 在客户端断开连接时,通过 | |
| 文件+实时场景共用统一的 | |
| 在调用 | |
| | |
| Kafka集成:使用 | |
| 用户请求文本优先级高于 | |
| 评估/延迟请求默认不包含请求文本,以便VLM使用 | |
| 视频块schema字段: | |
| 在单个线程中按顺序消费 | |
| | |
| 将 | |
| 每次调用 | |
| 当 | |
| | |
| 当 | |
| | |
| | |
| Pylon仿真PNG必须是明确的3通道RGB格式(与 | |
| | |
以下4条规则仅在**启用可选的RTSP流式输出功能(第18节)**时适用。默认构建无需遵循——若用户未请求RTSP输出,请跳过这些规则。RTSP_*
| | RTSP输出分支仅在存在时,从已有的(添加在主推理分支之后)链接。 | |
| | RTSP分支队列必须设置 + 极小容量(),以防止背压和NVMM池耗尽。 | |
| | RTSP H.264编码器必须设置(并禁用B帧),以支持下游的seek操作。 | |
| | 根据选择软件/硬件H.264编码器,同时支持MJPEG回退。 | |
RTSP_OUTPUT_TAPS_TEE1rtsp_porttee1skill_18_rtsp_streaming_output.mdRTSP_LEAKY_QUEUE_TINYleaky=2max-size-buffers=2skill_18_rtsp_streaming_output.mdRTSP_KEYINT_MAX_30key-int-max=30skill_18_rtsp_streaming_output.mdRTSP_ENCODER_FALLBACKSW_ENCODERskill_18_rtsp_streaming_output.md",