class documentation

class Input(BaseModelExtraForbid):

View In Hierarchy

Model input stream definition.

Static Method infer_layout Infer the layout when a shape is provided without one.
Method validate_layout Validate that the layout is compatible with the input shape.
Instance Variable dtype Data type of the input data, such as "float32".
Instance Variable input_type Expected kind of input data, such as "image".
Instance Variable layout Letter code for interpreting tensor dimensions, such as "NCHW".
Instance Variable name Name of the input layer.
Instance Variable preprocessing Preprocessing applied to the input data.
Instance Variable shape Input tensor shape.
@model_validator(mode='before')
@staticmethod
def infer_layout(data: dict[str, Any]) -> dict[str, Any]:

Infer the layout when a shape is provided without one.

Examples

>>> Input.infer_layout({"shape": [1, 3, 224, 224]})["layout"]
'NCHW'
>>> Input.infer_layout({"shape": [1, 3, 16, 16, 2]})
{'shape': [1, 3, 16, 16, 2], 'layout': 'NCDEF'}
>>> "layout" in Input.infer_layout({"shape": [1] * 30})
False
Parameters
data:dict[str, Any]Raw input model data.
Returns
dict[str, Any]Raw model data with layout added when inference succeeds.
@model_validator(mode='after')
def validate_layout(self) -> Self:

Validate that the layout is compatible with the input shape.

The layout must be a one-to-one description of the shape, so |layout| = |shape|. When N is present it denotes batch size and must be first. Image inputs must include a channel dimension C.

Returns
SelfThe validated input model.
Raises
ValueErrorIf the layout contains duplicate letters, its length does not match the shape length, N is present but not first, or image input has no C dimension.
dtype: DataType =

Data type of the input data, such as "float32".

input_type: InputType =

Expected kind of input data, such as "image".

layout: str =

Letter code for interpreting tensor dimensions, such as "NCHW".

name: str =

Name of the input layer.

preprocessing: PreprocessingBlock =

Preprocessing applied to the input data.

shape: list[int] =

Input tensor shape.