# Simplified Conversion for Yolos

> This is a legacy tool. We suggest switching to
> [HubAI Conversion](https://docs.luxonis.com/cloud/hubai/model-registry/detailed-conversion.md)
> or usig the Python API as described in the
> [ migration guide](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/online/hubai.md)
> .

## Overview

We created a tool to simplify the export process of the Yolo object detectors. Namely, our tools support the conversion of Yolos
ranging from V5 through V11 and Gold Yolo.

> Please note that our tools support conversion of YOLOv9 weights only from Ultralytics (see
> [here](https://docs.google.com/spreadsheets/d/16k3P-LxPMFREoePLvoLqDZo0Xu_tRcSpm_BjQE3PHQY/edit?usp=sharing)
> for the supported version overview). We strongly suggest you switch to
> [HubAI Conversion](https://docs.luxonis.com/cloud/hubai/model-registry/detailed-conversion.md)
> as that one is being actively maintained and newer YOLO versions are supported (e.g. YOLOv12).

Upload the weights of the pre-trained model (.pt file), set an input image shape, choose the Robotics Vision Core generation of
the target device (learn more about parameters in [Options of
Tools](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/online/yolo.md)) and we'll compile a blob and a
JSON file with information required by DepthAI to decode the results.

## Example

This example shows how to convert YoloV6n R4 and how to run the compiled model on an OAK device.

 1. First, we will start by downloading the model's weights. You can download them from
    [here](https://github.com/meituan/YOLOv6/releases/download/0.4.0/yolov6n.pt).

 2. Open the [tools](https://tools.luxonis.com/) in a browser of your choice. Then, upload the downloaded yolov6n.pt weights and
    set the Input image shape to 640 352 (we choose this input image shape as the aspect ratio is close to 16:9 and throughput and
    latency are still decent). The rest of the options are left as they are.

 3. Click on the Submit button. The model will be automatically converted and downloaded inside a zip folder (the zip folder will
    contain a converted blob file, JSON file alongside a intermediate representation used to generate the output blob file).

 4. Extract the ZIP folder locally, then run inference on the exported model using the script below. Make sure to set MODEL_PATH,
    and refer to the .json file for the required input size and label information.

```python
import depthai as dai
from depthai_nodes.node import YOLOExtendedParser

MODEL_PATH = ... # e.g. "yolov6n.blob"
INPUT_SIZE = ... # e.g. (640, 352)
LABELS = ... # e.g. ["person","bicycle","car", ...]

visualizer = dai.RemoteConnection(httpPort=8080)
device = dai.Device()
platform = device.getPlatform().name
frame_type = (
    dai.ImgFrame.Type.BGR888i if platform == "RVC4" else dai.ImgFrame.Type.BGR888p
)

with dai.Pipeline(device) as pipeline:

    # model node
    nn = pipeline.create(dai.node.NeuralNetwork)
    nn.setModelPath(MODEL_PATH)

    # parser node
    parser = pipeline.create(YOLOExtendedParser, n_classes=len(LABELS), label_names=LABELS)

    # input node
    camera = pipeline.create(dai.node.Camera).build()
    camera_stream = camera.requestOutput(size=INPUT_SIZE, type=frame_type)                                  

    # connect nodes
    camera_stream.link(nn.input)
    nn.out.link(parser.input)

    # visualize
    visualizer.addTopic("Video", nn.passthrough, "images")
    visualizer.addTopic("Detections", parser.out, "images")

    pipeline.start()
    visualizer.registerPipeline(pipeline)

    while pipeline.isRunning():
        key = visualizer.waitKey(1)
        if key == ord("q"):
            print("Got q key from the remote connection!")
            break
```

> For more details on running models, see the
> [Inference](https://docs.luxonis.com/software-v3/ai-inference/inference.md)
> section.

## Options of Tools

 * Yolo Version - Required, which Yolo version conversion should be used. Inside tools, an automatic Yolo version detector is
   integrated, which, when you upload a model's weights, will automatically detect the Yolo version and set it.
 * RVC2 or RVC3 - Required, Robotics Vision Core generation of the target device.
 * File - Required, weights of a pre-trained model (.pt file), size needs to be smaller than 300Mb.
 * Input image shape - Required, integer for square input image shape, or width and height separated by a space. It must be
   divisible by 32 (or 64, depending on the stride).
 * Shaves - Optional, default value is 6. Number of shaves used. To read more about shaves, please refer to
   [here](https://docs.luxonis.com/software-v3/ai-inference/conversion.md).
 * Use OpenVINO 2021.4 - Optional, default value is true. This checkbox controls whether, during compilation to IR, the legacy
   frontend flag will be used. If off, defaults to OpenVINO 2022.1. Slight performance degradation was noticed with 2022.1.
   Therefore, we recommend setting it to true.
