Welcome to ROSMASTER M1 repository
4. Model Format Conversion
Model Format Conversion
Model Format Conversion1. Model Format IntroductionCommon Model Formats2. Course Content3. Convert Model3.1 Model Conversion Program3.1 Start Conversion4. Source Code Analysis4.1 Model Conversion Program
[!IMPORTANT]
- The factory image already includes converted format traffic sign and lane detection models. This tutorial is provided for users who need to master model conversion methods
- If you want to experience the complete autonomous driving functionality directly, you can skip this section!!!
1. Model Format Introduction
- The ultimate goal of training models is to deploy them in practical applications. The export modes in YOLOv11 provide multiple options to export trained models into different formats, making them deployable on various platforms and devices.

Common Model Formats
PyTorch(.pt):Default native format, containing complete model structure and weights. Applicable scenarios: Model training, fine-tuning, foundation for subsequent format export, not suitable for direct deployment.
TorchScript(.torchscript):Serialized format of PyTorch models, stripped of Python dependencies.
Applicable scenarios: Production environment deployment in PyTorch ecosystem (such as server-side inference), supports C++ calling.
ONNX(.onnx):Open Neural Network Exchange format, the core standard for cross-framework compatibility. Applicable scenarios: CPU/GPU universal deployment, can achieve 3x CPU acceleration with ONNX Runtime.
TensorRT(.engine):NVIDIA exclusive optimized format, GPU-based inference engine. Applicable scenarios: Real-time inference on NVIDIA GPUs (such as Jetson development boards), can achieve 5x GPU acceleration.
OpenVINO(openvino_model):Intel exclusive format, optimized for Intel CPU/GPU/VPU. Applicable scenarios: Deployment on Intel hardware (such as PCs, edge computing devices).
TF Lite(.tflite):TensorFlow lightweight format, targeting mobile/edge devices. Applicable scenarios: Android devices, embedded hardware (such as Raspberry Pi), supports INT8 quantization compression.
RKNN(rknn_model):Rockchip exclusive format, adapted to its AI chips. Applicable scenarios: Deployment on Rockchip RK series chips (such as development boards, smart hardware).
Comparison of Different Format Models
| Comparison | Universal Format (ONNX) | Accelerated Format (TensorRT) | Edge Format (TF Lite) | Native Format (.pt) |
|---|---|---|---|---|
| Inference Speed | Medium (CPU/GPU Universal) | Extremely Fast (GPU Exclusive) | Low - Medium (Lightweight) | Low (Python Dependent) |
| Model Size | Medium | Medium (supports quantization compression) | Extremely Small (INT8 Quantization) | Large |
| Hardware Dependency | None | NVIDIA GPU | Mobile / Embedded Devices | PyTorch Environment |
| Applicable Scenarios | Universal Deployment, Cross-Framework | Real-time High-Concurrency Inference | Low-Power Edge Devices | Training / Fine-Tuning |
| Precision Support | FP32/FP16 | FP32/FP16/INT8 | FP32/FP16/INT8 | Full Precision |
2. Course Content
- Convert pt model (native format exported by YOLOv11) to TensorRT format model and compare the inference speed differences between the two
What are the benefits of using TensorRT to export models?
Using TensorRT to export models on the Jetson platform can significantly improve model inference performance. YOLO11 models exported to TensorRT can achieve up to 5x GPU acceleration
- Speed: Faster inference through advanced optimizations.
- Compatibility: Smooth integration with NVIDIA hardware.
3. Convert Model
[!NOTE]
- Only Orin boards are recommended for on-board model training. The training source code is in the yolo_train folder under Model Training in the source code summary. If training is needed, you can place the yolo_train folder programs in the root directory of the board
- RDK Mainboard Conversion Model Reference [YOLOV11 Development (RDKX5)] - [Model Quantization]
3.1 Model Conversion Program
Model format conversion program path:
/home/jetson/yolo_train/conver_model.py
Optional Launch Parameters Description:
- format: Model format to export, default is engine (TensorRT format)
- MODEL_PATH Original pt format model path
- data Calibration dataset, only needed when performing int8 quantization on the model
- device Running device number, default is 0
- int8 Whether to use int8 quantization to further compress model size, default is False
3.1 Start Conversion
xxxxxxxxxxcd ~/yolo_train- Here we use the traffic sign recognition model trained in the previous section as an example for conversion (here replace the --MODEL_PATH path with your actual named .pt model path):
xxxxxxxxxxpython3 conver_model.py --MODEL_PATH /home/jetson/yolo_train/yolo11n.pt - After model conversion and export is completed, the terminal prompts
Export completeand the exported model path

- The best.engine in the output directory here is the exported TensorRT format model file

[!WARNING]
- Attention!!! TensorRT format models converted and exported on different GPU platforms are not universal due to different TensorRT versions.
- For example, TensorRT format models converted and exported on Jetson Orin NX cannot be used on Jetson Nano because the TensorRT versions on the two platforms are different.
4. Source Code Analysis
4.1 Model Conversion Program
The program source code is located at /home/jetson/yolo_train/conver_model.py
The program process is divided into:
- Parse parameters: args = get_args() reads parameters passed from command line, such as model path, export format, etc.
- Load model: model = YOLO(args.MODEL_PATH) loads YOLO pre-trained model from specified path.
- Export model: Call different export configurations based on whether INT8 quantization is enabled
ximport argparsefrom ultralytics import YOLOdef get_args(): ''' ''' parser = argparse.ArgumentParser() parser.add_argument('--project', default='./project', help='Project file output directory', type=str) parser.add_argument('--MODEL_PATH',default='/home/jetson/MODELS/yolov11/yolo11n.pt' ,help='原始模型权重文件路径Original model weight file path', type=str) parser.add_argument('--epochs', default=100, help='训练轮次Training rounds', type=int) parser.add_argument('--imgsz', default=640, help='图像大小Image size', type=int) parser.add_argument('--train_config', default='', help='配置文件路径Configuration file path', type=str) return parser.parse_args()if __name__ == "__main__": args = get_args() model = YOLO(args.MODEL_PATH) # load a pretrained model results = model.train(data=args.train_config, epochs=args.epochs, imgsz=args.imgsz,project=args.project)#start training