YOLOX Documentation

repository·main·Indexed 27 days ago

https://github.com/megvii-basedetection/yolox

An anchor-free version of YOLO implemented in PyTorch, designed to bridge the gap between research and industrial applications. It supports various deployment targets including ONNX, TensorRT, ncnn, and MegEngine. The documentation covers dataset configuration via YOLOX_DATADIR, COCO dataset structure, and detailed build and deployment guides for C++ and Python across Host (Linux) and Android platforms.

Tokens
13.2K
Snippets
50
Records
87
Agent score
94%

What's inside YOLOX

  1. Understand Training and Testing Image Size Hyperparameters

    main

    YOLOX uses specific hyperparameters to control image dimensions during training and testing.

    Training Hyperparameters:

    • self.input_size: A tuple (height, width) representing the base training size. It is recommended to set this to the same value as self.test_size. Default is (640, 640) for most models, or (416, 416) for yolox-tiny and yolox-nano.
    • self.multiscale_range: An integer that determines the range of scales used during multi-scale training.
    • self.random_size: A tuple (min_scale, max_scale) used to define a specific scale range when multi-scale training is configured with explicit bounds.

    Testing Hyperparameter:

    • self.test_size: A tuple (height, width) representing the image size used during inference/testing.
  2. Accelerate training with image caching

    main

    You can achieve up to 2X faster training by optimizing data preprocessing and using the --cache flag to cache images into system RAM. Note that this requires a large amount of system RAM.

    python tools/train.py -n yolox-s -d 8 -b 64 --fp16 -o [--cache]
                             yolox-m
                             yolox-l
                             yolox-x
  3. Convert ONNX models to OpenVINO

    main

    To convert a YOLOX model to OpenVINO format, follow these steps:

    1. Export ONNX: Export your model to ONNX format. Crucial: You must set --opset to 10 during ONNX export to ensure compatibility with the OpenVINO model optimizer.
    2. Install Prerequisites: Navigate to the OpenVINO model optimizer directory and run the prerequisite installation script.
    3. Run Model Optimizer: Use mo.py to convert the ONNX model to OpenVINO IR format.
  4. Modify ncnn model param for Focus layer support

    main

    Because ncnn does not support the Focus layer, you must manually modify the model.param file to replace the unsupported layers with a YoloV5Focus layer.

    Steps to modify model.param:

    1. Update Layer Count: Change the first number in the file (total layers). For example, if you are removing 10 layers and adding 1, subtract 9 from the original count.
    2. Remove Unsupported Layers: Delete the lines representing the Split to Concat operations that implement the Focus logic. Note the last index used before these layers (e.g., 683).
    3. Insert Focus Layer: Add the YoloV5Focus layer immediately after the Input layer using the index noted in step 2.

    Example Modification:

    Before (example):

    295 328
    Input            images                   0 1 images
    Split            splitncnn_input0         1 4 images images_splitncnn_0 images_splitncnn_1 images_splitncnn_2 images_splitncnn_3
    ... (layers to remove) ...
    Concat           Concat_40                4 1 652 672 662 682 683 0=0

    After (example):

    286 328
    Input            images                   0 1 images
    YoloV5Focus      focus                    1 1 images 683
    ... (remaining layers) ...