Manav Rathi il y a 1 an
Parent
commit
a10d5a4ff5

+ 0 - 56
web/apps/photos/src/constants/mlConfig.ts

@@ -1,56 +0,0 @@
-import { MLSearchConfig, MLSyncConfig } from "services/ml/types";
-import { JobConfig } from "types/common/job";
-
-export const DEFAULT_ML_SYNC_JOB_CONFIG: JobConfig = {
-    intervalSec: 5,
-    // TODO: finalize this after seeing effects on and from machine sleep
-    maxItervalSec: 960,
-    backoffMultiplier: 2,
-};
-
-export const DEFAULT_ML_SYNC_CONFIG: MLSyncConfig = {
-    batchSize: 200,
-    imageSource: "Original",
-    faceDetection: {
-        method: "YoloFace",
-    },
-    faceCrop: {
-        enabled: true,
-        method: "ArcFace",
-        padding: 0.25,
-        maxSize: 256,
-        blobOptions: {
-            type: "image/jpeg",
-            quality: 0.8,
-        },
-    },
-    faceAlignment: {
-        method: "ArcFace",
-    },
-    blurDetection: {
-        method: "Laplacian",
-        threshold: 15,
-    },
-    faceEmbedding: {
-        method: "MobileFaceNet",
-        faceSize: 112,
-        generateTsne: true,
-    },
-    faceClustering: {
-        method: "Hdbscan",
-        minClusterSize: 3,
-        minSamples: 5,
-        clusterSelectionEpsilon: 0.6,
-        clusterSelectionMethod: "leaf",
-        minInputSize: 50,
-        // maxDistanceInsideCluster: 0.4,
-        generateDebugInfo: true,
-    },
-    mlVersion: 3,
-};
-
-export const DEFAULT_ML_SEARCH_CONFIG: MLSearchConfig = {
-    enabled: false,
-};
-
-export const MAX_ML_SYNC_ERROR_COUNT = 1;

+ 1 - 1
web/apps/photos/src/pages/_app.tsx

@@ -67,7 +67,7 @@ import {
 import {
     getMLSearchConfig,
     updateMLSearchConfig,
-} from "utils/machineLearning/config";
+} from "services/machineLearning/machineLearningService";
 import {
     getUpdateAvailableForDownloadMessage,
     getUpdateReadyToInstallMessage,

+ 98 - 3
web/apps/photos/src/services/machineLearning/machineLearningService.ts

@@ -2,7 +2,6 @@ import log from "@/next/log";
 import { APPS } from "@ente/shared/apps/constants";
 import ComlinkCryptoWorker from "@ente/shared/crypto";
 import { CustomError, parseUploadErrorCodes } from "@ente/shared/error";
-import { MAX_ML_SYNC_ERROR_COUNT } from "constants/mlConfig";
 import downloadManager from "services/download";
 import { putEmbedding } from "services/embeddingService";
 import { getLocalFiles } from "services/fileService";
@@ -11,19 +10,115 @@ import {
     Face,
     FaceDetection,
     Landmark,
+    MLSearchConfig,
+    MLSyncConfig,
     MLSyncContext,
     MLSyncFileContext,
     MLSyncResult,
     MlFileData,
 } from "services/ml/types";
+import { JobConfig } from "types/common/job";
 import { EnteFile } from "types/file";
-import { getMLSyncConfig } from "utils/machineLearning/config";
-import mlIDbStorage from "utils/storage/mlIDbStorage";
+import mlIDbStorage, {
+    ML_SEARCH_CONFIG_NAME,
+    ML_SYNC_CONFIG_NAME,
+    ML_SYNC_JOB_CONFIG_NAME,
+} from "utils/storage/mlIDbStorage";
+import { isInternalUserForML } from "utils/user";
 import FaceService from "./faceService";
 import { MLFactory } from "./machineLearningFactory";
 import PeopleService from "./peopleService";
 import ReaderService from "./readerService";
 
+export const DEFAULT_ML_SYNC_JOB_CONFIG: JobConfig = {
+    intervalSec: 5,
+    // TODO: finalize this after seeing effects on and from machine sleep
+    maxItervalSec: 960,
+    backoffMultiplier: 2,
+};
+
+export const DEFAULT_ML_SYNC_CONFIG: MLSyncConfig = {
+    batchSize: 200,
+    imageSource: "Original",
+    faceDetection: {
+        method: "YoloFace",
+    },
+    faceCrop: {
+        enabled: true,
+        method: "ArcFace",
+        padding: 0.25,
+        maxSize: 256,
+        blobOptions: {
+            type: "image/jpeg",
+            quality: 0.8,
+        },
+    },
+    faceAlignment: {
+        method: "ArcFace",
+    },
+    blurDetection: {
+        method: "Laplacian",
+        threshold: 15,
+    },
+    faceEmbedding: {
+        method: "MobileFaceNet",
+        faceSize: 112,
+        generateTsne: true,
+    },
+    faceClustering: {
+        method: "Hdbscan",
+        minClusterSize: 3,
+        minSamples: 5,
+        clusterSelectionEpsilon: 0.6,
+        clusterSelectionMethod: "leaf",
+        minInputSize: 50,
+        // maxDistanceInsideCluster: 0.4,
+        generateDebugInfo: true,
+    },
+    mlVersion: 3,
+};
+
+export const DEFAULT_ML_SEARCH_CONFIG: MLSearchConfig = {
+    enabled: false,
+};
+
+export const MAX_ML_SYNC_ERROR_COUNT = 1;
+
+export async function getMLSyncJobConfig() {
+    return mlIDbStorage.getConfig(
+        ML_SYNC_JOB_CONFIG_NAME,
+        DEFAULT_ML_SYNC_JOB_CONFIG,
+    );
+}
+
+export async function getMLSyncConfig() {
+    return mlIDbStorage.getConfig(ML_SYNC_CONFIG_NAME, DEFAULT_ML_SYNC_CONFIG);
+}
+
+export async function getMLSearchConfig() {
+    if (isInternalUserForML()) {
+        return mlIDbStorage.getConfig(
+            ML_SEARCH_CONFIG_NAME,
+            DEFAULT_ML_SEARCH_CONFIG,
+        );
+    }
+    // Force disabled for everyone else while we finalize it to avoid redundant
+    // reindexing for users.
+    return DEFAULT_ML_SEARCH_CONFIG;
+}
+
+export async function updateMLSyncJobConfig(newConfig: JobConfig) {
+    return mlIDbStorage.putConfig(ML_SYNC_JOB_CONFIG_NAME, newConfig);
+}
+
+export async function updateMLSyncConfig(newConfig: MLSyncConfig) {
+    return mlIDbStorage.putConfig(ML_SYNC_CONFIG_NAME, newConfig);
+}
+
+export async function updateMLSearchConfig(newConfig: MLSearchConfig) {
+    return mlIDbStorage.putConfig(ML_SEARCH_CONFIG_NAME, newConfig);
+}
+
 class MachineLearningService {
     private localSyncContext: Promise<MLSyncContext>;
     private syncContext: Promise<MLSyncContext>;

+ 1 - 1
web/apps/photos/src/services/machineLearning/mlWorkManager.ts

@@ -5,13 +5,13 @@ import { eventBus, Events } from "@ente/shared/events";
 import { getToken, getUserID } from "@ente/shared/storage/localStorage/helpers";
 import debounce from "debounce";
 import PQueue from "p-queue";
+import { getMLSyncJobConfig } from "services/machineLearning/machineLearningService";
 import { MLSyncResult } from "services/ml/types";
 import { JobResult } from "types/common/job";
 import { EnteFile } from "types/file";
 import { getDedicatedMLWorker } from "utils/comlink/ComlinkMLWorker";
 import { SimpleJob } from "utils/common/job";
 import { logQueueStats } from "utils/machineLearning";
-import { getMLSyncJobConfig } from "utils/machineLearning/config";
 import mlIDbStorage from "utils/storage/mlIDbStorage";
 import { DedicatedMLWorker } from "worker/ml.worker";
 

+ 1 - 1
web/apps/photos/src/services/searchService.ts

@@ -17,7 +17,7 @@ import {
 import ComlinkSearchWorker from "utils/comlink/ComlinkSearchWorker";
 import { getUniqueFiles } from "utils/file";
 import { getAllPeople } from "utils/machineLearning";
-import { getMLSyncConfig } from "utils/machineLearning/config";
+import { getMLSyncConfig } from "services/machineLearning/machineLearningService";
 import { getFormattedDate } from "utils/search";
 import mlIDbStorage from "utils/storage/mlIDbStorage";
 import { clipService, computeClipMatchScore } from "./clip-service";

+ 0 - 48
web/apps/photos/src/utils/machineLearning/config.ts

@@ -1,48 +0,0 @@
-import {
-    DEFAULT_ML_SEARCH_CONFIG,
-    DEFAULT_ML_SYNC_CONFIG,
-    DEFAULT_ML_SYNC_JOB_CONFIG,
-} from "constants/mlConfig";
-import { MLSearchConfig, MLSyncConfig } from "services/ml/types";
-import { JobConfig } from "types/common/job";
-import mlIDbStorage, {
-    ML_SEARCH_CONFIG_NAME,
-    ML_SYNC_CONFIG_NAME,
-    ML_SYNC_JOB_CONFIG_NAME,
-} from "utils/storage/mlIDbStorage";
-import { isInternalUserForML } from "utils/user";
-
-export async function getMLSyncJobConfig() {
-    return mlIDbStorage.getConfig(
-        ML_SYNC_JOB_CONFIG_NAME,
-        DEFAULT_ML_SYNC_JOB_CONFIG,
-    );
-}
-
-export async function getMLSyncConfig() {
-    return mlIDbStorage.getConfig(ML_SYNC_CONFIG_NAME, DEFAULT_ML_SYNC_CONFIG);
-}
-
-export async function getMLSearchConfig() {
-    if (isInternalUserForML()) {
-        return mlIDbStorage.getConfig(
-            ML_SEARCH_CONFIG_NAME,
-            DEFAULT_ML_SEARCH_CONFIG,
-        );
-    }
-    // Force disabled for everyone else while we finalize it to avoid redundant
-    // reindexing for users.
-    return DEFAULT_ML_SEARCH_CONFIG;
-}
-
-export async function updateMLSyncJobConfig(newConfig: JobConfig) {
-    return mlIDbStorage.putConfig(ML_SYNC_JOB_CONFIG_NAME, newConfig);
-}
-
-export async function updateMLSyncConfig(newConfig: MLSyncConfig) {
-    return mlIDbStorage.putConfig(ML_SYNC_CONFIG_NAME, newConfig);
-}
-
-export async function updateMLSearchConfig(newConfig: MLSearchConfig) {
-    return mlIDbStorage.putConfig(ML_SEARCH_CONFIG_NAME, newConfig);
-}

+ 6 - 6
web/apps/photos/src/utils/storage/mlIDbStorage.ts

@@ -1,11 +1,5 @@
 import { haveWindow } from "@/next/env";
 import log from "@/next/log";
-import {
-    DEFAULT_ML_SEARCH_CONFIG,
-    DEFAULT_ML_SYNC_CONFIG,
-    DEFAULT_ML_SYNC_JOB_CONFIG,
-    MAX_ML_SYNC_ERROR_COUNT,
-} from "constants/mlConfig";
 import {
     DBSchema,
     IDBPDatabase,
@@ -15,6 +9,12 @@ import {
     openDB,
 } from "idb";
 import isElectron from "is-electron";
+import {
+    DEFAULT_ML_SEARCH_CONFIG,
+    DEFAULT_ML_SYNC_CONFIG,
+    DEFAULT_ML_SYNC_JOB_CONFIG,
+    MAX_ML_SYNC_ERROR_COUNT,
+} from "services/machineLearning/machineLearningService";
 import { Face, MLLibraryData, MlFileData, Person } from "services/ml/types";
 
 export interface IndexStatus {