pixano_inference.schemas.nd_array
Pydantic models for N-dimensional arrays.
This is a core, framework-agnostic wire type. It converts to and from numpy.ndarray
only; conversions to framework tensors live in the model packages (e.g.
pixano_inference_torch for PyTorch), so the core does not privilege any one framework.
Arrays serialize as {shape, dtype, data} where data is the base64-encoded raw bytes
of the array (compact and cheap to parse, unlike a JSON list of floats — important for
SAM2-scale embeddings).
NDArray(**data)
Bases: BaseModel, Generic[T], ABC
Represents an N-dimensional array serialized as base64-encoded raw bytes.
Attributes:
| Name | Type | Description |
|---|---|---|
shape |
list[int]
|
The shape of the array. |
dtype |
str
|
The numpy dtype name (informational; the concrete subclass fixes it). |
data |
str
|
Base64-encoded raw bytes of the (C-contiguous) array. |
Source code in pydantic/main.py
from_numpy(arr)
classmethod
Create an instance from a NumPy array (cast to the subclass dtype).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
ndarray
|
The NumPy array to convert. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
An instance holding the array's shape and base64-encoded bytes. |
Source code in pixano_inference/schemas/nd_array.py
to_numpy()
Convert the instance to a NumPy array.
Returns:
| Type | Description |
|---|---|
ndarray
|
A NumPy array with the stored shape and dtype. |
Source code in pixano_inference/schemas/nd_array.py
NDArrayFloat(**data)
Bases: NDArray[float]
An N-dimensional array of 32-bit floating-point values.