class documentation
class Input(BaseModelExtraForbid):
Model input stream definition.
| Static Method | infer |
Infer the layout when a shape is provided without one. |
| Method | validate |
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 |
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: @staticmethod
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[ | Raw input model data. |
| Returns | |
dict[ | Raw model data with layout added when inference succeeds. |
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 | |
Self | The validated input model. |
| Raises | |
ValueError | If 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. |