💚 End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Merge branch 'clip_face_integration' into yolo_custom_plugin
Neeraj Gupta107162fa2c90
diff --cc mobile/lib/generated/l10n.dartindex 017e4378fd,5055c220bc..191458bf4b--- a/mobile/lib/generated/l10n.dart+++ b/mobile/lib/generated/l10n.dart@@@ -8975,135 -8975,15 +8975,145 @@@ class S);}+ /// `Re-enter password`+ String get reenterPassword {+ return Intl.message(+ 'Re-enter password',+ name: 'reenterPassword',+ desc: '',+ args: [],+ );+ }++ /// `Re-enter PIN`+ String get reenterPin {+ return Intl.message(+ 'Re-enter PIN',+ name: 'reenterPin',+ desc: '',+ args: [],+ );+ }++ /// `Device lock`+ String get deviceLock {+ return Intl.message(+ 'Device lock',+ name: 'deviceLock',+ desc: '',+ args: [],+ );+ }++ /// `PIN lock`+ String get pinLock {+ return Intl.message(+ 'PIN lock',+ name: 'pinLock',+ desc: '',+ args: [],+ );+ }++ /// `Next`+ String get next {+ return Intl.message(+ 'Next',+ name: 'next',+ desc: '',+ args: [],+ );+ }++ /// `Set new password`+ String get setNewPassword {+ return Intl.message(+ 'Set new password',+ name: 'setNewPassword',+ desc: '',+ args: [],+ );+ }++ /// `Enter PIN`+ String get enterPin {+ return Intl.message(+ 'Enter PIN',+ name: 'enterPin',+ desc: '',+ args: [],+ );+ }++ /// `Set new PIN`+ String get setNewPin {+ return Intl.message(+ 'Set new PIN',+ name: 'setNewPin',+ desc: '',+ args: [],+ );+ }++ /// `App lock`+ String get appLock {+ return Intl.message(+ 'App lock',+ name: 'appLock',+ desc: '',+ args: [],+ );+ }++ /// `No system lock found`+ String get noSystemLockFound {+ return Intl.message(+ 'No system lock found',+ name: 'noSystemLockFound',+ desc: '',+ args: [],+ );+ }++ /// `To enable app lock, please setup device passcode or screen lock in your system settings.`+ String get toEnableAppLockPleaseSetupDevicePasscodeOrScreen {+ return Intl.message(+ 'To enable app lock, please setup device passcode or screen lock in your system settings.',+ name: 'toEnableAppLockPleaseSetupDevicePasscodeOrScreen',+ desc: '',+ args: [],+ );+ }++ /// `Tap to unlock`+ String get tapToUnlock {+ return Intl.message(+ 'Tap to unlock',+ name: 'tapToUnlock',+ desc: '',+ args: [],+ );+ }++ /// `Too many incorrect attempts`+ String get tooManyIncorrectAttempts {+ return Intl.message(+ 'Too many incorrect attempts',+ name: 'tooManyIncorrectAttempts',+ desc: '',+ args: [],+ );+ }+++ /// `ML functions`+ String get mlFunctions {+ return Intl.message(+ 'ML functions',+ name: 'mlFunctions',+ desc: '',+ args: [],+ );+ }}class AppLocalizationDelegate extends LocalizationsDelegate<S> {diff --cc mobile/lib/l10n/intl_cs.arbindex bb7ab3d553,3d95649c79..b5511d35c2--- a/mobile/lib/l10n/intl_cs.arb+++ b/mobile/lib/l10n/intl_cs.arb@@@ -26,18 -26,5 +26,19 @@@"foundFaces": "Found faces","clusteringProgress": "Clustering progress","indexingIsPaused": "Indexing is paused, will automatically resume when device is ready",+ "reenterPassword": "Re-enter password",+ "reenterPin": "Re-enter PIN",+ "deviceLock": "Device lock",+ "pinLock": "PIN lock",+ "passwordLock": "Password lock",+ "next": "Next",+ "setNewPassword": "Set new password",+ "enterPin": "Enter PIN",+ "setNewPin": "Set new PIN",+ "appLock": "App lock",+ "noSystemLockFound": "No system lock found",+ "toEnableAppLockPleaseSetupDevicePasscodeOrScreen": "To enable app lock, please setup device passcode or screen lock in your system settings.",+ "tapToUnlock": "Tap to unlock",- "tooManyIncorrectAttempts": "Too many incorrect attempts"++ "tooManyIncorrectAttempts": "Too many incorrect attempts",+ "mlFunctions": "ML functions"}diff --cc mobile/lib/l10n/intl_de.arbindex 5d3bbb8912,66162a59ef..d85432a532--- a/mobile/lib/l10n/intl_de.arb+++ b/mobile/lib/l10n/intl_de.arb@@@ -1252,17 -1252,5 +1252,18 @@@"right": "Rechts","whatsNew": "Neue Funktionen","reviewSuggestions": "Vorschläge überprüfen",+ "reenterPassword": "Re-enter password",+ "reenterPin": "Re-enter PIN",+ "deviceLock": "Device lock",+ "pinLock": "PIN lock",+ "next": "Next",+ "setNewPassword": "Set new password",+ "enterPin": "Enter PIN",+ "setNewPin": "Set new PIN",+ "appLock": "App lock",+ "noSystemLockFound": "No system lock found",+ "toEnableAppLockPleaseSetupDevicePasscodeOrScreen": "To enable app lock, please setup device passcode or screen lock in your system settings.",+ "tapToUnlock": "Tap to unlock",- "tooManyIncorrectAttempts": "Too many incorrect attempts"++ "tooManyIncorrectAttempts": "Too many incorrect attempts",+ "mlFunctions": "ML functions"}diff --cc mobile/lib/l10n/intl_en.arbindex fdbada3b8e,abdc91841c..fb06088246--- a/mobile/lib/l10n/intl_en.arb+++ b/mobile/lib/l10n/intl_en.arb@@@ -1263,17 -1263,5 +1263,18 @@@}}},+ "reenterPassword": "Re-enter password",+ "reenterPin": "Re-enter PIN",+ "deviceLock": "Device lock",+ "pinLock": "PIN lock",+ "next": "Next",+ "setNewPassword": "Set new password",+ "enterPin": "Enter PIN",+ "setNewPin": "Set new PIN",+ "appLock": "App lock",+ "noSystemLockFound": "No system lock found",+ "toEnableAppLockPleaseSetupDevicePasscodeOrScreen": "To enable app lock, please setup device passcode or screen lock in your system settings.",+ "tapToUnlock": "Tap to unlock",- "tooManyIncorrectAttempts": "Too many incorrect attempts"++ "tooManyIncorrectAttempts": "Too many incorrect attempts",+ "mlFunctions": "ML functions"}diff --cc mobile/lib/l10n/intl_es.arbindex 1860f35996,2e0adc2411..41ae696c06--- a/mobile/lib/l10n/intl_es.arb+++ b/mobile/lib/l10n/intl_es.arb@@@ -1252,17 -1252,5 +1252,18 @@@"right": "Derecha","whatsNew": "Qué hay de nuevo","reviewSuggestions": "Revisar sugerencias",+ "reenterPassword": "Re-enter password",+ "reenterPin": "Re-enter PIN",+ "deviceLock": "Device lock",+ "pinLock": "PIN lock",+ "next": "Next",+ "setNewPassword": "Set new password",+ "enterPin": "Enter PIN",+ "setNewPin": "Set new PIN",+ "appLock": "App lock",+ "noSystemLockFound": "No system lock found",+ "toEnableAppLockPleaseSetupDevicePasscodeOrScreen": "To enable app lock, please setup device passcode or screen lock in your system settings.",+ "tapToUnlock": "Tap to unlock",- "tooManyIncorrectAttempts": "Too many incorrect attempts"++ "tooManyIncorrectAttempts": "Too many incorrect attempts",+ "mlFunctions": "ML functions"}diff --cc mobile/lib/l10n/intl_fr.arbindex 9c606c1da7,b80289a044..0f177ef717--- a/mobile/lib/l10n/intl_fr.arb+++ b/mobile/lib/l10n/intl_fr.arb@@@ -1169,17 -1169,5 +1169,18 @@@"foundFaces": "Found faces","clusteringProgress": "Clustering progress","indexingIsPaused": "Indexing is paused, will automatically resume when device is ready",+ "reenterPassword": "Re-enter password",+ "reenterPin": "Re-enter PIN",+ "deviceLock": "Device lock",+ "pinLock": "PIN lock",+ "next": "Next",+ "setNewPassword": "Set new password",+ "enterPin": "Enter PIN",+ "setNewPin": "Set new PIN",+ "appLock": "App lock",+ "noSystemLockFound": "No system lock found",+ "toEnableAppLockPleaseSetupDevicePasscodeOrScreen": "To enable app lock, please setup device passcode or screen lock in your system settings.",+ "tapToUnlock": "Tap to unlock",- "tooManyIncorrectAttempts": "Too many incorrect attempts"++ "tooManyIncorrectAttempts": "Too many incorrect attempts",+ "mlFunctions": "ML functions"}diff --cc mobile/lib/l10n/intl_it.arbindex 76df9bdd41,90893a3c73..0e945b3b64--- a/mobile/lib/l10n/intl_it.arb+++ b/mobile/lib/l10n/intl_it.arb@@@ -1131,17 -1131,5 +1131,18 @@@"foundFaces": "Found faces","clusteringProgress": "Clustering progress","indexingIsPaused": "Indexing is paused, will automatically resume when device is ready",+ "reenterPassword": "Re-enter password",+ "reenterPin": "Re-enter PIN",+ "deviceLock": "Device lock",+ "pinLock": "PIN lock",+ "next": "Next",+ "setNewPassword": "Set new password",+ "enterPin": "Enter PIN",+ "setNewPin": "Set new PIN",+ "appLock": "App lock",+ "noSystemLockFound": "No system lock found",+ "toEnableAppLockPleaseSetupDevicePasscodeOrScreen": "To enable app lock, please setup device passcode or screen lock in your system settings.",+ "tapToUnlock": "Tap to unlock",- "tooManyIncorrectAttempts": "Too many incorrect attempts"++ "tooManyIncorrectAttempts": "Too many incorrect attempts",+ "mlFunctions": "ML functions"}diff --cc mobile/lib/l10n/intl_ko.arbindex bb7ab3d553,3d95649c79..280fc30fc4--- a/mobile/lib/l10n/intl_ko.arb+++ b/mobile/lib/l10n/intl_ko.arb@@@ -26,18 -26,5 +26,20 @@@"foundFaces": "Found faces","clusteringProgress": "Clustering progress","indexingIsPaused": "Indexing is paused, will automatically resume when device is ready",+ "reenterPassword": "Re-enter password",+ "reenterPin": "Re-enter PIN",+ "deviceLock": "Device lock",+ "pinLock": "PIN lock",+ "passwordLock": "Password lock",+ "next": "Next",+ "setNewPassword": "Set new password",+ "enterPin": "Enter PIN",+ "setNewPin": "Set new PIN",+ "appLock": "App lock",+ "noSystemLockFound": "No system lock found",+ "toEnableAppLockPleaseSetupDevicePasscodeOrScreen": "To enable app lock, please setup device passcode or screen lock in your system settings.",+ "tapToUnlock": "Tap to unlock",- "tooManyIncorrectAttempts": "Too many incorrect attempts"++ "tooManyIncorrectAttempts": "Too many incorrect attempts",+ "mlFunctions": "ML functions"++}diff --cc mobile/lib/l10n/intl_nl.arbindex 80824dbe21,526f579395..c33e878b2f--- a/mobile/lib/l10n/intl_nl.arb+++ b/mobile/lib/l10n/intl_nl.arb@@@ -1232,17 -1232,5 +1232,19 @@@"foundFaces": "Found faces","clusteringProgress": "Clustering progress","indexingIsPaused": "Indexing is paused, will automatically resume when device is ready",+ "reenterPassword": "Re-enter password",+ "reenterPin": "Re-enter PIN",+ "deviceLock": "Device lock",+ "pinLock": "PIN lock",+ "next": "Next",+ "setNewPassword": "Set new password",+ "enterPin": "Enter PIN",+ "setNewPin": "Set new PIN",+ "appLock": "App lock",+ "noSystemLockFound": "No system lock found",+ "toEnableAppLockPleaseSetupDevicePasscodeOrScreen": "To enable app lock, please setup device passcode or screen lock in your system settings.",+ "tapToUnlock": "Tap to unlock",- "tooManyIncorrectAttempts": "Too many incorrect attempts"++ "tooManyIncorrectAttempts": "Too many incorrect attempts",+ "mlFunctions": "ML functions"++}diff --cc mobile/lib/l10n/intl_no.arbindex b30793121a,ec322bccb1..5e1a23e059--- a/mobile/lib/l10n/intl_no.arb+++ b/mobile/lib/l10n/intl_no.arb@@@ -40,18 -40,5 +40,20 @@@"foundFaces": "Found faces","clusteringProgress": "Clustering progress","indexingIsPaused": "Indexing is paused, will automatically resume when device is ready",+ "reenterPassword": "Re-enter password",+ "reenterPin": "Re-enter PIN",+ "deviceLock": "Device lock",+ "pinLock": "PIN lock",+ "passwordLock": "Password lock",+ "next": "Next",+ "setNewPassword": "Set new password",+ "enterPin": "Enter PIN",+ "setNewPin": "Set new PIN",+ "appLock": "App lock",+ "noSystemLockFound": "No system lock found",+ "toEnableAppLockPleaseSetupDevicePasscodeOrScreen": "To enable app lock, please setup device passcode or screen lock in your system settings.",+ "tapToUnlock": "Tap to unlock",- "tooManyIncorrectAttempts": "Too many incorrect attempts"++ "tooManyIncorrectAttempts": "Too many incorrect attempts",+ "mlFunctions": "ML functions"++}diff --cc mobile/lib/l10n/intl_pl.arbindex e0feaa9148,cf99bdcf98..cc9f173f2b--- a/mobile/lib/l10n/intl_pl.arb+++ b/mobile/lib/l10n/intl_pl.arb@@@ -127,18 -127,5 +127,20 @@@"foundFaces": "Found faces","clusteringProgress": "Clustering progress","indexingIsPaused": "Indexing is paused, will automatically resume when device is ready",+ "reenterPassword": "Re-enter password",+ "reenterPin": "Re-enter PIN",+ "deviceLock": "Device lock",+ "pinLock": "PIN lock",+ "passwordLock": "Password lock",+ "next": "Next",+ "setNewPassword": "Set new password",+ "enterPin": "Enter PIN",+ "setNewPin": "Set new PIN",+ "appLock": "App lock",+ "noSystemLockFound": "No system lock found",+ "toEnableAppLockPleaseSetupDevicePasscodeOrScreen": "To enable app lock, please setup device passcode or screen lock in your system settings.",+ "tapToUnlock": "Tap to unlock",- "tooManyIncorrectAttempts": "Too many incorrect attempts"++ "tooManyIncorrectAttempts": "Too many incorrect attempts",+ "mlFunctions": "ML functions"++}diff --cc mobile/lib/l10n/intl_pt.arbindex 73406db361,7487bbccc1..9296d38797--- a/mobile/lib/l10n/intl_pt.arb+++ b/mobile/lib/l10n/intl_pt.arb@@@ -1252,17 -1252,5 +1252,19 @@@"right": "Direita","whatsNew": "O que há de novo","reviewSuggestions": "Revisar sugestões",+ "reenterPassword": "Re-enter password",+ "reenterPin": "Re-enter PIN",+ "deviceLock": "Device lock",+ "pinLock": "PIN lock",+ "next": "Next",+ "setNewPassword": "Set new password",+ "enterPin": "Enter PIN",+ "setNewPin": "Set new PIN",+ "appLock": "App lock",+ "noSystemLockFound": "No system lock found",+ "toEnableAppLockPleaseSetupDevicePasscodeOrScreen": "To enable app lock, please setup device passcode or screen lock in your system settings.",+ "tapToUnlock": "Tap to unlock",- "tooManyIncorrectAttempts": "Too many incorrect attempts"++ "tooManyIncorrectAttempts": "Too many incorrect attempts",+ "mlFunctions": "ML functions"++}diff --cc mobile/lib/l10n/intl_ru.arbindex b3a5eafd9a,c05ff62917..4525756198--- a/mobile/lib/l10n/intl_ru.arb+++ b/mobile/lib/l10n/intl_ru.arb@@@ -1251,17 -1251,5 +1251,19 @@@"left": "Влево","right": "Вправо","whatsNew": "Что нового",+ "reenterPassword": "Re-enter password",+ "reenterPin": "Re-enter PIN",+ "deviceLock": "Device lock",+ "pinLock": "PIN lock",+ "next": "Next",+ "setNewPassword": "Set new password",+ "enterPin": "Enter PIN",+ "setNewPin": "Set new PIN",+ "appLock": "App lock",+ "noSystemLockFound": "No system lock found",+ "toEnableAppLockPleaseSetupDevicePasscodeOrScreen": "To enable app lock, please setup device passcode or screen lock in your system settings.",+ "tapToUnlock": "Tap to unlock",- "tooManyIncorrectAttempts": "Too many incorrect attempts"++ "tooManyIncorrectAttempts": "Too many incorrect attempts",+ "mlFunctions": "ML functions"++}diff --cc mobile/lib/l10n/intl_zh.arbindex 524e74121b,2f3fc1f2d8..89a7c21822--- a/mobile/lib/l10n/intl_zh.arb+++ b/mobile/lib/l10n/intl_zh.arb@@@ -1252,17 -1252,5 +1252,19 @@@"right": "向右","whatsNew": "更新日志","reviewSuggestions": "查看建议",+ "reenterPassword": "Re-enter password",+ "reenterPin": "Re-enter PIN",+ "deviceLock": "Device lock",+ "pinLock": "PIN lock",+ "next": "Next",+ "setNewPassword": "Set new password",+ "enterPin": "Enter PIN",+ "setNewPin": "Set new PIN",+ "appLock": "App lock",+ "noSystemLockFound": "No system lock found",+ "toEnableAppLockPleaseSetupDevicePasscodeOrScreen": "To enable app lock, please setup device passcode or screen lock in your system settings.",+ "tapToUnlock": "Tap to unlock",- "tooManyIncorrectAttempts": "Too many incorrect attempts"++ "tooManyIncorrectAttempts": "Too many incorrect attempts",+ "mlFunctions": "ML functions"++}diff --cc mobile/lib/services/machine_learning/face_ml/face_detection/face_detection_service.dartindex 9935ed19ac,80f84a80f6..dea6be2213--- a/mobile/lib/services/machine_learning/face_ml/face_detection/face_detection_service.dart+++ b/mobile/lib/services/machine_learning/face_ml/face_detection/face_detection_service.dart@@@ -1,12 -1,9 +1,10 @@@import "dart:async";import "dart:developer" as dev show log;- import "dart:io" show File, Platform;-import 'dart:typed_data' show ByteData;+import 'dart:typed_data' show ByteBuffer, ByteData, Float32List, Uint8List;import 'dart:ui' as ui show Image;- import "package:computer/computer.dart";import 'package:logging/logging.dart';+import "package:onnx_dart/onnx_dart.dart";import 'package:onnxruntime/onnxruntime.dart';import "package:photos/face/model/dimension.dart";import 'package:photos/services/machine_learning/face_ml/face_detection/detection.dart';@@@ -86,10 -44,7 +45,12 @@@ class FaceDetectionService extends MlMoByteData imageByteData,int sessionAddress,) async {- assert(sessionAddress != 0 && sessionAddress != -1);+ assert(- !useCustomPlugin ? (sessionAddress != 0 && sessionAddress != -1) : true,++ !MlModel.useCustomPlugin++ ? (sessionAddress != 0 && sessionAddress != -1)++ : true,+ 'sessionAddress should be valid',+ );final stopwatch = Stopwatch()..start();@@@ -113,85 -80,30 +74,84 @@@// Run inferencefinal stopwatchInterpreter = Stopwatch()..start();- List<OrtValue?>? outputs;++ List<List<List<double>>>? nestedResults = [];try {- if (useCustomPlugin) {- final runOptions = OrtRunOptions();- final session = OrtSession.fromAddress(sessionAddress);- outputs = session.run(runOptions, inputs);- // inputOrt.release();- // runOptions.release();++ if (MlModel.useCustomPlugin) {+ nestedResults = await _runCustomPlugin(inputImageList);+ } else {+ nestedResults = _runJNIBasedPlugin(+ sessionAddress,+ inputImageList,+ ); // [1, 25200, 16]+ }} catch (e, s) {- _logger.severe('Error while running inference: $e \n $s');+ dev.log('Error while running inference', error: e, stackTrace: s);throw YOLOFaceInterpreterRunException();}stopwatchInterpreter.stop();- _logger.info(- 'interpreter.run is finished, in ${stopwatchInterpreter.elapsedMilliseconds} ms',- );+ try {+ _logger.info(+ 'interpreter.run is finished, in ${stopwatchInterpreter.elapsedMilliseconds} ms',+ );- final relativeDetections = _yoloPostProcessOutputs(outputs, newSize);+ final relativeDetections =+ _yoloPostProcessOutputs(nestedResults!, newSize);+ stopwatch.stop();+ _logger.info(+ 'predict() face detection executed in ${stopwatch.elapsedMilliseconds}ms',+ );- return (relativeDetections, originalSize);- stopwatch.stop();- _logger.info(- 'predict() face detection executed in ${stopwatch.elapsedMilliseconds}ms',++ return relativeDetections;+ } catch (e, s) {+ _logger.severe('Error while post processing', e, s);+ rethrow;+ }+ }++ static List<List<List<double>>>? _runJNIBasedPlugin(+ int sessionAddress,+ Float32List inputImageList,+ ) {+ final inputShape = [+ 1,+ 3,+ kInputHeight,+ kInputWidth,+ ];+ final inputOrt = OrtValueTensor.createTensorWithDataList(+ inputImageList,+ inputShape,);+ final inputs = {'input': inputOrt};- return relativeDetections;+ final runOptions = OrtRunOptions();+ final session = OrtSession.fromAddress(sessionAddress);+ final List<OrtValue?>? outputs = session.run(runOptions, inputs);+ // inputOrt.release();+ // runOptions.release();+ return outputs?[0]?.value as List<List<List<double>>>; // [1, 25200, 16]+ }++ static Future<List<List<List<double>>>> _runCustomPlugin(+ Float32List inputImageList,+ ) async {+ final OnnxDart plugin = OnnxDart();+ final result = await plugin.predict(+ inputImageList,+ "YOLO_FACE",+ );+ final List<List<List<double>>> reconstructedTensor = [];+ for (int i = 0; i < result.length; i += 25200 * 16) {+ final List<List<double>> outerArray = [];+ for (int j = 0; j < 25200; j++) {+ final List<double> innerArray =+ result.sublist(i + j * 16, i + (j + 1) * 16).cast<double>();+ outerArray.add(innerArray);+ }+ reconstructedTensor.add(outerArray);+ }+ return reconstructedTensor;}static List<FaceDetectionRelative> _yoloPostProcessOutputs(diff --cc mobile/lib/services/machine_learning/ml_model.dartindex 0000000000,b806e37bdb..d4e299d4d9mode 000000,100644..100644--- a/mobile/lib/services/machine_learning/ml_model.dart+++ b/mobile/lib/services/machine_learning/ml_model.dart@@@ -1,0 -1,80 +1,88 @@@-import "dart:io" show File;++import "dart:io" show File, Platform;++ import "package:computer/computer.dart";+ import "package:logging/logging.dart";++import "package:onnx_dart/onnx_dart.dart";+ import "package:onnxruntime/onnxruntime.dart";+ import "package:photos/services/machine_learning/onnx_env.dart";+ import "package:photos/services/remote_assets_service.dart";++ abstract class MlModel {+ Logger get logger;++ String get kModelBucketEndpoint => "https://models.ente.io/";++ String get modelRemotePath;++ String get modelName;++ bool isInitialized = false;+ int sessionAddress = 0;++ final computer = Computer.shared();++ static bool useCustomPlugin = Platform.isAndroid;++ Future<void> init() async {+ if (!isInitialized) {+ logger.info('init is called');+ final model =+ await RemoteAssetsService.instance.getAsset(modelRemotePath);+ final startTime = DateTime.now();+ try {- await ONNXEnv.instance.initONNX(modelName);- sessionAddress = await computer.compute(- _loadModel,- param: {- "modelPath": model.path,- },- );- isInitialized = true;++ if (useCustomPlugin) {++ final OnnxDart plugin = OnnxDart();++ final bool? initResult = await plugin.init(modelName, model.path);++ isInitialized = initResult ?? false;++ } else {++ await ONNXEnv.instance.initONNX(modelName);++ sessionAddress = await computer.compute(++ _loadModel,++ param: {++ "modelPath": model.path,++ },++ );++ isInitialized = true;++ }+ final endTime = DateTime.now();+ logger.info(+ "model loaded, took: ${(endTime.millisecondsSinceEpoch - startTime.millisecondsSinceEpoch).toString()}ms",+ );+ } catch (e, s) {+ logger.severe('model not loaded', e, s);+ }+ }+ }++ Future<void> release() async {+ if (isInitialized) {+ await computer.compute(_releaseModel, param: {'address': sessionAddress});+ await ONNXEnv.instance.releaseONNX(modelName);+ isInitialized = false;+ sessionAddress = 0;+ }+ }++ static Future<int> _loadModel(Map args) async {+ final sessionOptions = OrtSessionOptions()+ ..setInterOpNumThreads(1)+ ..setIntraOpNumThreads(1)+ ..setSessionGraphOptimizationLevel(GraphOptimizationLevel.ortEnableAll);+ try {+ final session =+ OrtSession.fromFile(File(args["modelPath"]), sessionOptions);+ return session.address;+ } catch (e) {+ rethrow;+ }+ }++ static Future<void> _releaseModel(Map args) async {+ final address = args['address'] as int;+ if (address == 0) {+ return;+ }+ final session = OrtSession.fromAddress(address);+ session.release();+ return;+ }+ }