dataeval.models.OnnxImageClassifier

class dataeval.models.OnnxImageClassifier(model_path, metadata_path, *, image_size=None, scores_name='scores')

Opinionated image classifier backed by ONNX Runtime.

Loads an exported .onnx image-classification 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 class scores. Calling the instance preprocesses each image to the model’s input contract (color layout, size, [0, 1] normalization), runs inference, and returns one (nClasses,) float32 score array per image. Requires dataeval[onnx].

Parameters:
model_path : str or Path

Path to the exported .onnx model file.

metadata_path : str or Path

Path to the model-metadata.json describing the input/output contract. Its declared task must be IMAGE_CLASSIFICATION.

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.

scores_name : str, default "scores"

Name of the model output tensor holding class scores.

Raises:

See also

LiteRtImageClassifier

Same classifier backed by LiteRT.

OnnxObjectDetector

Opinionated object detector backed by ONNX Runtime.

read_model_metadata

Parse the metadata contract.

Notes

Implements the MAITE image_classification.Model protocol: instances expose a ModelMetadata metadata attribute and are callable on a batch of images.

Examples

>>> from dataeval.models import OnnxImageClassifier
>>> classifier = OnnxImageClassifier(onnx_classifier_path, classifier_metadata_path)
>>> batch = [np.zeros((3, 16, 16), dtype=np.uint8), np.full((3, 16, 16), 255, dtype=np.uint8)]
>>> scores = classifier(batch)
>>> len(scores)
2
>>> scores[0].shape
(4,)