altametris.sara.yolo.detector

YOLO detector implementation.

Provides inference interface for YOLO models with standardized input/output format and batch processing support.

Example

>>> detector = YoloDetector(model_path="weights/best.pt", task="detect")
>>> results = detector.predict(source="image.jpg", conf=0.25)

Attributes

Classes

YoloDetector

YOLO detector implementing BaseDetector interface.

Module Contents

altametris.sara.yolo.detector.logger
class altametris.sara.yolo.detector.YoloDetector(model_path: str | pathlib.Path, task: str = 'detect', device: str = 'auto', warmup: bool = True, **kwargs: Any)

Bases: altametris.sara.core.base_detector.BaseDetector

YOLO detector implementing BaseDetector interface.

Provides inference capabilities with support for images, videos, and batch processing.

Parameters:
  • model_path – Path to YOLO model weights

  • task – YOLO task (“detect”, “segment”, “obb”, “pose”)

  • device – Inference device

  • warmup – Run warmup on initialization

Example

>>> detector = YoloDetector(model_path="yolo11x.pt", device="cuda")
>>> results = detector.predict("image.jpg", conf=0.5, imgsz=640)
SUPPORTED_TASKS = ['detect', 'segment', 'obb', 'pose', 'classify']
task = 'detect'
model: ultralytics.YOLO
_load_model(model_path: pathlib.Path, **kwargs: Any) None

Load YOLO model from path.

Parameters:
  • model_path – Path to model file

  • **kwargs – Additional loading arguments

Raises:

ModelError – If model cannot be loaded

_validate_predict_params(conf: float, iou: float, imgsz: int) None

Validate prediction parameters before inference.

Parameters:
  • conf – Confidence threshold

  • iou – IoU threshold

  • imgsz – Image size

Raises:

ConfigurationError – If parameters are invalid

predict(source: str | pathlib.Path | numpy.typing.NDArray[numpy.uint8] | PIL.Image.Image | List[Any], conf: float = 0.25, iou: float = 0.45, imgsz: int = 640, verbose: bool = False, **kwargs: Any) Any

Run inference on source.

Parameters:
  • source – Input source (image path, array, PIL Image, or list)

  • conf – Confidence threshold

  • iou – IoU threshold for NMS

  • imgsz – Input image size

  • verbose – Verbose output

  • **kwargs – Additional inference arguments

Returns:

Ultralytics Results object(s)

Raises:

Example

>>> # Single image
>>> results = detector.predict("image.jpg", conf=0.5)
>>>
>>> # Batch of images
>>> results = detector.predict(["img1.jpg", "img2.jpg"], conf=0.5)
>>>
>>> # NumPy array
>>> img : NDArray[np.uint8] = np.random.rand(640, 640, 3).astype(np.uint8)
>>> results = detector.predict(img, conf=0.5)
predict_batch(sources: List[str | pathlib.Path | numpy.typing.NDArray[numpy.uint8]], batch_size: int = 32, **kwargs: Any) List[Any]

Run batch inference on multiple sources.

Parameters:
  • sources – List of input sources

  • batch_size – Batch size for processing

  • **kwargs – Additional inference arguments

Returns:

List of results for each source

Example

>>> images = ["img1.jpg", "img2.jpg", "img3.jpg"]
>>> results = detector.predict_batch(images, batch_size=8)
warmup(iterations: int = 3, imgsz: int = 640) None

Warmup model with dummy inference.

Parameters:
  • iterations – Number of warmup iterations

  • imgsz – Image size for warmup

Example

>>> detector.warmup(iterations=5, imgsz=640)
get_names() dict[int, str]

Get class names mapping.

Returns:

Dictionary mapping class IDs to names

Example

>>> names = detector.get_names()
>>> print(names[0])  # 'person'
property num_classes: int

Get number of classes.

__repr__() str

String representation.