Skip to content

armgit / ente

Public Imported from GitHub
0

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

Fix suggestion not using previous negative feedback

laurenspriem7509a367c547
diff --git a/mobile/lib/db/ml/base.dart b/mobile/lib/db/ml/base.dart
index 0f8994192e..5bac0233d6 100644
--- a/mobile/lib/db/ml/base.dart
+++ b/mobile/lib/db/ml/base.dart
@@ -13,6 +13,7 @@ abstract class IMLDataDB<T> {
Future<int> getFaceIndexedFileCount({int minimumMlVersion});
Future<Map<String, int>> clusterIdToFaceCount();
Future<Set<String>> getPersonIgnoredClusters(String personID);
+ Future<Map<String, Set<String>>> getPersonToRejectedSuggestions();
Future<Set<String>> getPersonClusterIDs(String personID);
Future<Set<String>> getPersonsClusterIDs(List<String> personID);
Future<void> clearTable();
diff --git a/mobile/lib/db/ml/db.dart b/mobile/lib/db/ml/db.dart
index bba2a96d47..851e349d00 100644
--- a/mobile/lib/db/ml/db.dart
+++ b/mobile/lib/db/ml/db.dart
@@ -212,6 +212,21 @@ class MLDataDB with SqlDbBase implements IMLDataDB<int> {
return ignoredClusterIDs.union(rejectClusterIDs);
}
+ @override
+ Future<Map<String, Set<String>>> getPersonToRejectedSuggestions() async {
+ final db = await instance.asyncDB;
+ final List<Map<String, dynamic>> rejectMaps = await db.getAll(
+ 'SELECT $personIdColumn, $clusterIDColumn FROM $notPersonFeedback',
+ );
+ final Map<String, Set<String>> result = {};
+ for (final map in rejectMaps) {
+ final personID = map[personIdColumn] as String;
+ final clusterID = map[clusterIDColumn] as String;
+ result.putIfAbsent(personID, () => {}).add(clusterID);
+ }
+ return result;
+ }
+
@override
Future<Set<String>> getPersonClusterIDs(String personID) async {
final db = await instance.asyncDB;
diff --git a/mobile/lib/services/machine_learning/face_ml/feedback/cluster_feedback.dart b/mobile/lib/services/machine_learning/face_ml/feedback/cluster_feedback.dart
index 09cf6335a0..2cefa84ac6 100644
--- a/mobile/lib/services/machine_learning/face_ml/feedback/cluster_feedback.dart
+++ b/mobile/lib/services/machine_learning/face_ml/feedback/cluster_feedback.dart
@@ -357,11 +357,23 @@ class ClusterFeedbackService<T> {
allOtherPersonClustersToIgnore,
minClusterSize: kMinimumClusterSizeSearchResult,
);
+
+ final Map<String, Set<String>> personClusterToIgnoredClusters = {};
+ final personToRejectedSuggestions =
+ await mlDataDB.getPersonToRejectedSuggestions();
+ for (final personID in personToRejectedSuggestions.keys) {
+ final personCluster = personIdToBiggestCluster[personID];
+ if (personCluster == null) continue;
+ final ignoredClusters = personToRejectedSuggestions[personID] ?? {};
+ personClusterToIgnoredClusters[personCluster] = ignoredClusters;
+ }
+
final List<(String, double, String)> foundSuggestions =
await calcSuggestionsMeanInComputer(
clusterAvg,
allPersonClusters,
allOtherPersonClustersToIgnore,
+ personClusterToIgnoredClusters: personClusterToIgnoredClusters,
0.55,
);
@@ -1014,8 +1026,9 @@ class ClusterFeedbackService<T> {
Map<String, Vector> clusterAvg,
Set<String> personClusters,
Set<String> ignoredClusters,
- double maxClusterDistance,
- ) async {
+ double maxClusterDistance, {
+ Map<String, Set<String>>? personClusterToIgnoredClusters,
+ }) async {
return await _computer.compute(
_calcSuggestionsMean,
param: {
@@ -1023,6 +1036,7 @@ class ClusterFeedbackService<T> {
'personClusters': personClusters,
'ignoredClusters': ignoredClusters,
'maxClusterDistance': maxClusterDistance,
+ 'personClusterToIgnoredClusters': personClusterToIgnoredClusters,
},
);
}
@@ -1341,6 +1355,9 @@ List<(String, double, String)> _calcSuggestionsMean(Map<String, dynamic> args) {
final Set<String> personClusters = args['personClusters'];
final Set<String> ignoredClusters = args['ignoredClusters'];
final double maxClusterDistance = args['maxClusterDistance'];
+ final Map<String, Set<String>>? personClusterToIgnoredClusters =
+ args['personClusterToIgnoredClusters'];
+ final bool extraIgnoreCheck = personClusterToIgnoredClusters != null;
final Map<String, List<(String, double)>> suggestions = {};
const suggestionMax = 2000;
@@ -1366,6 +1383,12 @@ List<(String, double, String)> _calcSuggestionsMean(Map<String, dynamic> args) {
dev.log('[WARNING] no avg for personcluster $personCluster');
continue;
}
+ if (extraIgnoreCheck &&
+ personClusterToIgnoredClusters[personCluster] != null &&
+ personClusterToIgnoredClusters[personCluster]!
+ .contains(otherClusterID)) {
+ continue;
+ }
final Vector avg = clusterAvg[personCluster]!;
final distance = 1 - avg.dot(otherAvg);
comparisons++;