Introduction
A .tflite file is a trained model prepared to run on phones, embedded
boards and microcontrollers with TensorFlow Lite, which Google renamed
LiteRT in 2024. The converter takes a
TensorFlow, Keras or JAX model, fixes its graph, and often quantises the weights to
8-bit integers so the file is smaller and runs faster on small chips. The result holds
both the network and its weights in one file that can be mapped into memory and used
without parsing.
Structure
The file is a FlatBuffers buffer whose schema,
schema.fbs, is part of the TensorFlow source. It starts with a 4-byte offset
to the root table, then the file identifier TFL3 at bytes 4 to 7.
0Root offset little-endian, to the Model table4 bytes4IdentifierTFL34 bytes8Tables the Model and everything it refers tothe rest
The Model table has a schema version, a list of operator codes such as
CONV_2D and FULLY_CONNECTED, one or more subgraphs, a list of
buffers and optional metadata. Each subgraph lists its tensors (with type, shape,
quantisation parameters and the buffer that holds their values), its inputs and outputs,
and its operators in the order they run. Large models may keep buffer data after the
FlatBuffer instead of inside it. The schema
tables page lists the tables, fields and type codes.
Not described
The reference follows schema.fbs.
Known, not yet covered
- Reference: what each operator's inputs and outputs mean and the
version numbers of each operator. The schema does not carry them; they live in the
kernels and the operator documentation, which were not read. The schema page now
gives which options table each operator
reads (from the interpreter's parser), the
FlexBuffers encoding of
custom_optionsand the model metadata schema. The contents of custom operators' FlexBuffers (which keys each custom operator expects) are defined by each operator and are not in any shared document. - Viewer: not re-audited in this pass.
Links
Software
- LiteRT – Google’s runtime for TensorFlow Lite models (Android, iOS, Linux, microcontrollers)
- TensorFlow – machine learning framework whose converter writes TensorFlow Lite files (Windows, macOS, Linux)
- Netron – viewer that draws the network (Windows, macOS, Linux, web)
Developers
- LiteRT – runtime for loading and running models (Java, Kotlin, Swift, C++, Python)
- FlatBuffers – for reading the file with the published schema (C++, Java, Python and others)