Translation procedure for YOLOX
This document describes the procedure for translating YOLOX with DRP-AI Translator v1.80 or later.
Please note the following:
Use ONNX in Megvii-BaseDetection/YOLOX (OSS GitHub repository)
Cut the post-processing part of the ONNX and use it
Run DRP-AI Translator v1.80 or later on Ubuntu 20.04
For the Renesas DRP-AI TVM Translator please refer to link 🔗here.
1. Download ONNX
Please run the following command to download the ONNX in Megvii-BaseDetection
$ wget https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_s.onnx
2. Cut post-processing part of ONNX
Please edit the following in an editor such as vim, and save it as yolox_s_cut.py.
$ vim yolox_s_cut.py
# yolox_s_cut.py import onnx input_path = 'yolox_s.onnx' output_path = 'yolox_s_wo_post.onnx' input_names = ['images'] output_names = ['798', '824', '850'] onnx.utils.extract_model(input_path, output_path, input_names, output_names)
As shown in the figure below, please find and specify the output name of Concat before Reshape
Please run yolox_s_cut.py with the following command. If executed successfully, yolox_s_wo_post.onnx will be generated.
$ python3 yolox_s_cut.py
The above output names, 798, 824, and 850, are for YOLOX-s. Please note that different names must be specified for other
YOLOX (e.g. YOLOX-m). As shown in the figure below, please find and specify the output name of Concat before Reshape
of the three outputs of YOLOX.
3. Translate ONNX
Please run DRP-AI Translator using the generated yolox_s_wo_post.onnx. DRP-AI Translator must be v1.80 or later. For
information on how to run DRP-AI Translator, please refer to the User's Manual.
4. Post-processing
The post-processing (Reshape > Concat > Transpose) that is cut this time is the processing that concatinates the data of
three CHW shapes and converts them to HWC shapes.
DRP-AI outputs data in HWC shape by default, so if the three output data are stored in consecutive memory areas, the
same sequence of data as after post-processing is obtained in terms of memory layout.
5. Removing redundant Post‑Processing Layers/ DRP-AI TVM Flow
To improve the performance of most YOLO models, including YOLOX‑s, Renesas recommends removing redundant post‑processing layers from the model ("Cut post-process with onnx file“). These re-shaping operators are currently un-supported with DRP-AI Translator and would be assigned to CPU. By cutting these layers the overall processing time of the model is reduced.
For example, following layer are recommended for YOLOX‑s:
Note: To identify which layers are executed on DRP‑AI and which are assigned to the CPU, the log file generated during compilation with DRP‑AI TVM can be analyzed. The script analyse_log.py (Step 10) can be used to extract this information.
Following reduction in the overall processing time and can be seen:
Model | Pre-processing time [ms]* | Inference time [ms]* | Post-processing time [ms]* | Avg. CPU Utilization [%] |
|---|---|---|---|---|
YoloXs uncut | 8.07 | 27.62 | 10.20 | 96.25 |
YoloXs cut | 10.68 | 18.90 | 6.79 | 60 |
*The reported pre‑processing, inference, and post‑processing times are average values calculated over 4,000 iterations.
To illustrate the impact of cutting post‑processing layers, two applications are provided: one using the uncut YOLOX‑s model and another using the cut version, each with its corresponding post‑processing implementation. Both applications were built using RZ/V2H AI SDK 6.0 together with RUHMI (DRP‑AI TVM v2.7).
The provided folder contains the source code for both applications, as well as instructions for downloading the model, compiling it, and building the applications.
Please note that this example is not intended to serve as a benchmark, but rather as a practical example within an application that includes post‑processing, camera input, and display output.