Welcome to DOFBOT SE repository
8. Model Conversion
Model Conversion
Note: If you are using the factory-installed image, there is no need to set up the environment from scratch; the environment is already configured. Simply follow the tutorial to execute the corresponding commands to begin using the features.
1. Model Conversion
Based on the performance benchmarks provided by the Ultralytics team for various model formats, we have found that using TensorRT yields the best inference performance!
xxxxxxxxxxThe first time you use YOLOv11's export mode, it will automatically install certain dependencies; simply wait for this process to complete automatically.
2.1. CLI: pt → onnx, pt → ncnn
Convert PyTorch-format models into ONNX and NCNN formats.
xxxxxxxxxxcd ~/ultralytics/ultralytics/
Run the following command in the terminal:
xxxxxxxxxxyolo export model=yolo11n.pt format=onnx# yolo export model=yolo11n-seg.pt format=onnx# yolo export model=yolo11n-pose.pt format=onnx# yolo export model=yolo11n-cls.pt format=onnx# yolo export model=yolo11n-obb.pt format=onnxyolo export model=yolo11n.pt format=ncnn# yolo export model=yolo11n-seg.pt format=ncnn# yolo export model=yolo11n-pose.pt format=ncnn# yolo export model=yolo11n-cls.pt format=ncnn# yolo export model=yolo11n-obb.pt format=ncnn

2.2、Python:pt → onnx → ncnn
Converting a PyTorch model to TensorRT: The conversion process automatically generates an ONNX model.
xxxxxxxxxxcd ~/ultralytics/ultralytics/yahboom_demo
xxxxxxxxxxpython3 model_pt_onnx_ncnn.py

Sample Code:
xxxxxxxxxxfrom ultralytics import YOLO# Load a YOLO11n PyTorch modelmodel = YOLO("/home/yahboom/ultralytics/ultralytics/yolo11n.pt")# model = YOLO("/home/yahboom/ultralytics/ultralytics/yolo11n-seg.pt")# model = YOLO("/home/yahboom/ultralytics/ultralytics/yolo11n-pose.pt")# model = YOLO("/home/yahboom/ultralytics/ultralytics/yolo11n-cls.pt")# model = YOLO("/home/yahboom/ultralytics/ultralytics/yolo11n-obb.pt")# Export the model to ONNX formatmodel.export(format="onnx") # This will create 'yolo11n.onnx' in the same directory# Export the model to NCNN formatmodel.export(format="ncnn") # creates 'yolo11n_ncnn_model'3. Model Prediction
CLI Usage
The CLI currently supports only USB cameras!
xxxxxxxxxxcd ~/ultralytics/ultralytics/
xxxxxxxxxxyolo predict model=yolo11n.onnx source=0 save=False show

xxxxxxxxxxyolo predict model=yolo11n_ncnn_model source=0 save=False show
