Integrate
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
isMLEnabled,
|
||||
isMLSupported,
|
||||
mlStatusSnapshot,
|
||||
wipCluster,
|
||||
} from "@/new/photos/services/ml";
|
||||
import type { Person } from "@/new/photos/services/ml/people";
|
||||
import { EnteFile } from "@/new/photos/types/file";
|
||||
@@ -415,6 +416,7 @@ function convertSuggestionToSearchQuery(option: Suggestion): Search {
|
||||
|
||||
async function getAllPeople(limit: number = undefined) {
|
||||
let people: Array<Person> = []; // await mlIDbStorage.getAllPeople();
|
||||
people = await wipCluster();
|
||||
// await mlPeopleStore.iterate<Person, void>((person) => {
|
||||
// people.push(person);
|
||||
// });
|
||||
|
||||
@@ -5,11 +5,11 @@ import type { FaceIndex } from "./face";
|
||||
import { dotProduct } from "./math";
|
||||
|
||||
/**
|
||||
* A cluster is an set of faces.
|
||||
* A face cluster is an set of faces.
|
||||
*
|
||||
* Each cluster has an id so that a Person (a set of clusters) can refer to it.
|
||||
*/
|
||||
export interface Cluster {
|
||||
export interface FaceCluster {
|
||||
/**
|
||||
* A randomly generated ID to uniquely identify this cluster.
|
||||
*/
|
||||
@@ -31,7 +31,7 @@ export interface Cluster {
|
||||
*
|
||||
* For ease of transportation, the Person entity on remote looks like
|
||||
*
|
||||
* { name, clusters: { cluster_id, face_ids }}
|
||||
* { name, clusters: [{ clusterID, faceIDs }] }
|
||||
*
|
||||
* That is, it has the clusters embedded within itself.
|
||||
*/
|
||||
@@ -78,7 +78,7 @@ export const clusterFaces = (faceIndexes: FaceIndex[]) => {
|
||||
|
||||
const faces = [...faceIDAndEmbeddings(faceIndexes)];
|
||||
|
||||
const clusters: Cluster[] = [];
|
||||
const clusters: FaceCluster[] = [];
|
||||
const clusterIndexByFaceID = new Map<string, number>();
|
||||
for (const [i, { faceID, embedding }] of faces.entries()) {
|
||||
let j = 0;
|
||||
@@ -118,7 +118,7 @@ export const clusterFaces = (faceIndexes: FaceIndex[]) => {
|
||||
`Clustered ${faces.length} faces into ${clusters.length} clusters (${Date.now() - t} ms)`,
|
||||
);
|
||||
|
||||
return undefined;
|
||||
return clusters;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
faceIndexes,
|
||||
indexableAndIndexedCounts,
|
||||
} from "./db";
|
||||
import type { Person } from "./people";
|
||||
import { MLWorker } from "./worker";
|
||||
import type { CLIPMatches } from "./worker-types";
|
||||
|
||||
@@ -262,8 +263,6 @@ const mlSync = async () => {
|
||||
triggerStatusUpdate();
|
||||
|
||||
if (_isMLEnabled) void worker().then((w) => w.sync());
|
||||
// TODO-ML
|
||||
if (_isMLEnabled) void wipCluster();
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -288,6 +287,8 @@ export const indexNewUpload = (enteFile: EnteFile, uploadItem: UploadItem) => {
|
||||
void worker().then((w) => w.onUpload(enteFile, uploadItem));
|
||||
};
|
||||
|
||||
let last: Person[] = [];
|
||||
|
||||
/**
|
||||
* WIP! Don't enable, dragon eggs are hatching here.
|
||||
*/
|
||||
@@ -295,7 +296,24 @@ export const wipCluster = async () => {
|
||||
if (!isDevBuild || !(await isInternalUser())) return;
|
||||
if (!process.env.NEXT_PUBLIC_ENTE_WIP_CL) return;
|
||||
|
||||
clusterFaces(await faceIndexes());
|
||||
if (last.length) return last;
|
||||
|
||||
const clusters = clusterFaces(await faceIndexes());
|
||||
|
||||
const people: Person[] = []; // await mlIDbStorage.getAllPeople();
|
||||
for (const cluster of clusters) {
|
||||
people.push({
|
||||
id: Math.random(), //cluster.id,
|
||||
name: "test",
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
files: cluster.faceIDs.map((s) => parseInt(s.split("_")[0]!)),
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
displayFaceId: cluster.faceIDs[0]!,
|
||||
});
|
||||
}
|
||||
|
||||
last = people;
|
||||
return people;
|
||||
};
|
||||
|
||||
export type MLStatus =
|
||||
|
||||
Reference in New Issue
Block a user