π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Vars
Manav Rathicd5e40a1f504
diff --git a/web/packages/new/photos/services/ml/cluster-new.ts b/web/packages/new/photos/services/ml/cluster-new.tsindex 9d5c57b84d..c0f5dd51c2 100644--- a/web/packages/new/photos/services/ml/cluster-new.ts+++ b/web/packages/new/photos/services/ml/cluster-new.ts@@ -190,9 +190,9 @@ export const clusterFaces = async (faceIndexes: FaceIndex[]) => {const faceAndNeigbours: FaceNeighbours[] = [];// For each face,- for (const [i, { faceID, blur, embedding }] of faces.entries()) {+ for (const [i, fi] of faces.entries()) {// If the face is already part of a cluster, then skip it.- if (clusterIDForFaceID.get(faceID)) continue;+ if (clusterIDForFaceID.get(fi.faceID)) continue;// Find the nearest neighbour from among all the other faces.let nn: Face | undefined;@@ -207,26 +207,26 @@ export const clusterFaces = async (faceIndexes: FaceIndex[]) => {// Can't find a way of avoiding the null assertion here.// eslint-disable-next-line @typescript-eslint/no-non-null-assertion- const n = faces[j]!;+ const fj = faces[j]!;// The vectors are already normalized, so we can directly use their// dot product as their cosine similarity.- const csim = dotProduct(embedding, n.embedding);+ const csim = dotProduct(fi.embedding, fj.embedding);// TODO-Cluster Delete me and uncomment the check above// Skip ourselves.if (i == j) {- neighbours.push({ face: n, cosineSimilarity: csim });+ neighbours.push({ face: fj, cosineSimilarity: csim });continue;}- const threshold = blur < 100 || n.blur < 100 ? 0.7 : 0.6;+ const threshold = fi.blur < 100 || fj.blur < 100 ? 0.7 : 0.6;if (csim > threshold && csim > nnCosineSimilarity) {- nn = n;+ nn = fj;nnCosineSimilarity = csim;}- neighbours.push({ face: n, cosineSimilarity: csim });+ neighbours.push({ face: fj, cosineSimilarity: csim });}neighbours = neighbours.sort(@@ -235,8 +235,11 @@ export const clusterFaces = async (faceIndexes: FaceIndex[]) => {// eslint-disable-next-line @typescript-eslint/no-non-null-assertionfaceAndNeigbours.push({ face: faces[i]!, neighbours });+ const { faceID } = fi;+if (nn) {// Found a neighbour near enough.+ const nnFaceID = nn.faceID;// Find the cluster the nearest neighbour belongs to, if any.const nnClusterID = clusterIDForFaceID.get(nn.faceID);@@ -256,11 +259,11 @@ export const clusterFaces = async (faceIndexes: FaceIndex[]) => {const cluster = {id: newClusterID(),- faceIDs: [faceID, nn.faceID],+ faceIDs: [faceID, nnFaceID],};clusterIndexForClusterID.set(cluster.id, clusters.length);clusterIDForFaceID.set(faceID, cluster.id);- clusterIDForFaceID.set(nn.faceID, cluster.id);+ clusterIDForFaceID.set(nnFaceID, cluster.id);clusters.push(cluster);}} else {