Skip to content

armgit / ente

Public Imported from GitHub
0

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

Indicate cluster

Manav Rathi77cf819ab4d5
diff --git a/web/apps/photos/src/pages/cluster-debug.tsx b/web/apps/photos/src/pages/cluster-debug.tsx
index 25f9b36031..ad2a16fb96 100644
--- a/web/apps/photos/src/pages/cluster-debug.tsx
+++ b/web/apps/photos/src/pages/cluster-debug.tsx
@@ -2,7 +2,8 @@ import { SelectionBar } from "@/base/components/Navbar";
import { pt } from "@/base/i18n";
import {
faceCrop,
- wipClusterPageContents,
+ wipClusterDebugPageContents,
+ type ClusterDebugPageContents,
type FaceFileNeighbour,
type FaceFileNeighbours,
} from "@/new/photos/services/ml";
@@ -23,7 +24,9 @@ import { VariableSizeList } from "react-window";
// TODO-Cluster Temporary component for debugging
export default function ClusterDebug() {
const { startLoading, finishLoading, showNavBar } = useContext(AppContext);
- const [faceFNs, setFaceFNs] = useState<FaceFileNeighbours[]>(null);
+ const [clusterRes, setClusterRes] = useState<
+ ClusterDebugPageContents | undefined
+ >();
useEffect(() => {
showNavBar(true);
@@ -32,20 +35,20 @@ export default function ClusterDebug() {
const cluster = async () => {
startLoading();
- setFaceFNs(await wipClusterPageContents());
+ setClusterRes(await wipClusterDebugPageContents());
finishLoading();
};
return (
<>
- {faceFNs ? (
+ {clusterRes ? (
<Container>
<AutoSizer>
{({ height, width }) => (
<ClusterPhotoList
width={width}
height={height}
- faceFNs={faceFNs}
+ clusterRes={clusterRes}
/>
)}
</AutoSizer>
@@ -91,14 +94,15 @@ const Container = styled("div")`
interface ClusterPhotoListProps {
height: number;
width: number;
- faceFNs: FaceFileNeighbours[];
+ clusterRes: ClusterDebugPageContents;
}
const ClusterPhotoList: React.FC<ClusterPhotoListProps> = ({
height,
width,
- faceFNs,
+ clusterRes,
}) => {
+ const { faceFNs, clusterIDForFaceID } = clusterRes;
const [itemList, setItemList] = useState<ItemListItem[]>([]);
const listRef = useRef(null);
@@ -108,7 +112,7 @@ const ClusterPhotoList: React.FC<ClusterPhotoListProps> = ({
);
const shrinkRatio = getShrinkRatio(width, columns);
- const listItemHeight = 120 * shrinkRatio + 4;
+ const listItemHeight = 120 * shrinkRatio + 24 + 4;
useEffect(() => {
setItemList(itemListFromFaceFNs(faceFNs, columns));
@@ -152,8 +156,11 @@ const ClusterPhotoList: React.FC<ClusterPhotoListProps> = ({
{`score ${item.toFixed(2)}`}
</LabelContainer>
) : (
- item.map((ffn, i) => (
- <FaceItem key={i.toString()} {...ffn} />
+ item.map((faceFN, i) => (
+ <FaceItem
+ key={i.toString()}
+ {...{ faceFN, clusterIDForFaceID }}
+ />
))
)}
</ListContainer>
@@ -192,11 +199,13 @@ const getShrinkRatio = (width: number, columns: number) =>
(width - 2 * getGapFromScreenEdge(width) - (columns - 1) * 4) /
(columns * 120);
-const FaceItem: React.FC<FaceFileNeighbour> = ({
- face,
- enteFile,
- cosineSimilarity,
-}) => {
+interface FaceItemProps {
+ faceFN: FaceFileNeighbour;
+ clusterIDForFaceID: Map<string, string>;
+}
+
+const FaceItem: React.FC<FaceItemProps> = ({ faceFN, clusterIDForFaceID }) => {
+ const { face, enteFile, cosineSimilarity } = faceFN;
const { faceID } = face;
const [objectURL, setObjectURL] = useState<string | undefined>();
@@ -217,7 +226,12 @@ const FaceItem: React.FC<FaceFileNeighbour> = ({
}, [faceID, enteFile]);
return (
- <FaceChip>
+ <FaceChip
+ style={{
+ outline: outlineForCluster(clusterIDForFaceID.get(faceID)),
+ outlineOffset: "2px",
+ }}
+ >
{objectURL && (
<img
style={{
@@ -228,7 +242,7 @@ const FaceItem: React.FC<FaceFileNeighbour> = ({
src={objectURL}
/>
)}
- <Typography variant="small" textAlign="right">
+ <Typography variant="small" color="text.muted" textAlign="right">
{cosineSimilarity.toFixed(2)}
</Typography>
</FaceChip>
@@ -240,6 +254,12 @@ const FaceChip = styled(Box)`
height: 120px;
`;
+const outlineForCluster = (clusterID: string | undefined) =>
+ clusterID ? `1px solid oklch(0.7 0.1 ${hForID(clusterID)})` : undefined;
+
+const hForID = (id: string) =>
+ ([...id].reduce((s, c) => s + c.charCodeAt(0), 0) % 10) * 36;
+
const ListContainer = styled(Box, {
shouldForwardProp: (propName) => propName != "shrinkRatio",
})<{
diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.ts
index 0d1b2f105e..6b0a72be69 100644
--- a/web/packages/new/photos/services/ml/index.ts
+++ b/web/packages/new/photos/services/ml/index.ts
@@ -354,23 +354,33 @@ export interface FaceFileNeighbour {
cosineSimilarity: number;
}
-export const wipClusterPageContents = async () => {
- if (!(await wipClusterEnable())) return [];
+export interface ClusterDebugPageContents {
+ faceFNs: FaceFileNeighbours[];
+ clusters: FaceCluster[];
+ clusterIDForFaceID: Map<string, string>;
+}
+
+export const wipClusterDebugPageContents = async (): Promise<
+ ClusterDebugPageContents | undefined
+> => {
+ if (!(await wipClusterEnable())) return undefined;
log.info("clustering");
_wip_isClustering = true;
_wip_searchPersons = undefined;
triggerStatusUpdate();
- const { faceAndNeigbours } = await clusterFaces(await faceIndexes());
+ const { faceAndNeigbours, clusters } = await clusterFaces(
+ await faceIndexes(),
+ );
// const searchPersons = await convertToSearchPersons(clusters, cgroups);
const localFiles = await getAllLocalFiles();
const localFileByID = new Map(localFiles.map((f) => [f.id, f]));
const fileForFace = ({ faceID }: Face) =>
- localFileByID.get(ensure(fileIDFromFaceID(faceID)));
+ ensure(localFileByID.get(ensure(fileIDFromFaceID(faceID))));
- const result = faceAndNeigbours
+ const faceFNs = faceAndNeigbours
.map(({ face, neighbours }) => ({
face,
neighbours: neighbours.map(({ face, cosineSimilarity }) => ({
@@ -381,12 +391,18 @@ export const wipClusterPageContents = async () => {
}))
.sort((a, b) => b.face.score - a.face.score);
+ const clusterIDForFaceID = new Map(
+ clusters.flatMap((cluster) =>
+ cluster.faceIDs.map((id) => [id, cluster.id]),
+ ),
+ );
+
_wip_isClustering = false;
// _wip_searchPersons = searchPersons;
triggerStatusUpdate();
// return { faces, clusters, cgroups };
- return result;
+ return { faceFNs, clusters, clusterIDForFaceID };
};
export const wipCluster = async () => {