Skip to content

types

types

Attributes

ImageInput module-attribute

ImageInput: TypeAlias = Union[ndarray, NDArray[uint8], Image, Tensor, bytes]

Supported image input types. Includes:

  • numpy ndarray (H, W, C) in BGR format
  • PIL Image
  • torch Tensor (C, H, W) or (1, C, H, W)
  • bytes (encoded image data)

P module-attribute

P = TypeVar('P')

Preprocessed input type.

R module-attribute

R = TypeVar('R')

Raw inference result type.

O module-attribute

O = TypeVar('O')

Final output type after postprocessing.

__all__ module-attribute

__all__ = ['P', 'R', 'O', 'DeviceType', 'Device', 'Box', 'ClassificationOutput', 'DetectionOutput', 'SegmentationOutput', 'Precision']

Classes

DeviceType

Bases: str, Enum

Attributes
CPU class-attribute instance-attribute
CPU = 'cpu'
CUDA class-attribute instance-attribute
CUDA = 'cuda'
MPS class-attribute instance-attribute
MPS = 'mps'
NPU class-attribute instance-attribute
NPU = 'npu'

Device

Device(device: str | DeviceType, index: int = 0)
Source code in inferflow/types.py
def __init__(self, device: str | DeviceType, index: int = 0):
    if isinstance(device, str):
        device = DeviceType(device)
    self.type = device
    self.index = index
Attributes
type instance-attribute
type = device
index instance-attribute
index = index
Functions
__str__
__str__() -> str
Source code in inferflow/types.py
def __str__(self) -> str:
    if self.type == DeviceType.CPU:
        return "cpu"
    return f"{self.type.value}:{self.index}"
__repr__
__repr__() -> str
Source code in inferflow/types.py
def __repr__(self) -> str:
    return f"Device({self.type.value}, {self.index})"

Box

Box(xc: float, yc: float, w: float, h: float)

Bounding box representation (center + width/height).

Source code in inferflow/types.py
def __init__(self, xc: float, yc: float, w: float, h: float):
    self.xc = xc
    self.yc = yc
    self.w = w
    self.h = h
Attributes
__slots__ class-attribute instance-attribute
__slots__ = ('xc', 'yc', 'w', 'h')
xc instance-attribute
xc = xc
yc instance-attribute
yc = yc
w instance-attribute
w = w
h instance-attribute
h = h
Functions
to_xyxy
to_xyxy() -> tuple[float, float, float, float]

Convert to (x1, y1, x2, y2) format.

Source code in inferflow/types.py
def to_xyxy(self) -> tuple[float, float, float, float]:
    """Convert to (x1, y1, x2, y2) format."""
    x1 = self.xc - self.w / 2
    y1 = self.yc - self.h / 2
    x2 = self.xc + self.w / 2
    y2 = self.yc + self.h / 2
    return x1, y1, x2, y2
to_xywh
to_xywh() -> tuple[float, float, float, float]

Convert to (x, y, w, h) format (top-left).

Source code in inferflow/types.py
def to_xywh(self) -> tuple[float, float, float, float]:
    """Convert to (x, y, w, h) format (top-left)."""
    x = self.xc - self.w / 2
    y = self.yc - self.h / 2
    return x, y, self.w, self.h

ClassificationOutput

Bases: NamedTuple

Classification result.

Attributes
class_id instance-attribute
class_id: int

Predicted class ID.

confidence instance-attribute
confidence: float

Confidence score (0-1).

class_name class-attribute instance-attribute
class_name: str | None = None

Human-readable class name.

DetectionOutput

Bases: NamedTuple

Single object detection result.

Attributes
box instance-attribute
box: Box

Bounding box.

class_id instance-attribute
class_id: int

Predicted class ID.

confidence instance-attribute
confidence: float

Confidence score (0-1).

class_name class-attribute instance-attribute
class_name: str | None = None

Human-readable class name.

SegmentationOutput

Bases: NamedTuple

Single instance segmentation result.

Attributes
mask instance-attribute
mask: ndarray

Binary mask (H, W).

box instance-attribute
box: Box

Bounding box.

class_id instance-attribute
class_id: int

Predicted class ID.

confidence instance-attribute
confidence: float

Confidence score (0-1).

class_name class-attribute instance-attribute
class_name: str | None = None

Human-readable class name.

Precision

Bases: str, Enum

Model precision.

Attributes
FP32 class-attribute instance-attribute
FP32 = 'fp32'
FP16 class-attribute instance-attribute
FP16 = 'fp16'
INT8 class-attribute instance-attribute
INT8 = 'int8'