convert_litert
PythonConvert a Keras model to LiteRT bytes; exportmodel validates the arguments first.
convert_litert( model: keras.Model, *, precision: Precision, io_dtype: IODType, mode: ConversionMode, strict: bool, calibration: npt.NDArray | Mapping[str, npt.NDArray] | None,) -> bytesConvert a Keras model to LiteRT bytes; export_model validates the arguments first.
A model with state inputs is converted with its outputs keyed by output name, so the signature names
state_in_k and state_out_k.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
model | keras.Model | Required | The Keras model, on the TensorFlow backend. |
precision | Precision | Required | The numeric format; FP16 is TensorFlow's float16 weight storage rewritten to a native float16 graph (``to_native_fp16``). |
io_dtype | IODType | Required | Inputs and outputs of the calibrated precisions. FP32 graphs have float32 and FP16 graphs float16 inputs and outputs whatever ``io_dtype`` says, so pass those. |
mode | ConversionMode | Required | How the model is traced; SAVED_MODEL exports to a temporary directory removed after conversion. |
strict | bool | Required | For calibrated precisions, refuse operators without an integer kernel. |
calibration | npt.NDArray | Mapping[str, npt.NDArray] | None | Required | Samples for the calibrated precisions, used one at a time in stored order; for a model with several inputs, a mapping of each input name to its samples, fed by name because the converter orders inputs its own way. |
Returns
| Value | Type | Description |
|---|---|---|
bytes | bytes | The LiteRT flatbuffer. |
Raises
| Type | Description |
|---|---|
ValueError | If ``mode`` is CONCRETE and the model has several inputs or state inputs: a concrete function converts to a graph without a signature, which name-keyed calibration and state tensors need. Also if a model with state inputs repeats an output name, as two outputs of one layer do. |