runFloat method

Future<List<Float32List>> runFloat(
  1. Map<String, OrtIsolateInput> inputs,
  2. List<int> outputElementCounts
)

Runs inference in the background isolate.

Returns output tensors as Float32Lists. This method is fully async and safe to call from the UI thread.

Implementation

Future<List<Float32List>> runFloat(
  Map<String, OrtIsolateInput> inputs,
  List<int> outputElementCounts,
) async {
  _ensureNotDisposed();

  final tensorInputs = inputs.map(
    (name, input) => MapEntry(
      name,
      _TensorData(shape: input.shape, data: input.data),
    ),
  );

  _workerPort.send(_InferRequest(
    inputs: tensorInputs,
    outputElementCounts: outputElementCounts,
  ));

  final response = await _responses.first;
  if (response is _ErrorResponse) {
    throw Exception(response.message);
  }
  return (response as _InferResponse).outputs;
}