import { parseTflite } from "@wetron/tflite";

const graph = parseTflite(bytes: Uint8Array): ModelGraph

Synchronous - no await needed.

What is parsed

  • The first subgraph (subgraphs[0]); secondary subgraphs referenced by If / While are not yet inlined
  • Op types from the built-in BuiltinOperator enum; custom ops use their custom_code string
  • Tensor shapes and dtypes for all tensors in the parsed subgraph
  • Graph inputs and outputs from the primary subgraph
  • Initializer bytes exposed via ModelGraph.weights.get(name) - tensors with a non-empty buffer reference

Detection

Detects both:

  • TFL3 at offset 4 (standard TFLite)
  • ODLF at offset 4 (LiteRT / ODLF variant)

Dtype mapping

TFLite enumdtype string
0float32
1int32
2uint8
3int64
4string
5bool
6int16
7complex64
8int8
9float16
10float64
11complex128
16uint32
17uint64
256bfloat16

Notes

  • Initializer buffers are exposed lazily through ModelGraph.weights; consumers call weights.get(name) for raw bytes and decodeWeight / computeStats from @wetron/core to inspect values. See Weights.
  • Synchronous because FlatBuffers decoding requires no async I/O.