diff --git a/mobile/lib/services/machine_learning/face_ml/face_recognition_service.dart b/mobile/lib/services/machine_learning/face_ml/face_recognition_service.dart index b8bc29e1d5..17546d58cc 100644 --- a/mobile/lib/services/machine_learning/face_ml/face_recognition_service.dart +++ b/mobile/lib/services/machine_learning/face_ml/face_recognition_service.dart @@ -101,7 +101,7 @@ class FaceRecognitionService { .toSet(); _logger.info('starting remote fetch for ${fileIds.length} files'); final res = - await RemoteFileMLService.instance.getFilessEmbedding(fileIds); + await RemoteFileMLService.instance.getFaceEmbedding(fileIds); _logger.info('fetched ${res.mlData.length} embeddings'); fetchedCount += res.mlData.length; final List faces = []; diff --git a/mobile/lib/services/machine_learning/file_ml/remote_fileml_service.dart b/mobile/lib/services/machine_learning/file_ml/remote_fileml_service.dart index 4bff78a35b..edfd6293e1 100644 --- a/mobile/lib/services/machine_learning/file_ml/remote_fileml_service.dart +++ b/mobile/lib/services/machine_learning/file_ml/remote_fileml_service.dart @@ -56,7 +56,7 @@ class RemoteFileMLService { } } - Future getFilessEmbedding( + Future getFaceEmbedding( Set fileIds, ) async { try { @@ -119,68 +119,66 @@ class RemoteFileMLService { }, ); } - } Future> _decryptFileMLComputer( - Map args, - ) async { - final result = {}; - final inputs = args["inputs"] as List; - for (final input in inputs) { - final decryptArgs = {}; - decryptArgs["source"] = - CryptoUtil.base642bin(input.embedding.encryptedEmbedding); - decryptArgs["key"] = input.decryptionKey; - decryptArgs["header"] = - CryptoUtil.base642bin(input.embedding.decryptionHeader); - final embeddingData = chachaDecryptData(decryptArgs); - final decodedJson = jsonDecode(utf8.decode(embeddingData)); - final FileMl decodedEmbedding = - FileMl.fromJson(decodedJson as Map); - result[input.embedding.fileID] = decodedEmbedding; - } - return result; + Map args, +) async { + final result = {}; + final inputs = args["inputs"] as List; + for (final input in inputs) { + final decryptArgs = {}; + decryptArgs["source"] = + CryptoUtil.base642bin(input.embedding.encryptedEmbedding); + decryptArgs["key"] = input.decryptionKey; + decryptArgs["header"] = + CryptoUtil.base642bin(input.embedding.decryptionHeader); + final embeddingData = chachaDecryptData(decryptArgs); + final decodedJson = jsonDecode(utf8.decode(embeddingData)); + final FileMl decodedEmbedding = + FileMl.fromJson(decodedJson as Map); + result[input.embedding.fileID] = decodedEmbedding; } + return result; +} bool shouldDiscardRemoteEmbedding(FileMl fileMl) { - if (fileMl.faceEmbedding.version < faceMlVersion) { - debugPrint("Discarding remote embedding for fileID ${fileMl.fileID} " - "because version is ${fileMl.faceEmbedding.version} and we need $faceMlVersion"); - return true; - } - // are all landmarks equal? - bool allLandmarksEqual = true; - if (fileMl.faceEmbedding.faces.isEmpty) { - debugPrint("No face for ${fileMl.fileID}"); + if (fileMl.faceEmbedding.version < faceMlVersion) { + debugPrint("Discarding remote embedding for fileID ${fileMl.fileID} " + "because version is ${fileMl.faceEmbedding.version} and we need $faceMlVersion"); + return true; + } + // are all landmarks equal? + bool allLandmarksEqual = true; + if (fileMl.faceEmbedding.faces.isEmpty) { + debugPrint("No face for ${fileMl.fileID}"); + allLandmarksEqual = false; + } + for (final face in fileMl.faceEmbedding.faces) { + if (face.detection.landmarks.isEmpty) { allLandmarksEqual = false; + break; } - for (final face in fileMl.faceEmbedding.faces) { - if (face.detection.landmarks.isEmpty) { - allLandmarksEqual = false; - break; - } - if (face.detection.landmarks - .any((landmark) => landmark.x != landmark.y)) { - allLandmarksEqual = false; - break; - } + if (face.detection.landmarks.any((landmark) => landmark.x != landmark.y)) { + allLandmarksEqual = false; + break; } - if (allLandmarksEqual) { - debugPrint("Discarding remote embedding for fileID ${fileMl.fileID} " - "because landmarks are equal"); - debugPrint( - fileMl.faceEmbedding.faces - .map((e) => e.detection.landmarks.toString()) - .toList() - .toString(), - ); - return true; - } - if (fileMl.width == null || fileMl.height == null) { - debugPrint("Discarding remote embedding for fileID ${fileMl.fileID} " - "because width is null"); - return true; - } - return false; - } \ No newline at end of file + } + if (allLandmarksEqual) { + debugPrint("Discarding remote embedding for fileID ${fileMl.fileID} " + "because landmarks are equal"); + debugPrint( + fileMl.faceEmbedding.faces + .map((e) => e.detection.landmarks.toString()) + .toList() + .toString(), + ); + return true; + } + if (fileMl.width == null || fileMl.height == null) { + debugPrint("Discarding remote embedding for fileID ${fileMl.fileID} " + "because width is null"); + return true; + } + return false; +}