TensorFloat32Views class

Cached Float32List views of an Interpreter's input and output tensors.

Capture once after Interpreter.allocateTensors and reuse the views on every inference. The views alias the underlying tensor native memory, so writing to inputs stages data directly into the input tensor and reading from outputs reads the latest values after Interpreter.invoke (or runForMultipleInputs).

This avoids recreating Float32List wrapper objects every inference and avoids repeated getInputTensor / getOutputTensor lookups on the hot path.

Validity:

  • Interpreter.allocateTensors must have been called before capture.
  • Views become stale after any Interpreter.resizeInputTensor or subsequent allocateTensors. Recapture in that case.
  • Only meaningful for tensors whose element type is float32. For quantized tensors, interpreting bytes as Float32 will produce garbage; use the raw Tensor.data bytes instead.

Example:

interp.allocateTensors();
final views = TensorFloat32Views.capture(interp);

// Hot path:
views.inputs[0].setAll(0, preparedNHWC);
interp.invoke();
final scores = views.outputs[1]; // aliases tensor native memory

Constructors

TensorFloat32Views.capture(Interpreter interp)
Captures Float32List views of every input and output tensor of interp.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
inputs List<Float32List>
One Float32List view per input tensor, in declaration order.
final
outputs List<Float32List>
One Float32List view per output tensor, in declaration order.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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