diff --git a/mobile/lib/face/db.dart b/mobile/lib/face/db.dart index 95aced5a5..e45ea4252 100644 --- a/mobile/lib/face/db.dart +++ b/mobile/lib/face/db.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import "dart:convert" show json; import "dart:io" show Directory; import "dart:math"; @@ -11,7 +10,6 @@ import 'package:path_provider/path_provider.dart'; import "package:photos/extensions/stop_watch.dart"; import 'package:photos/face/db_fields.dart'; import "package:photos/face/db_model_mappers.dart"; -import "package:photos/face/model/detection.dart"; import "package:photos/face/model/face.dart"; import "package:photos/models/file/file.dart"; import "package:photos/services/machine_learning/face_ml/face_clustering/face_info_for_clustering.dart"; @@ -455,31 +453,6 @@ class FaceMLDataDB { ); } - // TODO: remove this method and replace by correct logic during indexing - Future> getFaceIdsToIsSidewaysFaceTEMP() async { - final db = await instance.sqliteAsyncDB; - final List> maps = await db.getAll( - 'SELECT $faceIDColumn, $faceDetectionColumn FROM $facesTable', - ); - - final time = DateTime.now(); - final Map result = {}; - for (final map in maps) { - final faceID = map[faceIDColumn] as String; - final detection = - Detection.fromJson(json.decode(map[faceDetectionColumn] as String)); - result[faceID] = detection.faceIsSideways(); - } - _logger.info( - 'decoding detections and calculating face sideways bools took ${DateTime.now().difference(time).inMilliseconds} ms', - ); - final double sidewaysRatio = - result.values.where((e) => e).length / result.length; - _logger.info('sideways face ratio: $sidewaysRatio'); - - return result; - } - Future> getFaceInfoForClustering({ double minScore = kMinimumQualityFaceScore, int minClarity = kLaplacianHardThreshold, @@ -493,14 +466,11 @@ class FaceMLDataDB { ); final db = await instance.sqliteAsyncDB; - final Map faceIdsToIsSideways = - await getFaceIdsToIsSidewaysFaceTEMP(); - final Set result = {}; while (true) { // Query a batch of rows final List> maps = await db.getAll( - 'SELECT $faceIDColumn, $faceEmbeddingBlob, $faceScore, $faceBlur FROM $facesTable' + 'SELECT $faceIDColumn, $faceEmbeddingBlob, $faceScore, $faceBlur, $isSideways FROM $facesTable' ' WHERE $faceScore > $minScore AND $faceBlur > $minClarity' ' ORDER BY $faceIDColumn' ' DESC LIMIT $batchSize OFFSET $offset', @@ -522,7 +492,7 @@ class FaceMLDataDB { embeddingBytes: map[faceEmbeddingBlob] as Uint8List, faceScore: map[faceScore] as double, blurValue: map[faceBlur] as double, - isSideways: faceIdsToIsSideways[faceID] ?? false, + isSideways: (map[isSideways] as int) == 1, ); result.add(faceInfo); } diff --git a/mobile/lib/face/db_fields.dart b/mobile/lib/face/db_fields.dart index 206806e0c..c7d0c703c 100644 --- a/mobile/lib/face/db_fields.dart +++ b/mobile/lib/face/db_fields.dart @@ -8,6 +8,7 @@ const faceDetectionColumn = 'detection'; const faceEmbeddingBlob = 'eBlob'; const faceScore = 'score'; const faceBlur = 'blur'; +const isSideways = 'is_sideways'; const imageWidth = 'width'; const imageHeight = 'height'; const faceClusterId = 'cluster_id'; @@ -20,6 +21,7 @@ const createFacesTable = '''CREATE TABLE IF NOT EXISTS $facesTable ( $faceEmbeddingBlob BLOB NOT NULL, $faceScore REAL NOT NULL, $faceBlur REAL NOT NULL DEFAULT $kLapacianDefault, + $isSideways INTEGER NOT NULL DEFAULT 0, $imageHeight INTEGER NOT NULL DEFAULT 0, $imageWidth INTEGER NOT NULL DEFAULT 0, $mlVersionColumn INTEGER NOT NULL DEFAULT -1, diff --git a/mobile/lib/face/db_model_mappers.dart b/mobile/lib/face/db_model_mappers.dart index 683281e93..70dc77915 100644 --- a/mobile/lib/face/db_model_mappers.dart +++ b/mobile/lib/face/db_model_mappers.dart @@ -34,6 +34,7 @@ Map mapRemoteToFaceDB(Face face) { ).writeToBuffer(), faceScore: face.score, faceBlur: face.blur, + isSideways: face.detection.faceIsSideways() ? 1 : 0, mlVersionColumn: faceMlVersion, imageWidth: face.fileInfo?.imageWidth ?? 0, imageHeight: face.fileInfo?.imageHeight ?? 0,