Implement the API to release resources held by ORT
This commit is contained in:
parent
836fb97598
commit
6c242aa1d2
5 changed files with 25 additions and 5 deletions
|
@ -41,6 +41,9 @@ abstract class MLFramework {
|
|||
await _initTextModel();
|
||||
}
|
||||
|
||||
// Releases any resources held by the framework
|
||||
Future<void> release() async {}
|
||||
|
||||
/// Returns the cosine similarity between [imageEmbedding] and [textEmbedding]
|
||||
double computeScore(List<double> imageEmbedding, List<double> textEmbedding) {
|
||||
assert(
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import "package:computer/computer.dart";
|
||||
import "package:logging/logging.dart";
|
||||
import "package:onnxruntime/onnxruntime.dart";
|
||||
import "package:photos/services/semantic_search/frameworks/ml_framework.dart";
|
||||
import "package:photos/services/semantic_search/frameworks/onnx/onnx_image_encoder.dart";
|
||||
import "package:photos/services/semantic_search/frameworks/onnx/onnx_text_encoder.dart";
|
||||
|
@ -107,4 +108,12 @@ class ONNX extends MLFramework {
|
|||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> release() async {
|
||||
final session = OrtSession.fromAddress(_textEncoderAddress);
|
||||
session.release();
|
||||
OrtEnv.instance.release();
|
||||
_logger.info('Released');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,6 +78,12 @@ class SemanticSearchService {
|
|||
});
|
||||
}
|
||||
|
||||
Future<void> release() async {
|
||||
if (_frameworkInitialization.isCompleted) {
|
||||
await _mlFramework.release();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> sync() async {
|
||||
if (_isSyncing) {
|
||||
return;
|
||||
|
|
|
@ -1388,10 +1388,11 @@ packages:
|
|||
onnxruntime:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: onnxruntime
|
||||
sha256: "56d0a16c24f4d1be4cf976cdc6321fb33d81515429e6e81c58d02e77d8631e0f"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
path: "."
|
||||
ref: HEAD
|
||||
resolved-ref: "1318dce97f3aae5ec9bdf7491d5eff0ad6beb378"
|
||||
url: "https://github.com/ente-io/onnxruntime.git"
|
||||
source: git
|
||||
version: "1.1.0"
|
||||
open_mail_app:
|
||||
dependency: "direct main"
|
||||
|
|
|
@ -117,7 +117,8 @@ dependencies:
|
|||
# open_file: ^3.2.1
|
||||
objectbox: ^2.3.1
|
||||
objectbox_flutter_libs: any
|
||||
onnxruntime: ^1.1.0
|
||||
onnxruntime:
|
||||
git: "https://github.com/ente-io/onnxruntime.git"
|
||||
open_mail_app: ^0.4.5
|
||||
package_info_plus: ^4.1.0
|
||||
page_transition: ^2.0.2
|
||||
|
|
Loading…
Add table
Reference in a new issue