runInference method
Just run inference
Implementation
void runInference(List<Object> inputs) {
if (inputs.isEmpty) {
throw ArgumentError('Input error: Inputs should not be null or empty.');
}
final inputCount = _inputTensorsCount ??=
tfliteBinding.TfLiteInterpreterGetInputTensorCount(_interpreter);
if (inputs.length > inputCount) {
throw RangeError.range(inputs.length - 1, 0, inputCount - 1, 'inputs');
}
// Steady-state fast path: allocated and no resize needed. One pass with
// a fresh pointer per index, no wrapper list churn. Any resize or
// missing allocation falls through to the two-pass path below, which
// re-reads every pointer because resize/allocate relocates tensors.
var deferred = !_allocated;
for (int i = 0; i < inputs.length && !deferred; i++) {
final tensor = Tensor(
tfliteBinding.TfLiteInterpreterGetInputTensor(_interpreter, i),
);
final newShape = tensor.getInputShapeIfDifferent(inputs[i]);
if (newShape != null) {
resizeInputTensor(i, newShape);
deferred = true;
} else {
tensor.setTo(inputs[i]);
}
}
if (deferred) {
for (int i = 0; i < inputs.length; i++) {
final tensor = Tensor(
tfliteBinding.TfLiteInterpreterGetInputTensor(_interpreter, i),
);
final newShape = tensor.getInputShapeIfDifferent(inputs[i]);
if (newShape != null) {
resizeInputTensor(i, newShape);
}
}
if (!_allocated) {
allocateTensors();
}
for (int i = 0; i < inputs.length; i++) {
Tensor(
tfliteBinding.TfLiteInterpreterGetInputTensor(_interpreter, i),
).setTo(inputs[i]);
}
}
_inferenceStopwatch
..reset()
..start();
invoke();
_inferenceStopwatch.stop();
_lastInferenceDurationMicroseconds =
_inferenceStopwatch.elapsedMicroseconds;
}