π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Show debug info for cluster suggestions
laurenspriemb56b0c47d089
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.dartindex dfb6675b4b..bb91de4191 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@@ -63,7 +63,11 @@ class ClusterFeedbackService {return suggestions;}- Future<List<int>> getSuggestionsUsingMedian(+ /// Returns a list of suggestions. For each suggestion we return a record consisting of the following elements:+ /// 1. clusterID: the ID of the cluster+ /// 2. distance: the distance between the person's cluster and the suggestion+ /// 3. usedMean: whether the suggestion was found using the mean (true) or the median (false)+ Future<List<(int, double, bool)>> getSuggestionsUsingMedian(Person p, {int sampleSize = 50,double maxMedianDistance = 0.65,@@ -114,7 +118,9 @@ class ClusterFeedbackService {_logger.info("Already found good suggestions using mean: $suggestClusterIds, with sizes $suggestClusterIdsSizes and distances $suggestClusterIdsDistances",);- return suggestClusterIds.map((e) => e.$1).toList(growable: false);+ return suggestClusterIds+ .map((e) => (e.$1, e.$2, true))+ .toList(growable: false);}// Find the other cluster candidates based on the median@@ -128,7 +134,7 @@ class ClusterFeedbackService {if (moreSuggestionsMean.isEmpty) {_logger.info("No suggestions found using mean, even with higher threshold");- return <int>[];+ return [];}final List<(int, double)> temp = [];@@ -201,13 +207,13 @@ class ClusterFeedbackService {watch.log("Finished median test");if (suggestionsMedian.isEmpty) {_logger.info("No suggestions found using median");- return <int>[];+ return [];} else {_logger.info("Found suggestions using median: $suggestionsMedian");}- final List<int> finalSuggestionsMedian = suggestionsMedian- .map(((e) => e.$1))+ final List<(int, double, bool)> finalSuggestionsMedian = suggestionsMedian+ .map(((e) => (e.$1, e.$2, false))).toList(growable: false).reversed.toList(growable: false);@@ -230,7 +236,12 @@ class ClusterFeedbackService {return finalSuggestionsMedian;}- Future<List<(int, List<EnteFile>)>> getClusterFilesForPersonID(+ /// Returns a list of cluster suggestions for a person. Each suggestion is a tuple of the following elements:+ /// 1. clusterID: the ID of the cluster+ /// 2. distance: the distance between the person's cluster and the suggestion+ /// 3. bool: whether the suggestion was found using the mean (true) or the median (false)+ /// 4. List<EnteFile>: the files in the cluster+ Future<List<(int, double, bool, List<EnteFile>)>> getClusterFilesForPersonID(Person person,) async {_logger.info(@@ -249,12 +260,14 @@ class ClusterFeedbackService {try {// Get the suggestions for the person using centroids and median- final List<int> suggestClusterIds =+ final List<(int, double, bool)> suggestClusterIds =await getSuggestionsUsingMedian(person);// Get the files for the suggestions- final Map<int, Set<int>> fileIdToClusterID = await FaceMLDataDB.instance- .getFileIdToClusterIDSetForCluster(suggestClusterIds.toSet());+ final Map<int, Set<int>> fileIdToClusterID =+ await FaceMLDataDB.instance.getFileIdToClusterIDSetForCluster(+ suggestClusterIds.map((e) => e.$1).toSet(),+ );final Map<int, List<EnteFile>> clusterIDToFiles = {};final allFiles = await SearchService.instance.getAllFiles();for (final f in allFiles) {@@ -271,11 +284,16 @@ class ClusterFeedbackService {}}- final List<(int, List<EnteFile>)> clusterIdAndFiles = [];- for (final clusterId in suggestClusterIds) {- if (clusterIDToFiles.containsKey(clusterId)) {+ final List<(int, double, bool, List<EnteFile>)> clusterIdAndFiles = [];+ for (final clusterSuggestion in suggestClusterIds) {+ if (clusterIDToFiles.containsKey(clusterSuggestion.$1)) {clusterIdAndFiles.add(- (clusterId, clusterIDToFiles[clusterId]!),+ (+ clusterSuggestion.$1,+ clusterSuggestion.$2,+ clusterSuggestion.$3,+ clusterIDToFiles[clusterSuggestion.$1]!+ ),);}}@@ -397,6 +415,7 @@ class ClusterFeedbackService {return clusterAvg;}+ /// Returns a map of person's clusterID to map of closest clusterID to with disstanceMap<int, List<(int, double)>> _calcSuggestionsMean(Map<int, List<double>> clusterAvg,Set<int> personClusters,diff --git a/mobile/lib/ui/viewer/people/person_cluster_suggestion.dart b/mobile/lib/ui/viewer/people/person_cluster_suggestion.dartindex 26da744d6e..b350243b27 100644--- a/mobile/lib/ui/viewer/people/person_cluster_suggestion.dart+++ b/mobile/lib/ui/viewer/people/person_cluster_suggestion.dart@@ -1,5 +1,6 @@import "dart:math";+import "package:flutter/foundation.dart" show kDebugMode;import "package:flutter/material.dart";import "package:photos/core/event_bus.dart";import "package:photos/events/people_changed_event.dart";@@ -30,7 +31,8 @@ class _PersonClustersState extends State<PersonReviewClusterSuggestion> {Key futureBuilderKey = UniqueKey();// Declare a variable for the future- late Future<List<(int, List<EnteFile>)>> futureClusterSuggestions;+ late Future<List<(int, double, bool, List<EnteFile>)>>+ futureClusterSuggestions;@overridevoid initState() {@@ -45,7 +47,7 @@ class _PersonClustersState extends State<PersonReviewClusterSuggestion> {appBar: AppBar(title: const Text('Review suggestions'),),- body: FutureBuilder<List<(int, List<EnteFile>)>>(+ body: FutureBuilder<List<(int, double, bool, List<EnteFile>)>>(key: futureBuilderKey,future: futureClusterSuggestions,builder: (context, snapshot) {@@ -62,7 +64,9 @@ class _PersonClustersState extends State<PersonReviewClusterSuggestion> {final numberOfDifferentSuggestions = snapshot.data!.length;final currentSuggestion = snapshot.data![currentSuggestionIndex];final int clusterID = currentSuggestion.$1;- final List<EnteFile> files = currentSuggestion.$2;+ final double distance = currentSuggestion.$2;+ final bool isMean = currentSuggestion.$3;+ final List<EnteFile> files = currentSuggestion.$4;return InkWell(onTap: () {Navigator.of(context).push(@@ -82,6 +86,8 @@ class _PersonClustersState extends State<PersonReviewClusterSuggestion> {),child: _buildSuggestionView(clusterID,+ distance,+ isMean,files,numberOfDifferentSuggestions,),@@ -140,12 +146,19 @@ class _PersonClustersState extends State<PersonReviewClusterSuggestion> {Widget _buildSuggestionView(int clusterID,+ double distance,+ bool isMean,List<EnteFile> files,int numberOfSuggestions,) {return Column(key: ValueKey("cluster_id-$clusterID"),children: <Widget>[+ if (kDebugMode)+ Text(+ "Debug: Cluster ID: $clusterID, Distance: ${distance.toStringAsFixed(3)}, IsMean: $isMean",+ style: getEnteTextTheme(context).smallMuted,+ ),Text(files.length > 1? "These photos belong to ${widget.person.attr.name}?"