Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob][photos] Rename to MLComputer

laurenspriemde5fd245ef21
diff --git a/mobile/lib/utils/image_isolate.dart b/mobile/lib/services/machine_learning/ml_computer.dart
similarity index 91%
rename from mobile/lib/utils/image_isolate.dart
rename to mobile/lib/services/machine_learning/ml_computer.dart
index c30767755f..02f996ede3 100644
--- a/mobile/lib/utils/image_isolate.dart
+++ b/mobile/lib/services/machine_learning/ml_computer.dart
@@ -11,13 +11,13 @@ import "package:photos/services/remote_assets_service.dart";
import "package:photos/utils/image_ml_util.dart";
import "package:synchronized/synchronized.dart";
-enum ImageOperation {
+enum MLComputerOperation {
generateFaceThumbnails,
runClipText,
}
-class ImageIsolate {
- final _logger = Logger('ImageIsolate');
+class MLComputerIsolate {
+ final _logger = Logger('MLComputerIsolate');
Timer? _inactivityTimer;
final Duration _inactivityDuration = const Duration(seconds: 60);
@@ -33,9 +33,10 @@ class ImageIsolate {
bool isSpawned = false;
// Singleton pattern
- ImageIsolate._privateConstructor();
- static final ImageIsolate instance = ImageIsolate._privateConstructor();
- factory ImageIsolate() => instance;
+ MLComputerIsolate._privateConstructor();
+ static final MLComputerIsolate instance =
+ MLComputerIsolate._privateConstructor();
+ factory MLComputerIsolate() => instance;
Future<void> init() async {
return _initLock.synchronized(() async {
@@ -72,13 +73,13 @@ class ImageIsolate {
receivePort.listen((message) async {
final functionIndex = message[0] as int;
- final function = ImageOperation.values[functionIndex];
+ final function = MLComputerOperation.values[functionIndex];
final args = message[1] as Map<String, dynamic>;
final sendPort = message[2] as SendPort;
try {
switch (function) {
- case ImageOperation.generateFaceThumbnails:
+ case MLComputerOperation.generateFaceThumbnails:
final imagePath = args['imagePath'] as String;
final Uint8List imageData = await File(imagePath).readAsBytes();
final faceBoxesJson =
@@ -91,7 +92,7 @@ class ImageIsolate {
faceBoxes,
);
sendPort.send(List.from(results));
- case ImageOperation.runClipText:
+ case MLComputerOperation.runClipText:
final textEmbedding = await ClipTextEncoder.predict(args);
sendPort.send(List.from(textEmbedding, growable: false));
break;
@@ -105,7 +106,7 @@ class ImageIsolate {
/// The common method to run any operation in the isolate. It sends the [message] to [_isolateMain] and waits for the result.
Future<dynamic> _runInIsolate(
- (ImageOperation, Map<String, dynamic>) message,
+ (MLComputerOperation, Map<String, dynamic>) message,
) async {
await ensureSpawned();
return _functionLock.synchronized(() async {
@@ -174,7 +175,7 @@ class ImageIsolate {
faceBoxes.map((box) => box.toJson()).toList();
return await _runInIsolate(
(
- ImageOperation.generateFaceThumbnails,
+ MLComputerOperation.generateFaceThumbnails,
{
'imagePath': imagePath,
'faceBoxesList': faceBoxesJson,
@@ -191,7 +192,7 @@ class ImageIsolate {
await RemoteAssetsService.instance.getAssetPath(remotePath);
final textEmbedding = await _runInIsolate(
(
- ImageOperation.runClipText,
+ MLComputerOperation.runClipText,
{
"text": query,
"address": clipAddress,
diff --git a/mobile/lib/services/machine_learning/semantic_search/semantic_search_service.dart b/mobile/lib/services/machine_learning/semantic_search/semantic_search_service.dart
index 5460a975ef..0a88a8b1bf 100644
--- a/mobile/lib/services/machine_learning/semantic_search/semantic_search_service.dart
+++ b/mobile/lib/services/machine_learning/semantic_search/semantic_search_service.dart
@@ -16,12 +16,12 @@ import "package:photos/models/file/file.dart";
import "package:photos/models/ml/ml_versions.dart";
import "package:photos/services/collections_service.dart";
import "package:photos/services/machine_learning/face_ml/face_clustering/cosine_distance.dart";
+import "package:photos/services/machine_learning/ml_computer.dart";
import "package:photos/services/machine_learning/ml_result.dart";
import "package:photos/services/machine_learning/semantic_search/clip/clip_image_encoder.dart";
import "package:photos/services/machine_learning/semantic_search/clip/clip_text_encoder.dart";
import 'package:photos/services/machine_learning/semantic_search/embedding_store.dart';
import "package:photos/utils/debouncer.dart";
-import "package:photos/utils/image_isolate.dart";
import "package:photos/utils/local_settings.dart";
import "package:photos/utils/ml_util.dart";
@@ -295,7 +295,7 @@ class SemanticSearchService {
if (cachedResult != null) {
return cachedResult;
}
- final textEmbedding = await ImageIsolate.instance.runClipText(query);
+ final textEmbedding = await MLComputerIsolate.instance.runClipText(query);
_queryCache.put(query, textEmbedding);
return textEmbedding;
}
diff --git a/mobile/lib/utils/face/face_box_crop.dart b/mobile/lib/utils/face/face_box_crop.dart
index d8e3a10bd1..eadc5834c3 100644
--- a/mobile/lib/utils/face/face_box_crop.dart
+++ b/mobile/lib/utils/face/face_box_crop.dart
@@ -5,8 +5,8 @@ import "package:photos/core/cache/lru_map.dart";
import "package:photos/face/model/box.dart";
import "package:photos/models/file/file.dart";
import "package:photos/models/file/file_type.dart";
+import "package:photos/services/machine_learning/ml_computer.dart";
import "package:photos/utils/file_util.dart";
-import "package:photos/utils/image_isolate.dart";
import "package:photos/utils/thumbnail_util.dart";
import "package:pool/pool.dart";
@@ -53,7 +53,7 @@ Future<Map<String, Uint8List>?> getFaceCrops(
faceBoxes.add(e.value);
}
final List<Uint8List> faceCrop =
- await ImageIsolate.instance.generateFaceThumbnails(
+ await MLComputerIsolate.instance.generateFaceThumbnails(
// await generateJpgFaceThumbnails(
imagePath,
faceBoxes,