Principle:Microsoft Onnxruntime ONNX Input Schema Definition
Metadata
| Field | Value |
|---|---|
| Principle Name | ONNX_Input_Schema_Definition |
| Repository | Microsoft_Onnxruntime |
| Source Repository | https://github.com/microsoft/onnxruntime |
| Domain | ML_Inference, Model_Conversion |
| Last Updated | 2026-02-10 |
| Workflow | Train_Convert_Predict |
| Pair | 2 of 5 |
Overview
Declaration of typed tensor specifications that describe the expected inputs for an ONNX model conversion.
Description
Before converting a model to ONNX format, the input schema must be explicitly defined using typed tensor descriptors. This schema maps input names to tensor types and shapes, enabling the converter to generate a correctly-typed ONNX graph.
This is a Wrapper Doc for skl2onnx, the scikit-learn to ONNX converter. The input schema definition is a required step that bridges the untyped scikit-learn model interface with the strongly-typed ONNX graph format.
The schema is defined as a list of tuples, where each tuple contains:
- Input name (str) -- A symbolic name for the input tensor (e.g.,
"float_input"). - Tensor type -- A typed tensor descriptor from
skl2onnx.common.data_types, specifying the element type and shape.
The shape specification uses None for dynamic dimensions (typically the batch dimension), allowing the converted model to accept variable-length inputs.
The schema definition pattern is demonstrated at docs/python/examples/plot_train_convert_predict.py:L53-55.
Theoretical Basis
The ONNX specification requires that all inputs and outputs be explicitly typed with tensor element types and shapes. This is a fundamental difference from frameworks like scikit-learn, where input types are inferred at runtime.
The FloatTensorType descriptor maps to ONNX's tensor(float) type (32-bit floating point). Other available types include:
DoubleTensorType-- Maps totensor(double)(64-bit floating point).Int64TensorType-- Maps totensor(int64)(64-bit integer).StringTensorType-- Maps totensor(string).
The shape specification [None, num_features] declares:
- First dimension (
None) -- Dynamic batch size, allowing the model to process any number of samples. - Second dimension (
num_features) -- Fixed feature count matching the training data dimensionality.
This explicit typing enables the ONNX Runtime to pre-allocate memory, optimize operator selection, and validate inputs at session creation time rather than at inference time.
Usage
The input schema is defined using FloatTensorType before calling the converter:
from skl2onnx.common.data_types import FloatTensorType
initial_type = [("float_input", FloatTensorType([None, 4]))]