π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Preview
Manav Rathi2179b193d21a
diff --git a/web/apps/photos/src/pages/cluster-debug.tsx b/web/apps/photos/src/pages/cluster-debug.tsxindex c6abe7226f..dcffaecfd2 100644--- a/web/apps/photos/src/pages/cluster-debug.tsx+++ b/web/apps/photos/src/pages/cluster-debug.tsx@@ -53,8 +53,8 @@ export default function ClusterDebug() {{`${clusterRes.clusters.length} clusters`}</Typography><Typography variant="small" color="text.muted">- Showing only upto first 30 faces (and only upto 30 nearest- neighbours of each).+ Showing only top 20 and bottom 10 clusters (and only up to 50 faces in+ each, sorted by cosine distance to highest scoring face in the cluster).</Typography><hr /><Container>diff --git a/web/packages/new/photos/services/ml/cluster-new.ts b/web/packages/new/photos/services/ml/cluster-new.tsindex e934b54676..983c128a6a 100644--- a/web/packages/new/photos/services/ml/cluster-new.ts+++ b/web/packages/new/photos/services/ml/cluster-new.ts@@ -124,6 +124,16 @@ interface FaceNeighbour {cosineSimilarity: number;}+export interface ClusterPreview {+ clusterSize: number;+ faces: ClusterPreviewFace[];+}++interface ClusterPreviewFace {+ face: Face;+ cosineSimilarity: number;+}+/*** Cluster faces into groups.*@@ -455,22 +465,56 @@ export const clusterFacesHdb = async (faceIndexes: FaceIndex[]) => {}// Convert into the data structure we're using to debug/visualize.- const faceAndNeigbours: FaceNeighbours[] = [];- const topFaces = faces.sort((a, b) => b.score - a.score).slice(0, 30);- for (const fi of topFaces) {- let neighbours: FaceNeighbour[] = [];- for (const fj of faces) {- // The vectors are already normalized, so we can directly use their- // dot product as their cosine similarity.- const csim = dotProduct(fi.embedding, fj.embedding);- neighbours.push({ face: fj, cosineSimilarity: csim });- }+ // const faceAndNeigbours: FaceNeighbours[] = [];+ // const topFaces = faces.sort((a, b) => b.score - a.score).slice(0, 30);+ // for (const fi of topFaces) {+ // let neighbours: FaceNeighbour[] = [];+ // for (const fj of faces) {+ // // The vectors are already normalized, so we can directly use their+ // // dot product as their cosine similarity.+ // const csim = dotProduct(fi.embedding, fj.embedding);+ // neighbours.push({ face: fj, cosineSimilarity: csim });+ // }++ // neighbours = neighbours+ // .sort((a, b) => b.cosineSimilarity - a.cosineSimilarity)+ // .slice(0, 30);++ // faceAndNeigbours.push({ face: fi, neighbours });+ // }- neighbours = neighbours- .sort((a, b) => b.cosineSimilarity - a.cosineSimilarity)- .slice(0, 30);+ // Convert into the data structure we're using to debug/visualize.+ //+ // > Showing only top 20 and bottom 10 clusters (and only up to 50 faces in+ // > each, sorted by cosine distance to highest scoring face in the+ // > cluster).- faceAndNeigbours.push({ face: fi, neighbours });+ const sortedClusters = clusters.sort(+ (a, b) => b.faceIDs.length - a.faceIDs.length,+ );+ const debugClusters =+ sortedClusters.length < 30+ ? sortedClusters+ : sortedClusters.slice(0, 20).concat(sortedClusters.slice(-10));+ const clusterPreviews: ClusterPreview[] = [];+ for (const cluster of debugClusters) {+ const faces = cluster.faceIDs.map((id) =>+ ensure(faceForFaceID.get(id)),+ );+ const topFace = faces.reduce((max, face) =>+ max.score > face.score ? max : face,+ );+ const previewFaces: ClusterPreviewFace[] = [];+ for (const face of faces) {+ const csim = dotProduct(topFace.embedding, face.embedding);+ previewFaces.push({ face, cosineSimilarity: csim });+ }+ clusterPreviews.push({+ clusterSize: cluster.faceIDs.length,+ faces: previewFaces+ .sort((a, b) => b.cosineSimilarity - a.cosineSimilarity)+ .slice(0, 50),+ });}// Prune too small clusters.@@ -518,5 +562,5 @@ export const clusterFacesHdb = async (faceIndexes: FaceIndex[]) => {`Clustered ${faces.length} faces into ${validClusters.length} clusters (${Date.now() - t} ms)`,);- return { faces, clusters: validClusters, cgroups, faceAndNeigbours };+ return { faces, clusters: validClusters, cgroups, clusterPreviews };};diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.tsindex 53940232f6..df8d08235c 100644--- a/web/packages/new/photos/services/ml/index.ts+++ b/web/packages/new/photos/services/ml/index.ts@@ -360,6 +360,18 @@ export interface FaceFileNeighbour {cosineSimilarity: number;}+// "with file"+export interface ClusterPreviewWF {+ clusterSize: number;+ faces: ClusterPreviewFaceWF[];+}++interface ClusterPreviewFaceWF {+ face: Face;+ enteFile: EnteFile;+ cosineSimilarity: number;+}+export interface ClusterDebugPageContents {faceFNs: FaceFileNeighbours[];clusters: FaceCluster[];@@ -377,7 +389,7 @@ export const wipClusterDebugPageContents = async (): Promise<triggerStatusUpdate();// const { faceAndNeigbours, clusters, cgroups } = await clusterFaces(- const { faceAndNeigbours, clusters, cgroups } = await clusterFacesHdb(+ const { clusterPreviews, clusters, cgroups } = await clusterFacesHdb(await faceIndexes(),);const searchPersons = await convertToSearchPersons(clusters, cgroups);@@ -387,9 +399,19 @@ export const wipClusterDebugPageContents = async (): Promise<const fileForFace = ({ faceID }: Face) =>ensure(localFileByID.get(ensure(fileIDFromFaceID(faceID))));- const faceFNs = faceAndNeigbours.map(({ face, neighbours }) => ({- face,- neighbours: neighbours.map(({ face, cosineSimilarity }) => ({+ // const faceFNs = faceAndNeigbours.map(+ // ({ topFace: face, faces: neighbours }) => ({+ // face,+ // neighbours: neighbours.map(({ face, cosineSimilarity }) => ({+ // face,+ // enteFile: fileForFace(face),+ // cosineSimilarity,+ // })),+ // }),+ // );+ const clusterPreviewWFs = clusterPreviews.map(({ clusterSize, faces }) => ({+ clusterSize,+ faces: faces.map(({ face, cosineSimilarity }) => ({face,enteFile: fileForFace(face),cosineSimilarity,@@ -406,7 +428,7 @@ export const wipClusterDebugPageContents = async (): Promise<_wip_searchPersons = searchPersons;triggerStatusUpdate();- return { faceFNs, clusters, clusterIDForFaceID };+ return { clusterPreviewWFs, clusters, clusterIDForFaceID };};export const wipCluster = () => void wipClusterDebugPageContents();