Interpreter.fromBuffer constructor

Interpreter.fromBuffer(
  1. Uint8List buffer, {
  2. InterpreterOptions? options,
})

Creates interpreter from a buffer.

Prefer fromBytes for new cross-platform code. This synchronous constructor remains for tflite_flutter compatibility on native platforms.

Throws ArgumentError if unsuccessful.

Example:

  final buffer = await getBuffer('assets/your_model.tflite');
  final interpreter = Interpreter.fromBuffer(buffer);

  Future<Uint8List> getBuffer(String filePath) async {
      final rawAssetFile = await rootBundle.load(filePath);
      final rawBytes = rawAssetFile.buffer.asUint8List();
      return rawBytes;
  }

Implementation

factory Interpreter.fromBuffer(
  Uint8List buffer, {
  InterpreterOptions? options,
}) {
  final model = Model.fromBuffer(buffer);
  try {
    return Interpreter._create(model, options: options);
  } finally {
    model.delete();
  }
}