altametris.sara.yolo.exporter¶
YOLO exporter implementation.
Provides export functionality for YOLO models to various formats (ONNX, TensorRT, CoreML, etc.) with validation.
Example
>>> exporter = YoloExporter(model_path="weights/best.pt")
>>> onnx_path = exporter.export(format="onnx", imgsz=640)
>>> exporter.validate_export(onnx_path)
Attributes¶
Classes¶
YOLO exporter implementing BaseExporter interface. |
Module Contents¶
- altametris.sara.yolo.exporter.logger¶
- class altametris.sara.yolo.exporter.YoloExporter(model_path: str | pathlib.Path, output_dir: str | pathlib.Path | None = None)¶
Bases:
altametris.sara.core.base_exporter.BaseExporterYOLO exporter implementing BaseExporter interface.
Supports export to multiple formats via Ultralytics backend.
- Parameters:
model_path – Path to YOLO model weights
output_dir – Output directory for exports
Example
>>> exporter = YoloExporter(model_path="yolo11x.pt") >>> onnx_path = exporter.export(format="onnx", imgsz=640) >>> trt_path = exporter.export(format="tensorrt", imgsz=640, half=True)
- SUPPORTED_FORMATS = ['onnx', 'torchscript', 'tensorrt', 'coreml', 'tflite', 'engine']¶
- export(format: str = 'onnx', imgsz: int | tuple[int, int] = 640, half: bool = False, dynamic: bool = False, simplify: bool = True, **kwargs: Any) pathlib.Path¶
Export YOLO model to specified format.
- Parameters:
format – Export format
imgsz – Input image size (int or (height, width))
half – Use FP16 precision
dynamic – Dynamic axes for ONNX
simplify – Simplify ONNX model
**kwargs – Additional export arguments
- Returns:
Path to exported model
- Raises:
ExportError – If export fails
Example
>>> # Export to ONNX >>> exporter.export(format="onnx", imgsz=640, half=False) >>> >>> # Export to TensorRT >>> exporter.export(format="tensorrt", imgsz=640, half=True)
- validate_export(export_path: pathlib.Path, test_image: str | pathlib.Path | None = None, **kwargs: Any) bool¶
Validate exported model.
- Parameters:
export_path – Path to exported model
test_image – Optional test image for validation
**kwargs – Additional validation arguments
- Returns:
True if validation passes
- Raises:
ExportError – If validation fails
Example
>>> onnx_path = exporter.export(format="onnx") >>> exporter.validate_export(onnx_path, test_image="test.jpg")
- export_to_tensorrt(imgsz: int | tuple[int, int] = 640, half: bool = True, workspace: float = 4.0, **kwargs: Any) pathlib.Path¶
Export to TensorRT with optimized settings.
- Parameters:
imgsz – Input image size
half – Use FP16 precision
workspace – TensorRT workspace size (GB)
**kwargs – Additional TensorRT arguments
- Returns:
Path to TensorRT engine
Example
>>> trt_path = exporter.export_to_tensorrt(imgsz=640, half=True)
- export_to_onnx(imgsz: int | tuple[int, int] = 640, dynamic: bool = True, simplify: bool = True, **kwargs: Any) pathlib.Path¶
Export to ONNX with optimized settings.
- Parameters:
imgsz – Input image size
dynamic – Dynamic axes for variable input size
simplify – Simplify ONNX graph
**kwargs – Additional ONNX arguments
- Returns:
Path to ONNX model
Example
>>> onnx_path = exporter.export_to_onnx(imgsz=640, dynamic=True)
- __repr__() str¶
String representation.