Ultralytics Models¶
SAHI integrates with Ultralytics YOLO26, Ultralytics YOLO11, and Ultralytics YOLOv8, along with all other Ultralytics model variants (detection, segmentation, and oriented bounding boxes).
sahi.models.ultralytics
¶
Ultralytics detection model wrapper for SAHI.
Provides integration with Ultralytics YOLO models for object detection, instance segmentation, and oriented bounding box detection.
Classes¶
UltralyticsDetectionModel
¶
UltralyticsDetectionModel(
*args: object,
fuse: bool = False,
task: str | None = None,
**kwargs: object,
)
Bases: DetectionModel
Detection model for Ultralytics YOLO models.
Supports PyTorch (.pt), ONNX (.onnx), OpenVINO (.xml or _openvino_model/), NCNN (.param or _ncnn_model/), and TorchScript (.torchscript) models.
Initialize the Ultralytics detection model.
Accepts all arguments from DetectionModel.__init__ plus the
following keyword arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
object
|
Variable length argument list passed to DetectionModel. |
()
|
|
bool
|
If True, fuse Conv2d and BatchNorm2d layers for faster inference. Default: False. |
False
|
|
str | None
|
Ultralytics task type (e.g. |
None
|
|
object
|
Arbitrary keyword arguments passed to DetectionModel. |
{}
|
Source code in sahi/models/ultralytics.py
Attributes¶
category_names
property
¶
Returns the list of category names from the model.
Falls back to category_mapping values when model metadata is
unavailable (e.g. ONNX models without embedded names).
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither model names nor category_mapping are available. |
Methods:¶
load_model
¶
Detection model is initialized and set to self.model.
Source code in sahi/models/ultralytics.py
set_model
¶
Sets the underlying Ultralytics model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
¶ |
Any
|
Any A Ultralytics model |
required |
**kwargs
¶ |
Any
|
Any Additional keyword arguments for model setup. |
{}
|
Source code in sahi/models/ultralytics.py
perform_inference
¶
perform_inference(image: ndarray) -> None
Prediction is performed using self.model and the prediction result is set to self._original_predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
¶ |
ndarray
|
np.ndarray A numpy array that contains the image to be predicted. 3 channel image should be in RGB order. |
required |
Source code in sahi/models/ultralytics.py
perform_batch_inference
¶
perform_batch_inference(images: list[ndarray]) -> None
Performs inference on a batch of images using native YOLO batch support.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
¶ |
list[ndarray]
|
list[np.ndarray] List of numpy arrays (H, W, C) in RGB order. |
required |