SECUREXSECURITY ENGINEERINGNVR 文档

ONNX / YOLO

ONNX 是 Securex NVR 自定义模型部署最灵活的路径之一。ONNX 文件只是计算图,真正能否正确检测取决于导出方式、模型类型、输入布局、颜色顺序、dtype、后处理和 labelmap 是否全部一致。

Securex 自定义 YOLO 示例

detectors:
  onnx:
    type: onnx

model:
  model_type: yolo-generic
  width: 640
  height: 640
  input_tensor: nchw
  input_pixel_format: rgb
  input_dtype: float
  path: /config/model_cache/securex_custom_yolo.onnx
  labelmap_path: /config/model_cache/securex_custom_yolo_labels.txt

部署前检查

  1. 使用 Netron 或训练工具确认模型输入名称/尺寸,例如 1×3×640×640。
  2. 确认训练导出时是 RGB 还是 BGR、0–1 float 还是 uint8/int。
  3. 检查输出头是否属于 Securex/Frigate 支持的 YOLO 形式。
  4. 生成与训练类别顺序完全一致的 labels 文件。
  5. 先离线跑一张已知图片,确认类别、框坐标和置信度正常。

硬件后端

ONNX Runtime 可根据 Securex/Frigate 镜像和宿主机硬件使用不同 Execution Provider,例如 Intel/OpenVINO、NVIDIA/TensorRT/CUDA 或 AMD/ROCm。容器能看到 GPU 并不等于 ONNX Runtime 一定使用 GPU,应以日志和 provider 信息为准。

实时模型测试

训练中心部署后,建议在“模型测试”中直接读取实时摄像头帧,以固定间隔执行推理并覆盖检测框。测试页面只用于验证模型,不应与生产 detect pipeline 争夺过多 GPU/CPU 资源。

常见故障

表现原因
启动 shape mismatchwidth/height、NCHW/NHWC 不匹配
框全部偏移letterbox/缩放后处理不匹配
类别编号错位labels 顺序错误
能跑但速度很慢落到 CPU provider 或模型过大

ONNX / YOLO

ONNX is one of the most flexible deployment paths for custom models. The file is only a computation graph; correct detection depends on export format, model type, input layout, color order, dtype, post-processing, and label map all matching.

Securex custom YOLO example

detectors:
  onnx:
    type: onnx
model:
  model_type: yolo-generic
  width: 640
  height: 640
  input_tensor: nchw
  input_pixel_format: rgb
  input_dtype: float
  path: /config/model_cache/securex_custom_yolo.onnx
  labelmap_path: /config/model_cache/securex_custom_yolo_labels.txt

Pre-deployment checklist

  1. Inspect the model input, for example 1×3×640×640.
  2. Confirm RGB/BGR and float vs integer normalization.
  3. Confirm the output head is supported.
  4. Create labels in exactly the training class order.
  5. Run a known still image offline before production.

Hardware providers

ONNX Runtime may use Intel/OpenVINO, NVIDIA/TensorRT/CUDA, or AMD/ROCm depending on the image and host. Seeing a GPU inside the container does not prove ONNX is using it; verify runtime provider logs.

Live model testing

After deployment, a live test view can periodically infer on camera frames and overlay boxes. Keep the test rate limited so it does not compete with the production detector.

Common failures

SymptomLikely cause
Shape mismatchWrong size or NCHW/NHWC
Boxes shiftedLetterbox/scaling post-processing mismatch
Wrong class IDsLabel order mismatch
Very slowCPU provider or oversized model

ONNX / YOLO

ONNX es una ruta flexible para modelos personalizados. El archivo solo es el grafo; el resultado depende de que exportación, tipo, layout, color, dtype, postprocesado y labelmap coincidan.

Ejemplo YOLO

detectors:
  onnx:
    type: onnx
model:
  model_type: yolo-generic
  width: 640
  height: 640
  input_tensor: nchw
  input_pixel_format: rgb
  input_dtype: float
  path: /config/model_cache/securex_custom_yolo.onnx
  labelmap_path: /config/model_cache/securex_custom_yolo_labels.txt

Antes de desplegar

  1. Confirme la entrada, por ejemplo 1×3×640×640.
  2. Confirme RGB/BGR y normalización.
  3. Confirme salida compatible.
  4. Cree labels en el orden de entrenamiento.
  5. Pruebe una imagen conocida offline.

Backends

ONNX Runtime puede usar Intel/OpenVINO, NVIDIA/TensorRT/CUDA o AMD/ROCm. Ver la GPU no demuestra que ONNX la esté usando; revise providers en logs.

Prueba en vivo

La prueba de modelo puede inferir periódicamente sobre cámaras y dibujar cajas. Limite la frecuencia para no competir con producción.

Fallos comunes

SíntomaCausa
Shape mismatchTamaño/layout
Cajas desplazadasLetterbox/escalado
Clases incorrectasOrden de labels
Muy lentoCPU provider o modelo grande
输入关键词开始搜索