Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Rearrange

Manav Rathi1efbbf2b2f34
diff --git a/web/packages/new/photos/services/ml/cluster.ts b/web/packages/new/photos/services/ml/cluster.ts
index 8ea107e78f..675830dd47 100644
--- a/web/packages/new/photos/services/ml/cluster.ts
+++ b/web/packages/new/photos/services/ml/cluster.ts
@@ -12,7 +12,6 @@ import {
type FaceIndex,
} from "./face";
import { dotProduct } from "./math";
-import type { Person } from "./people";
/**
* A face cluster is an set of faces, and a nanoid to uniquely identify it.
@@ -184,26 +183,26 @@ export const clusterFaces = async (
(a, b) => b.faces.length - a.faces.length,
);
- // TODO-Cluster
- // This isn't really part of the clustering, but help the main thread out by
- // pre-computing temporary in-memory people, one per cluster.
-
- // For fast reverse lookup - map from face ids to the face.
- const faceForFaceID = new Map(faces.map((f) => [f.faceID, f]));
-
- const people = toPeople(sortedClusters, localFileByID, faceForFaceID);
-
const clusteredFaceCount = faceIDToClusterID.size;
const timeTakenMs = Date.now() - t;
log.info(
`Generated ${sortedClusters.length} clusters from ${faces.length} faces (${clusteredFaceCount} clustered ${faces.length - clusteredFaceCount} unclustered) (${timeTakenMs} ms)`,
);
- // reconcileClusters
- // Save local
- // updated map -> remote - Put
+ // // TODO-Cluster
+ // // This isn't really part of the clustering, but help the main thread out by
+ // // pre-computing temporary in-memory people, one per cluster.
+
+ // // For fast reverse lookup - map from face ids to the face.
+ // const faceForFaceID = new Map(faces.map((f) => [f.faceID, f]));
+
+ // const people = toPeople(sortedClusters, localFileByID, faceForFaceID);
- return { clusters: sortedClusters, people };
+ // // reconcileClusters
+ // // Save local
+ // // updated map -> remote - Put
+
+ return { clusters: sortedClusters, people: [] };
};
/**
@@ -318,43 +317,3 @@ const clusterBatchLinear = async (
}
}
};
-
-/**
- * Construct a {@link Person} object for each cluster.
- */
-const toPeople = (
- clusters: FaceCluster[],
- localFileByID: Map<number, EnteFile>,
- faceForFaceID: Map<string, ClusterFace>,
-): Person[] =>
- clusters
- .map((cluster) => {
- const faces = cluster.faces.map((id) =>
- ensure(faceForFaceID.get(id)),
- );
-
- const faceIDs = cluster.faces;
- const fileIDs = faceIDs.map((faceID) =>
- ensure(fileIDFromFaceID(faceID)),
- );
-
- const topFace = faces.reduce((top, face) =>
- top.score > face.score ? top : face,
- );
-
- const displayFaceID = topFace.faceID;
- const displayFaceFileID = ensure(fileIDFromFaceID(displayFaceID));
- const displayFaceFile = ensure(
- localFileByID.get(displayFaceFileID),
- );
-
- return {
- id: cluster.id,
- name: undefined,
- faceIDs,
- fileIDs: [...new Set(fileIDs)],
- displayFaceID,
- displayFaceFile,
- };
- })
- .sort((a, b) => b.faceIDs.length - a.faceIDs.length);
diff --git a/web/packages/new/photos/services/ml/people.ts b/web/packages/new/photos/services/ml/people.ts
index 196a82c3b1..934575017f 100644
--- a/web/packages/new/photos/services/ml/people.ts
+++ b/web/packages/new/photos/services/ml/people.ts
@@ -5,7 +5,8 @@ import { getLocalFiles } from "../files";
import { pullUserEntities, savedCGroups } from "../user-entity";
import type { FaceCluster } from "./cluster";
import { getFaceIndexes } from "./db";
-import { fileIDFromFaceID } from "./face";
+import { fileIDFromFaceID, type Face } from "./face";
+import { ensure } from "@/utils/ensure";
/**
* A cgroup ("cluster group") is a group of clusters (possibly containing just a
@@ -234,3 +235,44 @@ export const namedPeopleFromCGroups = async (): Promise<NamedPerson[]> => {
.filter((c) => !!c)
.sort((a, b) => b.fileIDs.length - a.fileIDs.length);
};
+
+
+/**
+ * Construct a {@link Person} object for each cluster.
+ */
+export const toPeople = (
+ clusters: FaceCluster[],
+ localFileByID: Map<number, EnteFile>,
+ faceForFaceID: Map<string, Face>,
+): Person[] =>
+ clusters
+ .map((cluster) => {
+ const faces = cluster.faces.map((id) =>
+ ensure(faceForFaceID.get(id)),
+ );
+
+ const faceIDs = cluster.faces;
+ const fileIDs = faceIDs.map((faceID) =>
+ ensure(fileIDFromFaceID(faceID)),
+ );
+
+ const topFace = faces.reduce((top, face) =>
+ top.score > face.score ? top : face,
+ );
+
+ const displayFaceID = topFace.faceID;
+ const displayFaceFileID = ensure(fileIDFromFaceID(displayFaceID));
+ const displayFaceFile = ensure(
+ localFileByID.get(displayFaceFileID),
+ );
+
+ return {
+ id: cluster.id,
+ name: undefined,
+ faceIDs,
+ fileIDs: [...new Set(fileIDs)],
+ displayFaceID,
+ displayFaceFile,
+ };
+ })
+ .sort((a, b) => b.faceIDs.length - a.faceIDs.length);