createCompiledFromBuffer static method

Future<IrisLandmark> createCompiledFromBuffer(
  1. Uint8List modelBytes
)

Creates an iris landmark model backed by LiteRT CompiledModel.

Implementation

static Future<IrisLandmark> createCompiledFromBuffer(
  Uint8List modelBytes,
) async {
  // The 64x64 iris model is below the compute size where Metal dispatch
  // pays off: measured in-app (macOS arm64, median), CompiledModel CPU runs
  // it in ~0.50 ms vs ~0.68 ms for GPU|CPU async. Pin it to the CPU.
  final CompiledModel compiledModel = CompiledModel.fromBuffer(
    modelBytes,
    accelerators: {Accelerator.cpu},
  );
  final int side;
  try {
    side = compiledSquareInputSide(
      compiledModel,
      label: 'Compiled iris landmark',
    );
  } catch (_) {
    compiledModel.close();
    rethrow;
  }
  final obj = IrisLandmark._compiled(compiledModel, side, side);
  try {
    obj._initializeCompiledModel();
    return obj;
  } catch (_) {
    obj.dispose();
    rethrow;
  }
}