Interpreter.fromFile constructor
Interpreter.fromFile(
- File modelFile, {
- InterpreterOptions? options,
Creates Interpreter from a model file
Throws ArgumentError if unsuccessful.
Example:
final dataFile = await getFile('assets/your_model.tflite');
final interpreter = Interpreter.fromFile(dataFile);
Future<File> getFile(String fileName) async {
final appDir = await getTemporaryDirectory();
final appPath = appDir.path;
final fileOnDevice = File('$appPath/$fileName');
final rawAssetFile = await rootBundle.load(fileName);
final rawBytes = rawAssetFile.buffer.asUint8List();
await fileOnDevice.writeAsBytes(rawBytes, flush: true);
return fileOnDevice;
}
Implementation
factory Interpreter.fromFile(File modelFile, {InterpreterOptions? options}) {
final model = Model.fromFile(modelFile.path);
final interpreter = Interpreter._create(model, options: options);
model.delete();
return interpreter;
}