Skip to content

armgit / ente

Public Imported from GitHub
0

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

Integrate clustering progress into ML status

Manav Rathic4f70c370ecf
diff --git a/web/packages/new/photos/components/MLSettings.tsx b/web/packages/new/photos/components/MLSettings.tsx
index 3c3c635c1c..43017e8eca 100644
--- a/web/packages/new/photos/components/MLSettings.tsx
+++ b/web/packages/new/photos/components/MLSettings.tsx
@@ -8,11 +8,10 @@ import {
enableML,
mlStatusSnapshot,
mlStatusSubscribe,
- wipClusterDebugPageContents,
+ wipCluster,
wipClusterEnable,
type MLStatus,
} from "@/new/photos/services/ml";
-import { type ClusteringProgress } from "@/new/photos/services/ml/cluster";
import EnteSpinner from "@ente/shared/components/EnteSpinner";
import { EnteMenuItem } from "@ente/shared/components/Menu/EnteMenuItem";
import {
@@ -22,7 +21,6 @@ import {
Divider,
FormControlLabel,
FormGroup,
- LinearProgress,
Link,
Paper,
Stack,
@@ -302,7 +300,6 @@ const ManageML: React.FC<ManageMLProps> = ({
}) => {
const [showClusterOpt, setShowClusterOpt] = useState(false);
const { phase, nSyncedFiles, nTotalFiles } = mlStatus;
- const [progress, setProgress] = useState<ClusteringProgress | undefined>();
useEffect(() => void wipClusterEnable().then(setShowClusterOpt), []);
@@ -341,12 +338,6 @@ const ManageML: React.FC<ManageMLProps> = ({
});
};
- // TODO-Cluster
- const wipClusterDebug = async () => {
- await wipClusterDebugPageContents(setProgress);
- setProgress(undefined);
- };
-
return (
<Stack px={"16px"} py={"20px"} gap={4}>
<Stack gap={3}>
@@ -397,30 +388,14 @@ const ManageML: React.FC<ManageMLProps> = ({
label={ut(
"Create clusters β€’ internal only option",
)}
- onClick={wipClusterDebug}
+ onClick={() => void wipCluster()}
/>
</MenuItemGroup>
<MenuSectionTitle
title={ut(
- "Create and show in-memory clusters (not saved or synced). You can also view them in the search dropdown later.",
+ "Create in-memory clusters (not saved or synced). You can also view them in the search dropdown later.",
)}
/>
- {progress && (
- <Box sx={{ mr: 1 }}>
- <LinearProgress
- variant="determinate"
- value={
- progress.total > 0
- ? Math.round(
- (progress.completed /
- progress.total) *
- 100,
- )
- : 0
- }
- />
- </Box>
- )}
</Box>
)}
</Stack>
diff --git a/web/packages/new/photos/components/SearchBar.tsx b/web/packages/new/photos/components/SearchBar.tsx
index 3ad465e26a..e46b4d3cc0 100644
--- a/web/packages/new/photos/components/SearchBar.tsx
+++ b/web/packages/new/photos/components/SearchBar.tsx
@@ -419,6 +419,7 @@ const EmptyState: React.FC<EmptyStateProps> = ({
label = t("indexing_fetching", mlStatus);
break;
case "clustering":
+ // TODO-Cluster
label = t("indexing_people", mlStatus);
break;
case "done":
diff --git a/web/packages/new/photos/services/ml/cluster.ts b/web/packages/new/photos/services/ml/cluster.ts
index 8d791c7fc0..4907f53911 100644
--- a/web/packages/new/photos/services/ml/cluster.ts
+++ b/web/packages/new/photos/services/ml/cluster.ts
@@ -42,8 +42,6 @@ export interface ClusteringProgress {
total: number;
}
-export type OnClusteringProgress = (progress: ClusteringProgress) => void;
-
/** A {@link Face} annotated with data needed during clustering. */
export type ClusterFace = Omit<Face, "embedding"> & {
embedding: Float32Array;
@@ -69,7 +67,7 @@ export interface ClusterPreviewFace {
export const clusterFaces = (
faceIndexes: FaceIndex[],
localFiles: EnteFile[],
- onProgress: OnClusteringProgress,
+ onProgress: (progress: ClusteringProgress) => void,
) => {
const {
minBlur,
diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.ts
index 0f6b32aed3..225c0891c6 100644
--- a/web/packages/new/photos/services/ml/index.ts
+++ b/web/packages/new/photos/services/ml/index.ts
@@ -24,7 +24,6 @@ import {
type ClusterFace,
type ClusterPreviewFace,
type FaceCluster,
- type OnClusteringProgress,
} from "./cluster";
import { regenerateFaceCrops } from "./crop";
import { clearMLDB, getFaceIndex, getIndexableAndIndexedCounts } from "./db";
@@ -340,7 +339,6 @@ export const wipClusterEnable = async (): Promise<boolean> =>
(await isInternalUser());
// // TODO-Cluster temporary state here
-let _wip_isClustering = false;
let _wip_peopleLocal: Person[] | undefined;
let _wip_peopleRemote: Person[] | undefined;
let _wip_hasSwitchedOnce = false;
@@ -374,12 +372,9 @@ export interface ClusterDebugPageContents {
}[];
}
-export const wipClusterDebugPageContents = async (
- onProgress: OnClusteringProgress,
-): Promise<ClusterDebugPageContents> => {
+export const wipCluster = async () => {
if (!(await wipClusterEnable())) throw new Error("Not implemented");
- _wip_isClustering = true;
_wip_peopleLocal = undefined;
triggerStatusUpdate();
@@ -390,7 +385,7 @@ export const wipClusterDebugPageContents = async (
cgroups,
unclusteredFaces,
...rest
- } = await worker().then((w) => w.clusterFaces(proxy(onProgress)));
+ } = await worker().then((w) => w.clusterFaces());
const fileForFace = ({ faceID }: { faceID: string }) =>
ensure(localFileByID.get(ensure(fileIDFromFaceID(faceID))));
@@ -441,7 +436,6 @@ export const wipClusterDebugPageContents = async (
.filter((c) => !!c)
.sort((a, b) => b.faceIDs.length - a.faceIDs.length);
- _wip_isClustering = false;
_wip_peopleLocal = people;
triggerStatusUpdate();
setPeopleSnapshot((_wip_peopleRemote ?? []).concat(people));
@@ -540,6 +534,19 @@ const setMLStatusSnapshot = (snapshot: MLStatus) => {
const getMLStatus = async (): Promise<MLStatus> => {
if (!_state.isMLEnabled) return { phase: "disabled" };
+ const w = await worker();
+
+ // The worker has a clustering progress set iff it is clustering. This
+ // overrides other behaviours.
+ const clusteringProgress = await w.clusteringProgess;
+ if (clusteringProgress) {
+ return {
+ phase: "clustering",
+ nSyncedFiles: clusteringProgress.completed,
+ nTotalFiles: clusteringProgress.total,
+ };
+ }
+
const { indexedCount, indexableCount } =
await getIndexableAndIndexedCounts();
@@ -551,11 +558,9 @@ const getMLStatus = async (): Promise<MLStatus> => {
// indexable count.
let phase: MLStatus["phase"];
- const state = await (await worker()).state;
+ const state = await w.state;
if (state == "indexing" || state == "fetching") {
phase = state;
- } else if (_wip_isClustering) {
- phase = "clustering";
} else if (state == "init" || indexableCount > 0) {
phase = "scheduled";
} else {
diff --git a/web/packages/new/photos/services/ml/worker.ts b/web/packages/new/photos/services/ml/worker.ts
index e43af4ccea..5f93257bad 100644
--- a/web/packages/new/photos/services/ml/worker.ts
+++ b/web/packages/new/photos/services/ml/worker.ts
@@ -25,7 +25,7 @@ import {
indexCLIP,
type CLIPIndex,
} from "./clip";
-import { clusterFaces, type OnClusteringProgress } from "./cluster";
+import { clusterFaces, type ClusteringProgress } from "./cluster";
import { saveFaceCrops } from "./crop";
import {
getFaceIndexes,
@@ -97,6 +97,8 @@ interface IndexableItem {
export class MLWorker {
/** The last known state of the worker. */
public state: WorkerState = "init";
+ /** If the worker is currently clustering, then its last known progress. */
+ public clusteringProgess: ClusteringProgress | undefined;
private electron: ElectronMLWorker | undefined;
private delegate: MLWorkerDelegate | undefined;
@@ -276,13 +278,23 @@ export class MLWorker {
}));
}
- // TODO-Cluster
- async clusterFaces(onProgress: OnClusteringProgress) {
- return clusterFaces(
+ /**
+ * Run face clustering on all faces.
+ *
+ * This should only be invoked when the face indexing (including syncing
+ * with remote) is complete so that we cluster the latest set of faces.
+ */
+ async clusterFaces() {
+ const result = clusterFaces(
await getFaceIndexes(),
await getAllLocalFiles(),
- onProgress,
+ (progress) => {
+ this.clusteringProgess = progress;
+ this.delegate?.workerDidUpdateStatus();
+ },
);
+ this.clusteringProgess = undefined;
+ return result;
}
}