Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] ML dev options

laurenspriemf902b7e75c11
diff --git a/mobile/lib/services/machine_learning/ml_indexing_isolate.dart b/mobile/lib/services/machine_learning/ml_indexing_isolate.dart
index 11e5375a61..52da789eb7 100644
--- a/mobile/lib/services/machine_learning/ml_indexing_isolate.dart
+++ b/mobile/lib/services/machine_learning/ml_indexing_isolate.dart
@@ -193,6 +193,28 @@ class MLIndexingIsolate extends SuperIsolate {
}
}
+ /// WARNING: This method is only for debugging purposes. It should not be used in production.
+ Future<void> debugLoadSingleModel(MLModels model) {
+ return _initModelLock.synchronized(() async {
+ final modelInstance = model.model;
+ if (modelInstance.isInitialized) {
+ _logger.info("Model ${model.name} already loaded");
+ return;
+ }
+ final modelName = modelInstance.modelName;
+ final modelPath = await modelInstance.downloadModelSafe();
+ if (modelPath == null) {
+ _logger.severe("Could not download model, no wifi");
+ return;
+ }
+ final address = await runInIsolate(IsolateOperation.loadModel, {
+ "modelName": modelName,
+ "modelPath": modelPath,
+ }) as int;
+ modelInstance.storeSessionAddress(address);
+ });
+ }
+
Future<void> cleanupLocalIndexingModels({bool delete = false}) async {
if (!areModelsDownloaded) return;
await _releaseModels();
diff --git a/mobile/lib/ui/settings/ml/ml_user_dev_screen.dart b/mobile/lib/ui/settings/ml/ml_user_dev_screen.dart
index f295d4b202..e68ec6d295 100644
--- a/mobile/lib/ui/settings/ml/ml_user_dev_screen.dart
+++ b/mobile/lib/ui/settings/ml/ml_user_dev_screen.dart
@@ -5,6 +5,8 @@ import "package:photos/db/ml/base.dart";
import "package:photos/db/ml/db.dart";
import "package:photos/events/people_changed_event.dart";
import "package:photos/service_locator.dart";
+import "package:photos/services/machine_learning/ml_indexing_isolate.dart";
+import "package:photos/services/machine_learning/ml_models_overview.dart";
import "package:photos/services/machine_learning/semantic_search/semantic_search_service.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/components/buttons/button_widget.dart";
@@ -104,6 +106,90 @@ class _MLUserDeveloperOptionsState extends State<MLUserDeveloperOptions> {
isBottomBorderRadiusRemoved: true,
isGestureDetectorDisabled: true,
),
+ const SizedBox(height: 24),
+ ButtonWidget(
+ buttonType: ButtonType.neutral,
+ labelText: "Load face detection model",
+ onTap: () async {
+ try {
+ await MLIndexingIsolate.instance
+ .debugLoadSingleModel(MLModels.faceDetection);
+ } catch (e, s) {
+ _logger.severe(
+ "Could not load face detection model",
+ e,
+ s,
+ );
+ await showGenericErrorDialog(
+ context: context,
+ error: e,
+ );
+ }
+ },
+ ),
+ const SizedBox(height: 24),
+ ButtonWidget(
+ buttonType: ButtonType.neutral,
+ labelText: "Load face recognition model",
+ onTap: () async {
+ try {
+ await MLIndexingIsolate.instance
+ .debugLoadSingleModel(MLModels.faceEmbedding);
+ } catch (e, s) {
+ _logger.severe(
+ "Could not load face detection model",
+ e,
+ s,
+ );
+ await showGenericErrorDialog(
+ context: context,
+ error: e,
+ );
+ }
+ },
+ ),
+ const SizedBox(height: 24),
+ ButtonWidget(
+ buttonType: ButtonType.neutral,
+ labelText: "Load clip image model",
+ onTap: () async {
+ try {
+ await MLIndexingIsolate.instance
+ .debugLoadSingleModel(MLModels.clipImageEncoder);
+ } catch (e, s) {
+ _logger.severe(
+ "Could not load face detection model",
+ e,
+ s,
+ );
+ await showGenericErrorDialog(
+ context: context,
+ error: e,
+ );
+ }
+ },
+ ),
+ const SizedBox(height: 24),
+ ButtonWidget(
+ buttonType: ButtonType.neutral,
+ labelText: "Load clip text model",
+ onTap: () async {
+ try {
+ await MLIndexingIsolate.instance
+ .debugLoadSingleModel(MLModels.clipTextEncoder);
+ } catch (e, s) {
+ _logger.severe(
+ "Could not load face detection model",
+ e,
+ s,
+ );
+ await showGenericErrorDialog(
+ context: context,
+ error: e,
+ );
+ }
+ },
+ ),
const SafeArea(
child: SizedBox(
height: 12,