# 用于 Luxonis DepthAI 实时目标检测的 YOLO 模型

## YOLO 模型简介

YOLO（You Only Look Once） 是一系列以速度和准确率著称的实时目标检测模型。与传统的将模型应用于图像多个位置和尺度的目标检测方法不同，YOLO
模型将目标检测视为回归问题。它们直接在单个评估中从完整图像预测边界框和类别概率，从而实现了适用于实时应用的快速高效目标检测。早期 YOLO 模型主要用于目标检测，而较新版本支持多头用于关键点检测、分割等任务。

## 在 DepthAI 上开始使用 YOLO

### YOLO 集成概述

DepthAI 支持解析 YOLO 模型输出（包括非极大值抑制等后处理）并将其转换为标准的 DepthAI
消息格式（[ImgDetections](https://docs.luxonis.com/software/depthai-components/messages/img_detections.md)）。这实现了在 DepthAI 设备上高效的 YOLO
模型集成和处理。

使用 YOLO 模型有两个主要节点：

 * [YoloDetectionNetwork](https://docs.luxonis.com/software/depthai-components/nodes/yolo_detection_network.md)：使用 YOLO
   模型进行标准目标检测。
 * [YoloSpatialDetectionNetwork](https://docs.luxonis.com/software/depthai-components/nodes/yolo_spatial_detection_network.md)：将目标检测与空间数据（即深度信息）相结合，实现
   3D 目标定位。

### 示例实现

为帮助您入门，请探索以下示例实现：

 * [RGB 与 Tiny YOLO](https://docs.luxonis.com/software/depthai/examples/tiny_yolo.md)：演示如何使用 Tiny YOLO 模型进行目标检测。
 * [RGB 与 Tiny YOLO（含空间数据）](https://docs.luxonis.com/software/depthai-components/nodes/yolo_spatial_detection_network.md)：展示如何使用
   Spatial Tiny YOLO 结合深度信息进行目标检测。
 * [RGB 与 YOLOv8 Nano](https://docs.luxonis.com/software/depthai/examples/yolov8_nano.md)：说明在资源受限环境中使用轻量级 YOLOv8 Nano
   模型进行高性能检测的方法。

### 使用 DepthAI 的 YOLO 实验

DepthAI 支持使用设备端和主机端解码方法进行各种 YOLO 模型的目标检测。您可以在 [OAK Examples 仓库](https://github.com/luxonis/oak-examples/tree/master/gen2-yolo)
中找到多个演示和示例，包括：

 * [device-decoding](https://github.com/luxonis/oak-examples/tree/master/gen2-yolo/device-decoding)：使用
   YOLOv3、YOLOv3-tiny、YOLOv4、YOLOv4-tiny 和 YOLOv5 进行设备端解码的通用目标检测。使用 DepthAI-API。

 * [car-detection](https://github.com/luxonis/oak-examples/tree/master/gen2-yolo/car-detection)：使用 YOLOv3-tiny 和 YOLOv4-tiny
   模型进行设备端解码的车辆检测。使用 DepthAI-SDK。

 * [host-decoding](https://github.com/luxonis/oak-examples/tree/master/gen2-yolo/host-decoding)：使用 YOLOv5 进行主机端解码的目标检测。

 * [yolox](https://github.com/luxonis/oak-examples/tree/master/gen2-yolo/yolox)：使用 YOLOX-tiny 在主机端解码的无锚点目标检测。

 * [yolop](https://github.com/luxonis/oak-examples/tree/master/gen2-yolo/yolop)：在 OAK 上使用 YOLOP 进行车辆检测、道路分割和车道分割，采用主机端解码。

这些示例展示了如何在 DepthAI 设备上使用设备端和主机端解码运行不同的 YOLO 模型。

### 训练与定制

如果您希望根据具体需求训练或微调 YOLO 模型，以下资源将为您提供指导：

 * 训练指南：提供使用您的数据集训练 YOLO 模型的分步说明。
   
   * [YOLOv4-tiny 和 YOLOv3-tiny
     教程](https://colab.research.google.com/github/luxonis/ai-tutorials/blob/master/colab-notebooks/YoloV3_V4_tiny_training.ipynb)
   * [YOLOv5 教程](https://colab.research.google.com/github/luxonis/ai-tutorials/blob/master/colab-notebooks/YoloV5_training.ipynb)
   * [YOLOv6 教程](https://colab.research.google.com/github/luxonis/ai-tutorials/blob/master/colab-notebooks/YoloV6_training.ipynb)
   * [YOLOv7 教程](https://colab.research.google.com/github/luxonis/ai-tutorials/blob/master/colab-notebooks/YoloV7_training.ipynb)
   * [YOLOv8 教程](https://colab.research.google.com/github/luxonis/ai-tutorials/blob/master/colab-notebooks/YoloV8_training.ipynb)

 * [模型动物园](https://github.com/luxonis/depthai-model-zoo/tree/main/models)：访问预训练的 YOLO 模型集合，可直接使用或作为进一步训练的起点。

### 使用 tools.luxonis.com 进行模型转换

Luxonis 在 [tools.luxonis.com](https://tools.luxonis.com) 提供了强大的工具集，允许您轻松地将训练好的 YOLO 模型转换为与 DepthAI 兼容的格式。此工具对于将在 PyTorch 中训练的 YOLO
模型（.pt 文件）转换为 OpenVINO 格式特别有用，然后可进一步转换为 DepthAI .blob 文件。

## 许可证

每个集成到 DepthAI 的 YOLO 模型版本可能有其自己的许可条款。请查看您所使用的模型的相应许可证：

 * YOLOv3：根据 [YOLOv3 许可证](https://github.com/pjreddie/darknet/blob/master/LICENSE) 发布。
 * YOLOv4：根据 [YOLOv4 许可证](https://github.com/AlexeyAB/darknet/blob/master/LICENSE) 发布。
 * YOLOv5：由 Ultralytics 根据 [YOLOv5 许可证](https://github.com/ultralytics/yolov5/blob/master/LICENSE)（GNU Affero 通用公共许可证 v3.0）发布。
 * YOLOv6：根据 [YOLOv6 许可证](https://github.com/meituan/YOLOv6/blob/main/LICENSE)（GNU 通用公共许可证 v3.0）发布。
 * YOLOv7：根据 [YOLOv7 许可证](https://github.com/WongKinYiu/yolov7/blob/main/LICENSE.md)（GNU 通用公共许可证 v3.0）发布。
 * YOLOv8：由 Ultralytics 根据 [YOLOv8 许可证](https://github.com/ultralytics/ultralytics/blob/main/LICENSE)（GNU Affero 通用公共许可证 v3.0）发布。
 * YOLOX：根据 [YOLOX 许可证](https://github.com/Megvii-BaseDetection/YOLOX/blob/main/LICENSE)（Apache 许可证 v2.0）发布。
 * YOLOP：根据 [YOLOP 许可证](https://github.com/hustvl/YOLOP/blob/main/LICENSE)（MIT 许可证）发布。
 * GoldYOLO：根据 [GoldYOLO 许可证](https://github.com/huawei-noah/Efficient-Computing/blob/master/Detection/Gold-YOLO/LICENSE)（GNU
   通用公共许可证 v3.0）发布。
