# YOLO Models for Real-Time Object Detection on Luxonis DepthAI

## Introduction to YOLO Models

YOLO (You Only Look Once) is a family of real-time object detection models known for their speed and accuracy. Unlike traditional
object detection methods that apply a model to an image at multiple locations and scales, YOLO models frame object detection as a
regression problem. They predict bounding boxes and class probabilities directly from full images in a single evaluation, enabling
fast and efficient object detection suitable for real-time applications. Initial YOLO models were used primarily for object
detection, while newer versions support multiple heads for tasks like keypoints detection, segmentation, and more.

## Getting Started with YOLO on DepthAI

### YOLO Integration Overview

DepthAI supports parsing YOLO model outputs (including post-processing like Non-Maximum Suppression) and converting them into the
standard DepthAI message format
([ImgDetections](https://docs.luxonis.com/software/depthai-components/messages/img_detections.md)). This enables efficient YOLO
model integration and processing on DepthAI devices.

There are two main nodes to use with YOLO models:

 * [YoloDetectionNetwork](https://docs.luxonis.com/software/depthai-components/nodes/yolo_detection_network.md): Standard object
   detection using YOLO models.
 * [YoloSpatialDetectionNetwork](https://docs.luxonis.com/software/depthai-components/nodes/yolo_spatial_detection_network.md):
   Combines object detection with spatial data (i.e., depth information), allowing 3D object localization.

### Example Implementations

To help you get started, explore the following example implementations:

 * [RGB & Tiny YOLO](https://docs.luxonis.com/software/depthai/examples/tiny_yolo.md): Demonstrates how to use the Tiny YOLO model
   for object detection.
 * [RGB & Tiny YOLO with Spatial
   Data](https://docs.luxonis.com/software/depthai-components/nodes/yolo_spatial_detection_network.md): Shows how to perform
   object detection with depth information using Spatial Tiny YOLO.
 * [RGB & YOLOv8 Nano](https://docs.luxonis.com/software/depthai/examples/yolov8_nano.md): Illustrates the use of the lightweight
   YOLOv8 Nano model for high-performance detection in resource-constrained environments.

### YOLO Experiments with DepthAI

DepthAI supports various YOLO models for object detection using both on-device and on-host decoding methods. You can find several
demos and examples in the [OAK Examples repository](https://github.com/luxonis/oak-examples/tree/master/gen2-yolo), which include:

 * [`device-decoding`](https://github.com/luxonis/oak-examples/tree/master/gen2-yolo/device-decoding): General object detection
   using YOLOv3, YOLOv3-tiny, YOLOv4, YOLOv4-tiny, and YOLOv5 with on-device decoding. Uses the DepthAI-API.
 * [`car-detection`](https://github.com/luxonis/oak-examples/tree/master/gen2-yolo/car-detection): Car detection using YOLOv3-tiny
   and YOLOv4-tiny models with on-device decoding. Uses the DepthAI-SDK.
 * [`host-decoding`](https://github.com/luxonis/oak-examples/tree/master/gen2-yolo/host-decoding): Object detection using YOLOv5
   with on-host decoding.
 * [`yolox`](https://github.com/luxonis/oak-examples/tree/master/gen2-yolo/yolox): Object detection without anchors using
   YOLOX-tiny with on-host decoding.
 * [`yolop`](https://github.com/luxonis/oak-examples/tree/master/gen2-yolo/yolop): Vehicle detection, road segmentation, and lane
   segmentation using YOLOP on OAK with on-host decoding.

These examples showcase how to run different YOLO models on DepthAI devices with both on-device and on-host decoding.

### Training and Customization

If you wish to train or fine-tune YOLO models for your specific needs, the following resources will guide you through the process:

 * Training Guide: Provides step-by-step instructions for training YOLO models using your dataset.
    * [YOLOv4-tiny and YOLOv3-tiny
      Tutorial](https://colab.research.google.com/github/luxonis/ai-tutorials/blob/master/colab-notebooks/YoloV3_V4_tiny_training.ipynb)
    * [YOLOv5
      Tutorial](https://colab.research.google.com/github/luxonis/ai-tutorials/blob/master/colab-notebooks/YoloV5_training.ipynb)
    * [YOLOv6
      Tutorial](https://colab.research.google.com/github/luxonis/ai-tutorials/blob/master/colab-notebooks/YoloV6_training.ipynb)
    * [YOLOv7
      Tutorial](https://colab.research.google.com/github/luxonis/ai-tutorials/blob/master/colab-notebooks/YoloV7_training.ipynb)
    * [YOLOv8
      Tutorial](https://colab.research.google.com/github/luxonis/ai-tutorials/blob/master/colab-notebooks/YoloV8_training.ipynb)
 * [Model Zoo](https://github.com/luxonis/depthai-model-zoo/tree/main/models): Access a collection of pre-trained YOLO models that
   you can use directly or as a starting point for further training.

### Model Conversion with tools.luxonis.com

Luxonis provides a powerful toolset at [tools.luxonis.com](https://tools.luxonis.com) that allows you to easily convert your
trained YOLO models into formats compatible with DepthAI. This tool is particularly useful for converting YOLO models trained in
PyTorch (`.pt` files) into the OpenVINO format, which can then be converted to a DepthAI `.blob` file.

## Licenses

Each YOLO model version integrated into DepthAI may have its own licensing terms. Please review the respective licenses for the
models you are using:

 * YOLOv3: Released under the [YOLOv3 License](https://github.com/pjreddie/darknet/blob/master/LICENSE).
 * YOLOv4: Released under the [YOLOv4 License](https://github.com/AlexeyAB/darknet/blob/master/LICENSE).
 * YOLOv5: Released by Ultralytics under the [YOLOv5 License](https://github.com/ultralytics/yolov5/blob/master/LICENSE) (GNU
   Affero General Public License v3.0).
 * YOLOv6: Released under the [YOLOv6 License](https://github.com/meituan/YOLOv6/blob/main/LICENSE) (GNU General Public License
   v3.0).
 * YOLOv7: Released under the [YOLOv7 License](https://github.com/WongKinYiu/yolov7/blob/main/LICENSE.md) (GNU General Public
   License v3.0).
 * YOLOv8: Released by Ultralytics under the [YOLOv8 License](https://github.com/ultralytics/ultralytics/blob/main/LICENSE) (GNU
   Affero General Public License v3.0).
 * YOLOX: Released under the [YOLOX License](https://github.com/Megvii-BaseDetection/YOLOX/blob/main/LICENSE) (Apache License
   v2.0).
 * YOLOP: Released under the [YOLOP License](https://github.com/hustvl/YOLOP/blob/main/LICENSE) (MIT License).
 * GoldYOLO: Released under the [GoldYOLO
   License](https://github.com/huawei-noah/Efficient-Computing/blob/master/Detection/Gold-YOLO/LICENSE) (GNU General Public
   License v3.0).
