LiteRTRunner
PythonRun a single-input, single-output .tflite model one sample at a time.
LiteRTRunner(content: bytes, *, reference_kernels: bool = False, num_threads: int = 1) -> NoneRun a single-input, single-output .tflite model one sample at a time.
The input tensor is resized to each sample’s shape along the model’s dynamic dimensions only; fixed dimensions must match. Native float16 graphs run when the runtime has float16 kernels for every operator; otherwise the runtime’s error is raised unchanged.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
content | bytes | Required | Model flatbuffer bytes. |
reference_kernels | bool | False | Use LiteRT's reference kernels instead of its optimized kernels. |
num_threads | int | 1 | Interpreter threads. |
interpreter
Pythoninterpreter = litert.Interpreter(model_content=content, num_threads=num_threads, experimental_op_resolver_type=resolver)run
PythonInvoke on samples along axis 0 already in the model's input dtype; return raw outputs.
run(x: npt.NDArray) -> npt.NDArrayInvoke on samples along axis 0 already in the model’s input dtype; return raw outputs.
encode
PythonConvert real-valued samples to the input dtype, rounding and saturating integer inputs.
encode(x: npt.NDArray) -> npt.NDArrayConvert real-valued samples to the input dtype, rounding and saturating integer inputs.
decode
PythonConvert raw outputs to float32 values.
decode(y: npt.NDArray) -> npt.NDArrayConvert raw outputs to float32 values.
predict
PythonEncode real-valued samples, run them and decode the outputs.
predict(x: npt.NDArray) -> npt.NDArrayEncode real-valued samples, run them and decode the outputs.