dataeval.models.build_model_input¶
-
dataeval.models.build_model_input(images, spec, *, height=
None, width=None)¶ Build the opinionated
imageinput tensor for a CV model.Each input image is normalized, converted to the color layout declared by
spec, resized to the target(height, width), and stacked into a single batched FP32 tensor. Integer pixels are assumed 8-bit[0, 255]and scaled to[0, 1]; float images are assumed already normalized and passed through unchanged.- Parameters:¶
- images : Sequence[ArrayLike]¶
Images in CHW (channels, height, width) layout. Each may have a different spatial size; all are resized to the resolved target size.
- spec : ModelIOSpec¶
Model input/output contract, typically from
read_model_metadata(). Supplies the target color layout and the defaultheight/width.- height : int or None, default None¶
Target height override. Required when
spec.heightis-1(variable); otherwise overrides the spec value when set.- width : int or None, default None¶
Target width override. Required when
spec.widthis-1(variable); otherwise overrides the spec value when set.
- Returns:¶
Batched tensor of shape
(B, C, H, W)with values in[0, 1], whereBislen(images)andCis 3 for"RGB"or 1 for"GRAYSCALE".- Return type:¶
NDArray[np.float32]
- Raises:¶
ValueError – If the resolved height or width is variable (
-1) with no override, if an image is not 3-dimensional (CHW), or if its channel count cannot be converted to the target layout.
See also
ModelIOSpecThe input/output contract consumed here.
Examples
>>> import numpy as np >>> spec = ModelIOSpec( ... task="IMAGE_CLASSIFICATION", ... channels="RGB", ... height=8, ... width=8, ... batch_size=-1, ... n_classes=4, ... ) >>> images = [np.zeros((3, 16, 16), dtype=np.uint8), np.full((3, 12, 20), 255, dtype=np.uint8)] >>> tensor = build_model_input(images, spec) >>> tensor.shape (2, 3, 8, 8) >>> tensor.dtype dtype('float32')