from ultralytics import YOLO
# Load a model
model = YOLO("yolov8n.pt") # load an official model
model = YOLO("path/to/best.pt") # load a custom trained model
# Export the model
model.export(format="onnx")
yolo export model=yolov8n.pt format=onnx # export official model
yolo export model=path/to/best.pt format=onnx # export custom trained model
Arguments 参数
Argument | Type | Default | Description |
|
|
| Target format for the exported model, such as 导出模型的目标格式,如 |
|
or |
| Desired image size for the model input. Can be an integer for square images or a tuple for specific dimensions. 模型输入所需的图像大小。对于方形图像可以是整数,对于特定维度可以是元组 |
|
|
| Enables export to Keras format for TensorFlow SavedModel, providing compatibility with TensorFlow serving and APIs. 支持将TensorFlow SavedModel导出为Keras格式,提供与TensorFlow服务和api的兼容性。 |
|
|
| Applies optimization for mobile devices when exporting to TorchScript, potentially reducing model size and improving performance. 在导出到TorchScript时,适用于移动设备的优化,可能会减小模型尺寸并提高性能。 |
|
|
| Enables FP16 (half-precision) quantization, reducing model size and potentially speeding up inference on supported hardware. 支持FP16(半精度)量化,减少模型尺寸,并可能加快对支持硬件的推理。 |
|
|
| Activates INT8 quantization, further compressing the model and speeding up inference with minimal accuracy loss, primarily for edge devices. 激活INT8量化,进一步压缩模型并以最小的精度损失加速推理,主要用于边缘设备。 |
|
|
| Allows dynamic input sizes for ONNX and TensorRT exports, enhancing flexibility in handling varying image dimensions. 允许ONNX和TensorRT导出的动态输入大小,增强处理不同图像尺寸的灵活性。 |
|
|
| Simplifies the model graph for ONNX exports with 使用 |
|
|
| Specifies the ONNX opset version for compatibility with different ONNX parsers and runtimes. If not set, uses the latest supported version. 指定ONNX opset版本,以便与不同的ONNX解析器和运行时兼容。如果没有设置,则使用支持的最新版本。 |
|
|
| Sets the maximum workspace size in GiB for TensorRT optimizations, balancing memory usage and performance. 为TensorRT优化设置GiB中的最大工作空间大小,平衡内存使用和性能。 |
|
|
| Adds Non-Maximum Suppression (NMS) to the CoreML export, essential for accurate and efficient detection post-processing. 将非最大抑制(NMS)添加到CoreML导出中,这对于准确有效的检测后处理至关重要。 |
|
|
| Specifies export model batch inference size or the max number of images the exported model will process concurrently in 指定导出模型批推理大小或导出模型将在 |
Export Formats 导出格式
Format 格式 |
| Model 模型 | Metadata 元数据 | Arguments 参数 |
- |
| ✅ | - | |
|
| ✅ |
| |
|
| ✅ |
| |
|
| ✅ |
| |
|
| ✅ |
| |
|
| ✅ |
| |
|
| ✅ |
| |
|
| ❌ |
| |
|
| ✅ |
| |
|
| ✅ |
| |
|
| ✅ |
| |
|
| ✅ |
| |
|
| ✅ |
|