yobx.litert.to_onnx#
- yobx.litert.to_onnx(model: str | ~os.PathLike[str] | bytes, args: ~typing.Tuple[~typing.Any, ...], input_names: ~typing.Sequence[str] | None = None, dynamic_shapes: ~typing.Tuple[~typing.Dict[int, str], ...] | None = None, target_opset: int | ~typing.Dict[str, int] = 21, builder_cls: type | ~typing.Callable = <class 'yobx.xbuilder.graph_builder.GraphBuilder'>, verbose: int = 0, extra_converters: ~typing.Dict[int, ~typing.Callable] | None = None, large_model: bool = False, external_threshold: int = 1024, subgraph_index: int = 0) ExportArtifact[source]#
Convert a TFLite/LiteRT model to ONNX.
The function parses the binary FlatBuffer that every
.tflitefile uses and walks every operator in the requested subgraph. Each operator is converted to its ONNX equivalent by a registered converter (seeyobx.litert.register).- Parameters:
model – path to a
.tflitefile or raw model bytesargs – dummy inputs (numpy arrays or
onnx.ValueInfoProtodescriptors); used to determine dtypes and shapes when the model does not carry that information.input_names – optional list of names for the ONNX input tensors; defaults to the tensor names stored inside the TFLite model.
dynamic_shapes – optional per-input axis-to-dim-name mappings. When None, axis 0 is treated as a dynamic batch dimension.
target_opset – opset version; either an integer for the default domain (
"") or aDict[str, int]mapping domain names to versions.builder_cls – by default the graph builder is a
yobx.xbuilder.GraphBuilderbut any builder can be used as long it implements the Shape and type tracking.verbose – verbosity level (0 = silent).
extra_converters – optional mapping from
BuiltinOperatorint (or custom-op name string) to converter function with signature(g, sts, outputs, op). Entries here take priority over the built-in op converters.large_model – if True the returned
ExportArtifacthas itscontainerattribute set to anExtendedModelContainer.external_threshold – if large_model is True, every tensor whose element count exceeds this threshold is stored as external data.
subgraph_index – index of the subgraph to convert (default: 0).
- Returns:
ExportArtifactwrapping the exported ONNX proto together with anExportReport.
Example:
import numpy as np from yobx.litert import to_onnx X = np.random.rand(1, 4).astype(np.float32) artifact = to_onnx("model.tflite", (X,)) proto = artifact.proto artifact.save("model.onnx")