libreyolo.LIBREYOLOOnnx¶
- class libreyolo.LIBREYOLOOnnx[source]¶
Bases:
objectONNX runtime inference backend for LIBREYOLO models.
Provides the same API as LIBREYOLO8/LIBREYOLO11 but uses ONNX Runtime instead of PyTorch for inference.
- Parameters:
onnx_path – Path to the ONNX model file.
nb_classes – Number of classes (default: 80 for COCO).
device – Device for inference. “auto” (default) uses CUDA if available, else CPU.
Example
>>> model = LIBREYOLOOnnx("model.onnx") >>> detections = model("image.jpg", save=True)
Methods
__init__(onnx_path[, nb_classes, device])predict(image[, save, output_path, ...])Alias for __call__ method.
- __call__(image, save=False, output_path=None, conf_thres=0.25, iou_thres=0.45, color_format='auto', batch_size=1)[source]¶
Run inference on an image or directory of images.
- Parameters:
image (str | Path | Image | ndarray) – Input image or directory (file path, directory path, PIL Image, or numpy array).
save (bool) – If True, saves annotated image to disk.
output_path (str) – Optional path to save the annotated image.
conf_thres (float) – Confidence threshold (default: 0.25).
iou_thres (float) – IoU threshold for NMS (default: 0.45).
color_format (str) – Color format hint for NumPy/OpenCV arrays (“auto”, “rgb”, “bgr”).
batch_size (int) – Number of images to process per batch when handling multiple images (e.g., directories). Currently used for chunking at the Python level; true batched model inference is planned for future versions. Default: 1 (process one image at a time).
- Returns:
Dictionary with boxes, scores, classes, source, and num_detections. For directory: List of dictionaries, one per image processed.
- Return type:
For single image
- predict(image, save=False, output_path=None, conf_thres=0.25, iou_thres=0.45, color_format='auto', batch_size=1)[source]¶
Alias for __call__ method.
- Parameters:
image (str | Path | Image | ndarray) – Input image or directory.
save (bool) – If True, saves annotated image to disk.
output_path (str) – Optional path to save the annotated image.
conf_thres (float) – Confidence threshold (default: 0.25).
iou_thres (float) – IoU threshold for NMS (default: 0.45).
color_format (str) – Color format hint for NumPy/OpenCV arrays.
batch_size (int) – Number of images to process per batch when handling multiple images (e.g., directories). Default: 1.
- Returns:
Dictionary containing detection results. For directory: List of dictionaries, one per image processed.
- Return type:
For single image