trtutils.image.interfaces module

Interaces for the image models.

Classes

ClassifierInterface

Interface for image classifiers.

DepthEstimatorInterface

Interface for depth estimators.

DetectorInterface

Interface for image detectors.

HandInteractionDetectorInterface

Interface for hand-object interaction detectors.

class trtutils.image.interfaces.ClassifierInterface[source]

Bases: ABC

Interface for image classifiers.

abstract property engine: TRTEngine

Get the underlying TRTEngine.

abstract property name: str

Get the name of the engine.

abstract property input_shape: tuple[int, int]

Get the input shape of the model.

abstract property dtype: np.dtype

Get the dtype required by the model.

abstractmethod preprocess(images: np.ndarray, resize: str | None = None, method: str | None = None, *, no_copy: bool | None = None, verbose: bool | None = None) → tuple[np.ndarray, list[tuple[float, float]], list[tuple[float, float]]][source]
abstractmethod preprocess(images: list[np.ndarray], resize: str | None = None, method: str | None = None, *, no_copy: bool | None = None, verbose: bool | None = None) → tuple[np.ndarray, list[tuple[float, float]], list[tuple[float, float]]]

Preprocess the input images.

abstractmethod postprocess(outputs: list[np.ndarray], *, no_copy: bool | None = None, verbose: bool | None = None) → list[np.ndarray] | list[list[np.ndarray]][source]

Postprocess the outputs.

abstractmethod run(images: list[np.ndarray], *, preprocessed: bool | None = None, postprocess: Literal[False], no_copy: bool | None = None, verbose: bool | None = None) → list[np.ndarray][source]
abstractmethod run(images: list[np.ndarray], *, preprocessed: bool | None = None, postprocess: Literal[True] | None = None, no_copy: bool | None = None, verbose: bool | None = None) → list[list[np.ndarray]]
abstractmethod run(images: list[np.ndarray], *, preprocessed: bool | None = None, postprocess: bool | None = None, no_copy: bool | None = None, verbose: bool | None = None) → list[np.ndarray] | list[list[np.ndarray]]
abstractmethod run(images: np.ndarray, *, preprocessed: bool | None = None, postprocess: Literal[False], no_copy: bool | None = None, verbose: bool | None = None) → list[np.ndarray]
abstractmethod run(images: np.ndarray, *, preprocessed: bool | None = None, postprocess: Literal[True] | None = None, no_copy: bool | None = None, verbose: bool | None = None) → list[np.ndarray]
abstractmethod run(images: np.ndarray, *, preprocessed: bool | None = None, postprocess: bool | None = None, no_copy: bool | None = None, verbose: bool | None = None) → list[np.ndarray]

Run the model on input.

abstractmethod get_classifications(outputs: list[np.ndarray], top_k: int = 5, *, verbose: bool | None = None) → list[tuple[int, float]][source]
abstractmethod get_classifications(outputs: list[list[np.ndarray]], top_k: int = 5, *, verbose: bool | None = None) → list[list[tuple[int, float]]]

Get the classifications for each image.

abstractmethod end2end(images: np.ndarray, top_k: int = 5, *, verbose: bool | None = None) → list[tuple[int, float]][source]
abstractmethod end2end(images: list[np.ndarray], top_k: int = 5, *, verbose: bool | None = None) → list[list[tuple[int, float]]]

Perform end to end inference for a batch of images.

class trtutils.image.interfaces.DepthEstimatorInterface[source]

Bases: ABC

Interface for depth estimators.

abstract property engine: TRTEngine

Get the underlying TRTEngine.

abstract property name: str

Get the name of the engine.

abstract property input_shape: tuple[int, int]

Get the input shape of the model.

abstract property dtype: np.dtype

Get the dtype required by the model.

abstractmethod preprocess(images: np.ndarray, resize: str | None = None, method: str | None = None, *, no_copy: bool | None = None, verbose: bool | None = None) → tuple[np.ndarray, list[tuple[float, float]], list[tuple[float, float]]][source]
abstractmethod preprocess(images: list[np.ndarray], resize: str | None = None, method: str | None = None, *, no_copy: bool | None = None, verbose: bool | None = None) → tuple[np.ndarray, list[tuple[float, float]], list[tuple[float, float]]]

Preprocess the input images.

abstractmethod postprocess(outputs: list[np.ndarray], *, no_copy: bool | None = None, verbose: bool | None = None) → list[np.ndarray] | list[list[np.ndarray]][source]

Postprocess the outputs.

abstractmethod run(images: list[np.ndarray], *, preprocessed: bool | None = None, postprocess: Literal[False], no_copy: bool | None = None, verbose: bool | None = None) → list[np.ndarray][source]
abstractmethod run(images: list[np.ndarray], *, preprocessed: bool | None = None, postprocess: Literal[True] | None = None, no_copy: bool | None = None, verbose: bool | None = None) → list[list[np.ndarray]]
abstractmethod run(images: list[np.ndarray], *, preprocessed: bool | None = None, postprocess: bool | None = None, no_copy: bool | None = None, verbose: bool | None = None) → list[np.ndarray] | list[list[np.ndarray]]
abstractmethod run(images: np.ndarray, *, preprocessed: bool | None = None, postprocess: Literal[False], no_copy: bool | None = None, verbose: bool | None = None) → list[np.ndarray]
abstractmethod run(images: np.ndarray, *, preprocessed: bool | None = None, postprocess: Literal[True] | None = None, no_copy: bool | None = None, verbose: bool | None = None) → list[np.ndarray]
abstractmethod run(images: np.ndarray, *, preprocessed: bool | None = None, postprocess: bool | None = None, no_copy: bool | None = None, verbose: bool | None = None) → list[np.ndarray]

Run the model on input.

abstractmethod get_depth_maps(outputs: list[np.ndarray], *, verbose: bool | None = None) → np.ndarray[source]
abstractmethod get_depth_maps(outputs: list[list[np.ndarray]], *, verbose: bool | None = None) → list[np.ndarray]

Get the depth maps for each image.

abstractmethod end2end(images: np.ndarray, *, verbose: bool | None = None) → np.ndarray[source]
abstractmethod end2end(images: list[np.ndarray], *, verbose: bool | None = None) → list[np.ndarray]

Perform end to end inference for a batch of images.

class trtutils.image.interfaces.HandInteractionDetectorInterface[source]

Bases: ABC

Interface for hand-object interaction detectors.

Implementations wrap engines following the unified hand-object interaction output contract: [boxes (B,K,4), scores (B,K), labels (B,K), pair_probs (B,K,K,C), side (B,K)]; side is optional. Postprocessed per-image outputs pair hands (label 0) with a first object (label 1) and optionally a second object (label 2) into HandInteraction tuples of the form ((hand_bbox, hand_score), (obj_bbox, obj_score) | None, (second_bbox, second_score) | None, side | None, contact | None), where each bbox is an int (x1, y1, x2, y2) in original image coordinates.

abstract property engine: TRTEngine

Get the underlying TRTEngine.

abstract property name: str

Get the name of the engine.

abstract property input_shape: tuple[int, int]

Get the input shape of the model.

abstract property dtype: np.dtype

Get the dtype required by the model.

abstractmethod preprocess(images: np.ndarray, resize: str | None = None, method: str | None = None, *, no_copy: bool | None = None, verbose: bool | None = None) → tuple[np.ndarray, list[tuple[float, float]], list[tuple[float, float]]][source]
abstractmethod preprocess(images: list[np.ndarray], resize: str | None = None, method: str | None = None, *, no_copy: bool | None = None, verbose: bool | None = None) → tuple[np.ndarray, list[tuple[float, float]], list[tuple[float, float]]]

Preprocess the input images.

abstractmethod postprocess(outputs: list[np.ndarray], ratios: list[tuple[float, float]], padding: list[tuple[float, float]], conf_thres: float | None = None, *, no_copy: bool | None = None, verbose: bool | None = None) → list[np.ndarray] | list[list[np.ndarray]][source]

Postprocess the outputs.

abstractmethod run(images: list[np.ndarray], ratios: list[tuple[float, float]] | None = None, padding: list[tuple[float, float]] | None = None, conf_thres: float | None = None, *, preprocessed: bool | None = None, postprocess: Literal[False], no_copy: bool | None = None, verbose: bool | None = None) → list[np.ndarray][source]
abstractmethod run(images: list[np.ndarray], ratios: list[tuple[float, float]] | None = None, padding: list[tuple[float, float]] | None = None, conf_thres: float | None = None, *, preprocessed: bool | None = None, postprocess: Literal[True] | None = None, no_copy: bool | None = None, verbose: bool | None = None) → list[list[np.ndarray]]
abstractmethod run(images: list[np.ndarray], ratios: list[tuple[float, float]] | None = None, padding: list[tuple[float, float]] | None = None, conf_thres: float | None = None, *, preprocessed: bool | None = None, postprocess: bool | None = None, no_copy: bool | None = None, verbose: bool | None = None) → list[np.ndarray] | list[list[np.ndarray]]
abstractmethod run(images: np.ndarray, ratios: tuple[float, float] | None = None, padding: tuple[float, float] | None = None, conf_thres: float | None = None, *, preprocessed: bool | None = None, postprocess: Literal[False], no_copy: bool | None = None, verbose: bool | None = None) → list[np.ndarray]
abstractmethod run(images: np.ndarray, ratios: tuple[float, float] | None = None, padding: tuple[float, float] | None = None, conf_thres: float | None = None, *, preprocessed: bool | None = None, postprocess: Literal[True] | None = None, no_copy: bool | None = None, verbose: bool | None = None) → list[np.ndarray]
abstractmethod run(images: np.ndarray, ratios: tuple[float, float] | None = None, padding: tuple[float, float] | None = None, conf_thres: float | None = None, *, preprocessed: bool | None = None, postprocess: bool | None = None, no_copy: bool | None = None, verbose: bool | None = None) → list[np.ndarray]

Run the model on input.

abstractmethod get_interactions(outputs: list[np.ndarray], pair_thres: float | None = None, second_pair_thres: float | None = None, *, verbose: bool | None = None) → list[HandInteraction][source]
abstractmethod get_interactions(outputs: list[list[np.ndarray]], pair_thres: float | None = None, second_pair_thres: float | None = None, *, verbose: bool | None = None) → list[list[HandInteraction]]

Get the hand-object interactions for each image.

abstractmethod end2end(images: np.ndarray, *, conf_thres: float | None = None, pair_thres: float | None = None, second_pair_thres: float | None = None, verbose: bool | None = None) → list[HandInteraction][source]
abstractmethod end2end(images: list[np.ndarray], *, conf_thres: float | None = None, pair_thres: float | None = None, second_pair_thres: float | None = None, verbose: bool | None = None) → list[list[HandInteraction]]

Perform end to end inference for a batch of images.

class trtutils.image.interfaces.DetectorInterface[source]

Bases: ABC

Interface for image detectors.

abstract property engine: TRTEngine

Get the underlying TRTEngine.

abstract property name: str

Get the name of the engine.

abstract property input_shape: tuple[int, int]

Get the input shape of the model.

abstract property dtype: np.dtype

Get the dtype required by the model.

abstract property input_schema: InputSchema

Get the input schema used by this detector.

abstract property output_schema: OutputSchema

Get the output schema used by this detector.

abstractmethod preprocess(images: np.ndarray, resize: str | None = None, method: str | None = None, *, no_copy: bool | None = None, verbose: bool | None = None) → tuple[np.ndarray, list[tuple[float, float]], list[tuple[float, float]]][source]
abstractmethod preprocess(images: list[np.ndarray], resize: str | None = None, method: str | None = None, *, no_copy: bool | None = None, verbose: bool | None = None) → tuple[np.ndarray, list[tuple[float, float]], list[tuple[float, float]]]

Preprocess the input images.

abstractmethod postprocess(outputs: list[np.ndarray], ratios: list[tuple[float, float]], padding: list[tuple[float, float]], conf_thres: float | None = None, *, no_copy: bool | None = None, verbose: bool | None = None) → list[np.ndarray] | list[list[np.ndarray]][source]

Postprocess the outputs.

abstractmethod run(images: list[np.ndarray], ratios: list[tuple[float, float]] | None = None, padding: list[tuple[float, float]] | None = None, conf_thres: float | None = None, *, preprocessed: bool | None = None, postprocess: Literal[False], no_copy: bool | None = None, verbose: bool | None = None) → list[np.ndarray][source]
abstractmethod run(images: list[np.ndarray], ratios: list[tuple[float, float]] | None = None, padding: list[tuple[float, float]] | None = None, conf_thres: float | None = None, *, preprocessed: bool | None = None, postprocess: Literal[True] | None = None, no_copy: bool | None = None, verbose: bool | None = None) → list[list[np.ndarray]]
abstractmethod run(images: list[np.ndarray], ratios: list[tuple[float, float]] | None = None, padding: list[tuple[float, float]] | None = None, conf_thres: float | None = None, *, preprocessed: bool | None = None, postprocess: bool | None = None, no_copy: bool | None = None, verbose: bool | None = None) → list[np.ndarray] | list[list[np.ndarray]]
abstractmethod run(images: np.ndarray, ratios: tuple[float, float] | None = None, padding: tuple[float, float] | None = None, conf_thres: float | None = None, *, preprocessed: bool | None = None, postprocess: Literal[False], no_copy: bool | None = None, verbose: bool | None = None) → list[np.ndarray]
abstractmethod run(images: np.ndarray, ratios: tuple[float, float] | None = None, padding: tuple[float, float] | None = None, conf_thres: float | None = None, *, preprocessed: bool | None = None, postprocess: Literal[True] | None = None, no_copy: bool | None = None, verbose: bool | None = None) → list[np.ndarray]
abstractmethod run(images: np.ndarray, ratios: tuple[float, float] | None = None, padding: tuple[float, float] | None = None, conf_thres: float | None = None, *, preprocessed: bool | None = None, postprocess: bool | None = None, no_copy: bool | None = None, verbose: bool | None = None) → list[np.ndarray]

Run the model on input.

abstractmethod get_detections(outputs: list[np.ndarray], conf_thres: float | None = None, nms_iou_thres: float | None = None, *, extra_nms: bool | None = None, agnostic_nms: bool | None = None, verbose: bool | None = None) → list[tuple[tuple[int, int, int, int], float, int]][source]
abstractmethod get_detections(outputs: list[list[np.ndarray]], conf_thres: float | None = None, nms_iou_thres: float | None = None, *, extra_nms: bool | None = None, agnostic_nms: bool | None = None, verbose: bool | None = None) → list[list[tuple[tuple[int, int, int, int], float, int]]]

Get the detections for each image.

abstractmethod end2end(images: np.ndarray, conf_thres: float | None = None, nms_iou_thres: float | None = None, *, extra_nms: bool | None = None, agnostic_nms: bool | None = None, verbose: bool | None = None) → list[tuple[tuple[int, int, int, int], float, int]][source]
abstractmethod end2end(images: list[np.ndarray], conf_thres: float | None = None, nms_iou_thres: float | None = None, *, extra_nms: bool | None = None, agnostic_nms: bool | None = None, verbose: bool | None = None) → list[list[tuple[tuple[int, int, int, int], float, int]]]

Perform end to end inference for a batch of images.