Interpreter class

Web implementation of Interpreter.

Uses the TFLite.js WASM runtime for inference. The supported subset of the API (fromAsset, fromBytes, run, runForMultipleInputs, and the tensor getters) matches the native Interpreter, so common inference code needs no conditional branching. Native-only members (fromFile, fromBuffer, fromAddress, resizeInputTensor, the signature-runner and variable-tensor APIs, and address) throw UnsupportedError on web.

Constructors

Interpreter.fromAddress(int address, {bool allocated = true, bool deleted = false})
Not supported on web (no pointer addresses).
factory
Interpreter.fromBuffer(Uint8List buffer, {InterpreterOptions? options})
Not supported on web.
factory
Interpreter.fromFile(dynamic modelFile, {InterpreterOptions? options})
Not supported on web. Use fromAsset or fromBytes instead.
factory

Properties

address int
Not supported on web (no pointer addresses).
no setter
hashCode int
The hash code for this object.
no setterinherited
isAllocated bool
Whether the interpreter is still usable (not yet closed).
no setter
isDeleted bool
Whether the interpreter has been deleted.
no setter
lastInferenceDurationMicroseconds int
Duration of the last inference call in microseconds.
no setter
lastNativeInferenceDurationMicroSeconds int
Duration of the last inference call in microseconds.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
signatureCount int
Not supported on web.
no setter
signatureKeys List<String>
Not supported on web.
no setter

Methods

allocateTensors() → void
No-op on web (TFLite.js handles allocation internally).
close() → void
Closes the interpreter.
getInputIndex(String opName) int
Gets index of an input given the op name.
getInputTensor(int index) Tensor
Gets the input Tensor for the provided input index.
getInputTensors() List<Tensor>
Gets input tensors (metadata-only on web).
getOutputIndex(String opName) int
Gets index of an output given the op name.
getOutputTensor(int index) Tensor
Gets the output Tensor for the provided output index.
getOutputTensors() List<Tensor>
Gets output tensors.
getSignatureKey(int index) String
Not supported on web.
getSignatureRunner(String signatureKey) SignatureRunner
Not supported on web.
getVariableTensor(int index) Tensor
Not supported on web.
getVariableTensorCount() int
Returns 0 on web (no variable tensor support).
invoke() → void
No-op on web (inference is done through run/runForMultipleInputs).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
resetVariableTensors() → void
No-op on web.
resizeInputTensor(int tensorIndex, List<int> shape) → void
Not supported on web, TFLite.js does not expose a tensor resize API.
run(Object input, Object output) → void
Run inference for single input and output.
runForMultipleInputs(List<Object> inputs, Map<int, Object> outputs) → void
Run inference for multiple inputs and outputs.
runInference(List<Object> inputs) → void
Runs inference by converting inputs to JS tensors and calling predict.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

version String
Returns the TFLite web runtime version string.
no setter

Static Methods

fromAsset(String assetName, {InterpreterOptions? options}) Future<Interpreter>
Creates interpreter from an asset name.
fromBytes(Uint8List buffer, {InterpreterOptions? options}) Future<Interpreter>
Creates interpreter from raw bytes (async web-compatible version).