Skip to content

onnx

onnx

Attributes

__all__ module-attribute

__all__ = ['YOLODetectionMixin', 'YOLOv5DetectionPipeline']

Classes

YOLODetectionMixin

Shared YOLOv5 detection logic (ONNX version).

Attributes
image_size instance-attribute
image_size: tuple[int, int]
stride instance-attribute
stride: int
conf_threshold instance-attribute
conf_threshold: float
iou_threshold instance-attribute
iou_threshold: float
class_names instance-attribute
class_names: dict[int, str]

YOLOv5DetectionPipeline

YOLOv5DetectionPipeline(runtime: ONNXRuntime, image_size: tuple[int, int] = (640, 640), stride: int = 32, conf_threshold: float = 0.25, iou_threshold: float = 0.45, class_names: dict[int, str] | None = None, batch_strategy: BatchStrategy[ndarray, tuple[ndarray, ...] | ndarray] | None = None)

Bases: YOLODetectionMixin, Pipeline[ndarray, tuple[ndarray, ...] | ndarray, list[DetectionOutput]]

YOLOv5 object detection pipeline (ONNX version).

Source code in inferflow/pipeline/detection/onnx.py
def __init__(
    self,
    runtime: ONNXRuntime,
    image_size: tuple[int, int] = (640, 640),
    stride: int = 32,
    conf_threshold: float = 0.25,
    iou_threshold: float = 0.45,
    class_names: dict[int, str] | None = None,
    batch_strategy: BatchStrategy[np.ndarray, tuple[np.ndarray, ...] | np.ndarray] | None = None,
):
    super().__init__(runtime=runtime, batch_strategy=batch_strategy)

    self.image_size = image_size
    self.stride = stride
    self.conf_threshold = conf_threshold
    self.iou_threshold = iou_threshold
    self.class_names = class_names or {}

    self._runtime = runtime

    self._original_size = None
    self._padding = None
Attributes
image_size instance-attribute
image_size = image_size
stride instance-attribute
stride = stride
conf_threshold instance-attribute
conf_threshold = conf_threshold
iou_threshold instance-attribute
iou_threshold = iou_threshold
class_names instance-attribute
class_names = class_names or {}
Functions
preprocess
preprocess(input: ImageInput) -> ndarray

Preprocess image input.

Source code in inferflow/pipeline/detection/onnx.py
def preprocess(self, input: ImageInput) -> np.ndarray:
    """Preprocess image input."""
    image = self._convert_to_numpy(input)
    return self._preprocess_numpy(image)
postprocess
postprocess(raw: tuple[ndarray, ...] | ndarray) -> list[DetectionOutput]

Postprocess YOLOv5 output.

Source code in inferflow/pipeline/detection/onnx.py
def postprocess(self, raw: tuple[np.ndarray, ...] | np.ndarray) -> list[DetectionOutput]:
    """Postprocess YOLOv5 output."""
    predictions = raw if isinstance(raw, np.ndarray) else raw[0]
    return self._postprocess_detections(predictions)

Functions