Skip to content

YOLO26

1 Overview

1.1 Background Introduction

YOLO26 is an advanced real-time object detection algorithm that natively supports a non-maximum suppression (NMS-free) mechanism. It enhances detection accuracy and robustness while maintaining fast detection speeds. The official YOLO26 provides various detection model sizes: n, s, m, l, x, and the accuracies of these open-source models are as follows:

For more details, please refer to the official YOLO26 documentation:

https://github.com/ultralytics/ultralytics/tree/v8.4.37

The download link for the YOLO26 open-source models is as follows:

1.2 Usage Instructions

The Linux SDK-alkaid comes with pre-converted offline models and board-side examples by default. The relevant file paths are as follows:

  • Board-side example program path

    Linux_SDK/sdk/verify/opendla/source/detection/yolo26
    
  • Board-side offline model path

    Linux_SDK/project/board/${chip}/dla_file/ipu_open_models/detection/yolo26n_640x640.img
    
  • Board-side test image path

    Linux_SDK/sdk/verify/opendla/source/resource/bus.jpg
    

If the user does not need to convert the model, they can jump directly to section 3.

2 Model Conversion

2.1 ONNX Model Conversion

  • Setting up the Python environment

    $conda create -n yolo26 python==3.10
    $conda activate yolo26
    $git clone https://github.com/ultralytics/ultralytics
    $cd ultralytics
    $pip install -e . -i https://pypi.tuna.tsinghua.edu.cn/simple
    

    Note: The provided Python environment setup is only a reference example; for the specific setup process, please refer to the official source running tutorial:

    https://docs.ultralytics.com/quickstart/
    
  • Model Testing

    • Write the model testing script predict.py

      from ultralytics import YOLO
      # Load a pretrained YOLO8n model
      model = YOLO("yolo26n.pt")
      
      # Run inference on 'bus.jpg' with arguments
      # Use one-to-one head (default, no NMS required)
      model.predict("./ultralytics/assets/bus.jpg", save=True, imgsz=640, conf=0.5)
      
      # Use one-to-many head (requires NMS)
      model.predict("./ultralytics/assets/bus.jpg", save=True, imgsz=640, conf=0.5, end2end=False)
      
    • Run the model testing script to ensure the YOLO26 environment is configured correctly.

      $python predict.py
      

    For specific details, please refer to the official YOLO26 testing documentation

    https://docs.ultralytics.com/zh/models/yolo26/#usage-examples
    
  • Model Export

    • Write the model conversion script export.py:

      import os
      import sys
      from ultralytics import YOLO
      model = YOLO("yolo26n.pt")
      
      # Use one-to-one head (default, no NMS required)
      model.export(format="onnx", imgsz=[640,640], simplify=True)
      
      # Use one-to-many head (requires NMS)
      model.export(format="onnx", imgsz=[640,640], simplify=True, end2end=False)
      
    • Run the model conversion script to generate the yolo26n.onnx model in the current directory

      $python export.py
      

2.2 Offline Model Conversion

2.2.1 Preprocessing & Postprocessing Instructions

  • Preprocessing

    The input information for the successfully converted yolo26n.onnx model is shown in the figure below, requiring the input image size to be (1, 3, 640, 640), and the pixel values must be normalized to the range [0, 1].

  • Postprocessing

    YOLO26 features a dual-head architecture, providing flexibility for different deployment scenarios: - one-to-one head (default): The output information of the yolo26n.onnx model is shown in the figure below. It generates end-to-end predictions without the need for NMS, with an output dimension of (1, 300, 6), where 300 is the number of detection boxes, and 6 includes 4 boundary box coordinates, category probability, and category index.

    • one-to-many head: The output information of the yolo26n_one2many.onnx model is shown in the figure below, generating the traditional YOLO output that requires NMS post-processing. The output dimensions are (1, 84, 8400), where 8400 is the number of candidate boxes and 84 includes 4 bounding box coordinates and 80 class probabilities. After obtaining the candidate boxes from the model output, all candidate box classes need to be judged, and NMS (Non-Maximum Suppression) must be performed to output the correct bounding boxes.

2.2.2 Offline Model Conversion Process

Note: 1) OpenDLAModel corresponds to the smodel file extracted from the compressed package image-dev_model_convert.tar. 2) The conversion command must be run in a Docker environment; please load the SGS Docker environment according to the Docker development environment tutorial.

  • Copy the ONNX model to the conversion code directory

    $cp ultralytics/yolo26n.onnx OpenDLAModel/detection/yolo26/onnx
    $cp ultralytics/yolo26n_one2many.onnx OpenDLAModel/detection/yolo26/onnx
    
  • Conversion command

    $cd IPU_SDK_Release/docker
    $bash run_docker.sh
    # Enter the OpenDLAModel directory in the Docker environment
    $cd /work/SGS_XXX/OpenDLAModel
    #one2one head
    $bash convert.sh -a detection/yolo26 -c config/detection_yolo26.cfg -p SGS_IPU_Toolchain(absolute path) -s false
    #one2many head
    $bash convert.sh -a detection/yolo26 -c config/detection_yolo26_one2many.cfg -p SGS_IPU_Toolchain(absolute path) -s false
    
  • Final generated model locations

    output/${chip}_${time}/yolo26n_640x640.img
    output/${chip}_${time}/yolo26n_640x640_fixed.sim
    output/${chip}_${time}/yolo26n_640x640_float.sim
    output/${chip}_${time}/yolo26n_one2many_640x640.img
    output/${chip}_${time}/yolo26n_one2many_640x640_fixed.sim
    output/${chip}_${time}/yolo26n_one2many_640x640_float.sim
    

2.2.3 Key Script Parameter Analysis

-   input_config.ini

        [INPUT_CONFIG]
        inputs = images;                # ONNX input node names, separated by commas if there are multiple;
        training_input_formats = RGB;   # Input format during model training, usually RGB;
        input_formats = YUV_NV12;       # Board-side input format, can choose BGRA or YUV_NV12 based on the situation;
        quantizations = TRUE;           # Enable input quantization, do not modify;
        mean_red = 0;                   # Mean, related to model preprocessing, configure according to actual conditions;
        mean_green = 0;                 # Mean, related to model preprocessing, configure according to actual conditions;
        mean_blue = 0;                  # Mean, related to model preprocessing, configure according to actual conditions;
        std_value = 255;                # Variance, related to model preprocessing, configure according to actual conditions;
        [OUTPUT_CONFIG]
        outputs = output0;              # ONNX output node names, separated by commas if there are multiple;
        dequantizations = TRUE;         # Whether to enable dequantization, fill according to actual needs, recommended to be TRUE. If set to False, output will be int16; if set to True, output will be float32.

-   detection_yolo26.cfg

        [YOLO26]
        CHIP_LIST=pcupid                        # Platform name, must match the board platform; otherwise, the model cannot run
        Model_LIST=yolo26n                      # Input ONNX model name
        INPUT_SIZE_LIST=640x640                 # Model input resolution
        INPUT_INI_LIST=input_config_cpu.ini     # Configuration file
        CLASS_NUM_LIST=0                        # Just fill in 0
        SAVE_NAME_LIST=yolo26n_640x640.img      # Output model name
        QUANT_DATA_PATH=quant_data              # Path for quantization images

2.3 Model Simulation

  • Obtain float/fixed/offline model outputs

    $bash convert.sh -a detection/yolo26 -c config/detection_yolo26.cfg -p SGS_IPU_Toolchain (absolute path) -s true
    

    After executing the above command, the output tensor of the float model will be saved by default in a txt file under the path detection/yolo26/log/output. Additionally, the detection/yolo26/convert.sh script also provides simulation examples for fixed and offline, allowing users to obtain outputs for the fixed and offline models by uncommenting code blocks during execution.

  • Model Accuracy Comparison

    With the input being the same as the aforementioned models, enter the environment built in section 2.1, and add the following print statement at line 222 in the ultralytics/ultralytics/nn/modules/head.py file:

    print(torch.cat([boxes, scores, conf], dim=-1))
    

    This will obtain the output tensor of the corresponding node in the PyTorch model, allowing for comparison with the float, fixed, and offline models.

3 Board-side Deployment

3.1 Program Compilation

Before compiling the example program, it is necessary to select the appropriate deconfig based on the board (nand/nor/emmc, ddr model, etc.) for the complete SDK compilation. For details, refer to the alkaid SDK sigdoc document "Development Environment Setup."

  • Compile the board-side YOLO26 example.

    $cd sdk/verify/opendla
    $make clean && make source/detection/yolo26 -j8
    
  • Final generated executable file location

    sdk/verify/opendla/out/${AARCH}/app/prog_detection_yolo26
    

3.2 Running Files

When running the program, you need to copy the following files to the board:

  • prog_detection_yolo26
  • bus.jpg
  • yolo26n_640x640.img

3.3 Running Instructions

  • Usage: ./prog_detection_yolo26 -i image -m model [-t threshold] (command to run the executable)
  • Required Input:
    • image: path to the image folder/single image
    • model: path to the offline model to be tested
  • Optional Input:

    • threshold: detection threshold (0.0~1.0, default is 0.5)
  • Typical output:

    >./prog_detection_yolo26 -m ./yolo26n_640x640.img -i ./images/bus.jpg
    
        demo_args: inImages=./; modelPath=./yolo26n_640x640.img; threshold=0.5
        found 1 images!
        [0] processing ./images/bus.jpg...
        model invoke time: 29.250000 ms
        post process time: 0.179000 ms
        outImagePath: ./output/22545/bus.png
    

4 Algorithm Optimization

4.1 Postprocessing Optimization

  • Existing Issues

    The CPU usage of the official YOLO26 (one2many head) converted offline model is relatively high. The root cause is that the YOLO26 (one2many head) model outputs 8400 candidate detection boxes (Bounding Boxes) by default, and in the COCO dataset with 80 categories, each candidate box requires 80 computations for class confidence, resulting in a total computation of 672,000 times per frame (8400×80), which keeps the CPU loading at a high state.

  • Solution

    Construct a post-processing model using the SGS_IPU_Toolchain (as shown in the figures below) and concatenate it with the official YOLO26 (one2many head) model. This allows the computation of all candidate boxes to be performed on the IPU without changing the structure of the official YOLO26 (one2many head) model. Therefore, while converting the model and running the board-side example:

    • The ONNX model remains unchanged; refer to 2.1
    • Offline model conversion command

      $bash convert.sh -a detection/yolo26 -c config/detection_yolo26_one2many.cfg -p SGS_IPU_Toolchain (absolute path) -s false -d ipu
      

      Relevant optimizations can be found in OpenDLAModel/detection/yolo26/yolo26_post.py

    • Board-side deployment; refer to 3

  • Note

    The method of building IPU operators through the SGS_IPU_Toolchain requires the user to be familiar with the IPU Toolchain. For specifics, refer to the documentation for using the IPU Toolchain.