altametris.sara.yolo.model¶
YOLO model implementation.
Wrapper around Ultralytics YOLO with standardized Altametris interface. Supports YOLOv8 and YOLO11 for detection, segmentation, OBB, and pose tasks.
Example
>>> model = YoloModel(version="11", task="detect", size="x", pretrained=True)
>>> x = torch.randn(1, 3, 640, 640)
>>> output = model(x)
Attributes¶
Classes¶
YOLO model wrapper implementing BaseModel interface. |
Module Contents¶
- altametris.sara.yolo.model.logger¶
- class altametris.sara.yolo.model.YoloModel(model_path: str | pathlib.Path | None = None, version: str = '11', task: str = 'detect', size: str = 'x', pretrained: bool = False, device: str = 'auto', **kwargs: Any)¶
Bases:
altametris.sara.core.base_model.BaseModelYOLO model wrapper implementing BaseModel interface.
Provides standardized interface for YOLO models from Ultralytics with support for multiple versions, tasks, and sizes.
- Parameters:
model_path – Path to existing model weights (optional)
version – YOLO version (“11” or “v8”)
task – YOLO task (“detect”, “segment”, “obb”, “pose”, “classify”)
size – Model size (“n”, “s”, “m”, “l”, “x”)
pretrained – Load pretrained weights from Ultralytics
device – Device for model (“cpu”, “cuda”, “mps”, “auto”)
Example
>>> # Create from scratch >>> model = YoloModel(version="11", task="detect", size="x") >>> >>> # Load from weights >>> model = YoloModel(model_path="weights/best.pt")
- SUPPORTED_VERSIONS = ['11', 'v8']¶
- SUPPORTED_TASKS = ['detect', 'segment', 'obb', 'pose', 'classify']¶
- SUPPORTED_SIZES = ['n', 's', 'm', 'l', 'x']¶
- yolo: ultralytics.YOLO¶
- _validate_init_params(version: str, task: str, size: str, model_path: str | pathlib.Path | None, pretrained: bool) None¶
Validate initialization parameters.
- _get_model_name(version: str, task: str, size: str) str¶
Generate Ultralytics model name.
- Parameters:
version – YOLO version
task – Task type
size – Model size
- Returns:
Model name string (e.g., “yolo11x-seg.pt”)
- forward(x: torch.Tensor, **kwargs: Any) Any¶
Forward pass through YOLO model.
- Parameters:
x – Input tensor (B, C, H, W)
**kwargs – Additional forward arguments
- Returns:
Model output
Example
>>> x = torch.randn(1, 3, 640, 640) >>> output = model(x)
- load_weights(path: str | pathlib.Path, **kwargs: Any) None¶
Load weights from file.
- Parameters:
path – Path to weights file
**kwargs – Additional loading arguments
- Raises:
ModelError – If weights cannot be loaded
- save_weights(path: str | pathlib.Path, **kwargs: Any) None¶
Save model weights in Ultralytics checkpoint format.
This method uses the native Ultralytics save() API which creates a complete checkpoint file compatible with YOLO loading.
- Parameters:
path – Path to save weights
**kwargs – Additional saving arguments
Example
>>> model.save_weights("weights/my_model.pt")
Note
The saved file is a complete Ultralytics checkpoint that can be reloaded with YoloModel(model_path=path) or YOLO(path).
- property names: dict[int, str]¶
Get class names mapping.
- property task: str¶
Get model task.
- property version: str¶
Get YOLO version.
- __repr__() str¶
String representation.