diff --git a/mobile/lib/face/db.dart b/mobile/lib/face/db.dart index c8b4f75f7..bc4b15885 100644 --- a/mobile/lib/face/db.dart +++ b/mobile/lib/face/db.dart @@ -154,7 +154,7 @@ class FaceMLDataDB { final Map result = {}; final db = await instance.database; final List> maps = await db.rawQuery( - 'SELECT $fileIDColumn, COUNT(*) as count FROM $facesTable where $faceScore > 0.8 GROUP BY $fileIDColumn', + 'SELECT $fileIDColumn, COUNT(*) as count FROM $facesTable where $faceScore > $kMinFaceDetectionScore GROUP BY $fileIDColumn', ); for (final map in maps) { @@ -197,7 +197,7 @@ class FaceMLDataDB { final clusterIDs = cluterRows.map((e) => e[cluserIDColumn] as int).toList(); final List> faceMaps = await db.rawQuery( - 'SELECT * FROM $facesTable where $faceClusterId IN (${clusterIDs.join(",")}) AND $fileIDColumn in (${fileId.join(",")}) AND $faceScore > 0.8 ORDER BY $faceScore DESC', + 'SELECT * FROM $facesTable where $faceClusterId IN (${clusterIDs.join(",")}) AND $fileIDColumn in (${fileId.join(",")}) AND $faceScore > $kMinHighQualityFaceScore ORDER BY $faceScore DESC', ); if (faceMaps.isNotEmpty) { if (avatarFileId != null) { @@ -341,7 +341,7 @@ class FaceMLDataDB { /// /// Only selects faces with score greater than [minScore] and blur score greater than [minClarity] Future> getFaceEmbeddingMap({ - double minScore = kMinFaceScore, + double minScore = kMinHighQualityFaceScore, int minClarity = kLaplacianThreshold, int maxRows = 20000, }) async { @@ -398,7 +398,7 @@ class FaceMLDataDB { facesTable, columns: [faceIDColumn, faceEmbeddingBlob], where: - '$faceScore > 0.8 AND $faceBlur > $kLaplacianThreshold AND $fileIDColumn IN (${fileIDs.join(",")})', + '$faceScore > $kMinHighQualityFaceScore AND $faceBlur > $kLaplacianThreshold AND $fileIDColumn IN (${fileIDs.join(",")})', limit: batchSize, offset: offset, orderBy: '$faceIDColumn DESC', diff --git a/mobile/lib/face/model/face.dart b/mobile/lib/face/model/face.dart index c29c03ae1..af151c2ec 100644 --- a/mobile/lib/face/model/face.dart +++ b/mobile/lib/face/model/face.dart @@ -11,7 +11,7 @@ class Face { bool get isBlurry => blur < kLaplacianThreshold; - bool get hasHighScore => score > kMinFaceScore; + bool get hasHighScore => score > kMinHighQualityFaceScore; bool get isHighQuality => (!isBlurry) && hasHighScore; diff --git a/mobile/lib/services/face_ml/face_filtering/face_filtering_constants.dart b/mobile/lib/services/face_ml/face_filtering/face_filtering_constants.dart index 478161f22..a1970fd4d 100644 --- a/mobile/lib/services/face_ml/face_filtering/face_filtering_constants.dart +++ b/mobile/lib/services/face_ml/face_filtering/face_filtering_constants.dart @@ -1,8 +1,13 @@ +import "package:photos/services/face_ml/face_detection/yolov5face/onnx_face_detection.dart"; + /// Blur detection threshold const kLaplacianThreshold = 15; /// Default blur value const kLapacianDefault = 10000.0; -/// The minimum score for a face to be considered a face -const kMinFaceScore = 0.78; \ No newline at end of file +/// The minimum score for a face to be considered a high quality face for clustering and person detection +const kMinHighQualityFaceScore = 0.78; + +/// The minimum score for a face to be detected, regardless of quality. Use [kMinHighQualityFaceScore] for high quality faces. +const kMinFaceDetectionScore = YoloOnnxFaceDetection.kMinScoreSigmoidThreshold; diff --git a/mobile/lib/services/face_ml/face_ml_service.dart b/mobile/lib/services/face_ml/face_ml_service.dart index db3931ed7..a3b36e192 100644 --- a/mobile/lib/services/face_ml/face_ml_service.dart +++ b/mobile/lib/services/face_ml/face_ml_service.dart @@ -362,7 +362,9 @@ class FaceMlService { await clusterAllImages(); } - Future clusterAllImages({double minFaceScore = kMinFaceScore}) async { + Future clusterAllImages({ + double minFaceScore = kMinHighQualityFaceScore, + }) async { _logger.info("`clusterAllImages()` called"); try {