runForMultipleInputs method

void runForMultipleInputs(
  1. List<Object> inputs,
  2. Map<int, Object> outputs
)

Run for multiple inputs and outputs

Implementation

void runForMultipleInputs(List<Object> inputs, Map<int, Object> outputs) {
  if (outputs.isEmpty) {
    throw ArgumentError('Input error: Outputs should not be null or empty.');
  }
  // Invalidate cached tensor handles before each run so we always use
  // fresh pointers from the interpreter. TFLite may relocate internal
  // tensor storage between invocations (e.g. XNNPACK workspace reuse).
  _inputTensors = null;
  _outputTensors = null;
  runInference(inputs);
  // Fresh per-index pointers without rebuilding the wrapper list (the
  // count is stable between allocateTensors calls, the pointers are not).
  final outputCount = _outputTensorsCount ??=
      tfliteBinding.TfLiteInterpreterGetOutputTensorCount(_interpreter);
  for (var i = 0; i < outputCount; i++) {
    Tensor(
      tfliteBinding.TfLiteInterpreterGetOutputTensor(_interpreter, i),
    ).copyTo(outputs[i]!);
  }
}