From 0c8549a8402d2f52118d13bbbda2ddced5e9d466 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Tue, 14 May 2024 11:04:51 +0530 Subject: [PATCH] Inline --- .../machineLearning/yoloFaceDetectionService.ts | 2 +- web/apps/photos/src/services/ml/geom.ts | 12 +++++------- web/apps/photos/src/services/ml/types.ts | 2 +- web/apps/photos/src/types/image/index.ts | 9 --------- web/apps/photos/src/utils/image/index.ts | 8 ++++++-- web/apps/photos/src/utils/machineLearning/index.ts | 7 +++---- 6 files changed, 16 insertions(+), 24 deletions(-) diff --git a/web/apps/photos/src/services/machineLearning/yoloFaceDetectionService.ts b/web/apps/photos/src/services/machineLearning/yoloFaceDetectionService.ts index a98a7b89df..14a5fb9f3e 100644 --- a/web/apps/photos/src/services/machineLearning/yoloFaceDetectionService.ts +++ b/web/apps/photos/src/services/machineLearning/yoloFaceDetectionService.ts @@ -14,7 +14,7 @@ import { scale, translate, } from "transformation-matrix"; -import { Dimensions } from "types/image"; +import { Dimensions } from "services/ml/geom"; import { clamp, getPixelBilinear, diff --git a/web/apps/photos/src/services/ml/geom.ts b/web/apps/photos/src/services/ml/geom.ts index 926b08389a..37e4525788 100644 --- a/web/apps/photos/src/services/ml/geom.ts +++ b/web/apps/photos/src/services/ml/geom.ts @@ -20,6 +20,11 @@ export class Point { } } +export interface Dimensions { + width: number; + height: number; +} + export interface IBoundingBox { left: number; top: number; @@ -99,10 +104,3 @@ export class Box implements IRect { return new Box({ x, y, width, height }); } } - -export function isValidNumber(num: any) { - return ( - (!!num && num !== Infinity && num !== -Infinity && !isNaN(num)) || - num === 0 - ); -} diff --git a/web/apps/photos/src/services/ml/types.ts b/web/apps/photos/src/services/ml/types.ts index 336b4c027d..97eb9c0702 100644 --- a/web/apps/photos/src/services/ml/types.ts +++ b/web/apps/photos/src/services/ml/types.ts @@ -1,7 +1,7 @@ import { DebugInfo } from "hdbscan"; import PQueue from "p-queue"; import { EnteFile } from "types/file"; -import { Dimensions } from "types/image"; +import { Dimensions } from "services/ml/geom"; import { Box, Point } from "./geom"; export interface MLSyncResult { diff --git a/web/apps/photos/src/types/image/index.ts b/web/apps/photos/src/types/image/index.ts index 8c9619e2eb..e69de29bb2 100644 --- a/web/apps/photos/src/types/image/index.ts +++ b/web/apps/photos/src/types/image/index.ts @@ -1,9 +0,0 @@ -export interface Dimensions { - width: number; - height: number; -} - -export interface BlobOptions { - type?: string; - quality?: number; -} diff --git a/web/apps/photos/src/utils/image/index.ts b/web/apps/photos/src/utils/image/index.ts index af8a498156..39263ab308 100644 --- a/web/apps/photos/src/utils/image/index.ts +++ b/web/apps/photos/src/utils/image/index.ts @@ -1,10 +1,9 @@ // these utils only work in env where OffscreenCanvas is available import { Matrix, inverse } from "ml-matrix"; +import { Box, Dimensions } from "services/ml/geom"; import { FaceAlignment } from "services/ml/types"; -import { BlobOptions, Dimensions } from "types/image"; import { enlargeBox } from "utils/machineLearning"; -import { Box } from "services/ml/geom"; export function normalizePixelBetween0And1(pixelValue: number) { return pixelValue / 255.0; @@ -447,6 +446,11 @@ export function addPadding(image: ImageBitmap, padding: number) { return offscreen.transferToImageBitmap(); } +export interface BlobOptions { + type?: string; + quality?: number; +} + export async function imageBitmapToBlob( imageBitmap: ImageBitmap, options?: BlobOptions, diff --git a/web/apps/photos/src/utils/machineLearning/index.ts b/web/apps/photos/src/utils/machineLearning/index.ts index db0c333c18..54060802f0 100644 --- a/web/apps/photos/src/utils/machineLearning/index.ts +++ b/web/apps/photos/src/utils/machineLearning/index.ts @@ -4,7 +4,7 @@ import log from "@/next/log"; import PQueue from "p-queue"; import DownloadManager from "services/download"; import { getLocalFiles } from "services/fileService"; -import { Box, Point, boxFromBoundingBox } from "services/ml/geom"; +import { Box, Dimensions, Point, boxFromBoundingBox } from "services/ml/geom"; import { DetectedFace, Face, @@ -14,7 +14,6 @@ import { Versioned, } from "services/ml/types"; import { EnteFile } from "types/file"; -import { Dimensions } from "types/image"; import { getRenderableImage } from "utils/file"; import { clamp, warpAffineFloat32List } from "utils/image"; import mlIDbStorage from "utils/storage/mlIDbStorage"; @@ -23,11 +22,11 @@ export function newBox(x: number, y: number, width: number, height: number) { return new Box({ x, y, width, height }); } -export function getBoxCenterPt(topLeft: Point, bottomRight: Point): Point { +function getBoxCenterPt(topLeft: Point, bottomRight: Point): Point { return topLeft.add(bottomRight.sub(topLeft).div(new Point(2, 2))); } -export function getBoxCenter(box: Box): Point { +function getBoxCenter(box: Box): Point { return getBoxCenterPt(box.topLeft, box.bottomRight); }