dataeval.models.OnnxObjectDetector¶
-
class dataeval.models.OnnxObjectDetector(model_path, metadata_path, *, image_size=
None, boxes_name='boxes', scores_name='scores')¶ Opinionated object detector backed by ONNX Runtime.
Loads an exported
.onnxobject-detection model via ONNX Runtime (GPU when available, else CPU) together with its model-metadata.json contract, then maps a batch of CHW images to per-image detection targets. Calling the instance preprocesses each image to the model’s input contract (color layout, size,[0, 1]normalization), runs inference, and returns one detection target per image. Requiresdataeval[onnx].- Parameters:¶
- model_path : str or Path¶
Path to the exported
.onnxmodel file.- metadata_path : str or Path¶
Path to the model-metadata.json describing the input/output contract. Its declared task must be
IMAGE_OBJECT_DETECTION.- image_size : tuple[int, int] or None, default None¶
Optional
(height, width)override for the model’s input size. When set, images are resized to this size instead of the size declared in metadata; required when the metadata declares a variable (-1) dimension.- boxes_name : str, default "boxes"¶
Name of the model output tensor holding detection boxes.
- scores_name : str, default "scores"¶
Name of the model output tensor holding per-class detection scores.
- Raises:¶
ValueError – If the metadata declares a task other than
IMAGE_OBJECT_DETECTION.ImportError – If
onnxruntimeis not installed.FileNotFoundError – If
model_pathdoes not exist.
See also
LiteRtObjectDetectorSame detector backed by LiteRT.
OnnxImageClassifierOpinionated image classifier backed by ONNX Runtime.
read_model_metadataParse the metadata contract.
Notes
Implements the MAITE
object_detection.Modelprotocol: instances expose aModelMetadatametadataattribute and are callable on a batch of images, returning one MAITEObjectDetectionTargetper image (with labels taken as the argmax over each detection’s class scores).Examples
>>> from dataeval.models import OnnxObjectDetector >>> detector = OnnxObjectDetector(onnx_detector_path, detector_metadata_path) >>> targets = detector([np.zeros((3, 16, 16), dtype=np.uint8)]) >>> len(targets) 1 >>> targets[0].boxes.shape (5, 4) >>> targets[0].scores.shape (5, 4)