[mob][photos] Fix breakup cluster for large clusters
This commit is contained in:
parent
bcf78fb4b9
commit
a222e06634
2 changed files with 19 additions and 7 deletions
|
@ -48,7 +48,7 @@ class ClusteringResult {
|
|||
final Map<int, (Uint8List, int)>? newClusterSummaries;
|
||||
|
||||
bool get isEmpty => newFaceIdToCluster.isEmpty;
|
||||
|
||||
|
||||
ClusteringResult({
|
||||
required this.newFaceIdToCluster,
|
||||
this.newClusterSummaries,
|
||||
|
@ -302,7 +302,7 @@ class FaceClusteringService {
|
|||
"input": clusteringInput,
|
||||
"fileIDToCreationTime": fileIDToCreationTime,
|
||||
"distanceThreshold": distanceThreshold,
|
||||
"conservativeDistanceThreshold": distanceThreshold,
|
||||
"conservativeDistanceThreshold": distanceThreshold - 0.08,
|
||||
"useDynamicThreshold": false,
|
||||
},
|
||||
taskName: "createImageEmbedding",
|
||||
|
@ -372,14 +372,14 @@ class FaceClusteringService {
|
|||
);
|
||||
try {
|
||||
if (input.length < 500) {
|
||||
final mergeThreshold = distanceThreshold + 0.08;
|
||||
final mergeThreshold = distanceThreshold;
|
||||
_logger.info(
|
||||
'Running complete clustering on ${input.length} faces with distance threshold $mergeThreshold',
|
||||
);
|
||||
final result = await predictCompleteComputer(
|
||||
input,
|
||||
fileIDToCreationTime: fileIDToCreationTime,
|
||||
distanceThreshold: distanceThreshold,
|
||||
distanceThreshold: distanceThreshold - 0.08,
|
||||
mergeThreshold: mergeThreshold,
|
||||
);
|
||||
if (result.newFaceIdToCluster.isEmpty) return null;
|
||||
|
@ -620,6 +620,17 @@ class FaceClusteringService {
|
|||
newFaceIdToCluster[faceInfo.faceID] = faceInfo.clusterId!;
|
||||
}
|
||||
|
||||
// Create a map of clusterId to faceIds
|
||||
final Map<int, List<String>> clusterIdToFaceIds = {};
|
||||
for (final entry in newFaceIdToCluster.entries) {
|
||||
final clusterID = entry.value;
|
||||
if (clusterIdToFaceIds.containsKey(clusterID)) {
|
||||
clusterIdToFaceIds[clusterID]!.add(entry.key);
|
||||
} else {
|
||||
clusterIdToFaceIds[clusterID] = [entry.key];
|
||||
}
|
||||
}
|
||||
|
||||
stopwatchClustering.stop();
|
||||
log(
|
||||
' [ClusterIsolate] ${DateTime.now()} Clustering for ${sortedFaceInfos.length} embeddings executed in ${stopwatchClustering.elapsedMilliseconds}ms',
|
||||
|
@ -645,6 +656,7 @@ class FaceClusteringService {
|
|||
return ClusteringResult(
|
||||
newFaceIdToCluster: newFaceIdToCluster,
|
||||
newClusterSummaries: newClusterSummaries,
|
||||
newClusterIdToFaceIds: clusterIdToFaceIds,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -429,11 +429,11 @@ class ClusterFeedbackService {
|
|||
await FaceClusteringService.instance.predictWithinClusterComputer(
|
||||
embeddings,
|
||||
fileIDToCreationTime: fileIDToCreationTime,
|
||||
distanceThreshold: 0.14,
|
||||
distanceThreshold: 0.22,
|
||||
);
|
||||
|
||||
if (clusterResult == null || clusterResult.isEmpty) {
|
||||
_logger.info('No clusters found');
|
||||
if (clusterResult == null || clusterResult.newClusterIdToFaceIds == null || clusterResult.isEmpty) {
|
||||
_logger.warning('No clusters found or something went wrong');
|
||||
return ClusteringResult(newFaceIdToCluster: {});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue