Fix the same overwriting bug again

This commit is contained in:
Manav Rathi
2024-09-02 19:55:30 +05:30
parent 5f6ae20f96
commit c403f4f3a1

View File

@@ -297,21 +297,26 @@ export const clusterFaces = (
// Merge the new clusters we got from this batch into the existing
// clusters, using the lookback embeddings as a link when they exist.
let [existingCount, newCount] = [0, 0];
for (const batchCluster of batchClusters) {
// If any of the faces in this batch cluster were part of an
// existing cluster, also add the other faces from that batch to
// that existing cluster.
// Find the existing clusters before modifying any state so that we
// don't end up merging into clusters from the same batch.
const annotatedBatch = batchClusters.map((batchCluster) => {
let existingClusterIndex: number | undefined;
for (const j of batchCluster) {
const faceIndex = batchStart + j;
existingClusterIndex = clusterIndexForFaceIndex.get(faceIndex);
if (existingClusterIndex !== undefined) break;
}
return [batchCluster, existingClusterIndex] as const;
});
let [existingCount, newCount] = [0, 0];
for (const [batchCluster, existingClusterIndex] of annotatedBatch) {
if (existingClusterIndex !== undefined) {
// If any of the faces in this batch cluster were part of an
// existing cluster, also add the other faces from that batch to
// that existing cluster.
const existingCluster = ensure(clusters[existingClusterIndex]);
for (const j of batchCluster) {
const faceIndex = batchStart + j;