Manav Rathi преди 1 година
родител
ревизия
ce566f522d

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

@@ -46,22 +46,6 @@ export const DEFAULT_ML_SYNC_CONFIG: MLSyncConfig = {
         // maxDistanceInsideCluster: 0.4,
         // maxDistanceInsideCluster: 0.4,
         generateDebugInfo: true,
         generateDebugInfo: true,
     },
     },
-    objectDetection: {
-        method: "SSDMobileNetV2",
-        maxNumBoxes: 20,
-        minScore: 0.2,
-    },
-    sceneDetection: {
-        method: "ImageScene",
-        minScore: 0.1,
-    },
-    // tsne: {
-    //     samples: 200,
-    //     dim: 2,
-    //     perplexity: 10.0,
-    //     learningRate: 10.0,
-    //     metric: 'euclidean',
-    // },
     mlVersion: 3,
     mlVersion: 3,
 };
 };
 
 
@@ -80,12 +64,4 @@ export const TEXT_DETECTION_TIMEOUT_MS = [10000, 30000, 60000, 120000, 240000];
 export const MOBILEFACENET_FACE_SIZE = 112;
 export const MOBILEFACENET_FACE_SIZE = 112;
 export const MOBILEFACENET_EMBEDDING_SIZE = 192;
 export const MOBILEFACENET_EMBEDDING_SIZE = 192;
 
 
-// scene detection model takes fixed-shaped (224x224) inputs
-// https://tfhub.dev/sayannath/lite-model/image-scene/1
-export const SCENE_DETECTION_IMAGE_SIZE = 224;
-
-// SSD with Mobilenet v2 initialized from Imagenet classification checkpoint. Trained on COCO 2017 dataset (images scaled to 320x320 resolution).
-// https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2
-export const OBJECT_DETECTION_IMAGE_SIZE = 320;
-
 export const BATCHES_BEFORE_SYNCING_INDEX = 5;
 export const BATCHES_BEFORE_SYNCING_INDEX = 5;

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

@@ -127,7 +127,6 @@ export class LocalMLSyncContext implements MLSyncContext {
     public nSyncedFiles: number;
     public nSyncedFiles: number;
     public nSyncedFaces: number;
     public nSyncedFaces: number;
     public allSyncedFacesMap?: Map<number, Array<Face>>;
     public allSyncedFacesMap?: Map<number, Array<Face>>;
-    public tsne?: any;
 
 
     public error?: Error;
     public error?: Error;
 
 

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

@@ -61,7 +61,6 @@ class MachineLearningService {
                     .length,
                     .length,
             nFaceNoise:
             nFaceNoise:
                 syncContext.mlLibraryData?.faceClusteringResults?.noise.length,
                 syncContext.mlLibraryData?.faceClusteringResults?.noise.length,
-            tsne: syncContext.tsne,
             error: syncContext.error,
             error: syncContext.error,
         };
         };
         // log.info('[MLService] sync results: ', mlSyncResult);
         // log.info('[MLService] sync results: ', mlSyncResult);

+ 0 - 2
web/apps/photos/src/services/machineLearning/readerService.ts

@@ -16,7 +16,6 @@ class ReaderService {
             if (fileContext.imageBitmap) {
             if (fileContext.imageBitmap) {
                 return fileContext.imageBitmap;
                 return fileContext.imageBitmap;
             }
             }
-            // log.info('1 TF Memory stats: ',JSON.stringify(tf.memory()));
             if (fileContext.localFile) {
             if (fileContext.localFile) {
                 if (
                 if (
                     fileContext.enteFile.metadata.fileType !== FILE_TYPE.IMAGE
                     fileContext.enteFile.metadata.fileType !== FILE_TYPE.IMAGE
@@ -47,7 +46,6 @@ class ReaderService {
             fileContext.newMlFile.imageSource = syncContext.config.imageSource;
             fileContext.newMlFile.imageSource = syncContext.config.imageSource;
             const { width, height } = fileContext.imageBitmap;
             const { width, height } = fileContext.imageBitmap;
             fileContext.newMlFile.imageDimensions = { width, height };
             fileContext.newMlFile.imageDimensions = { width, height };
-            // log.info('2 TF Memory stats: ',JSON.stringify(tf.memory()));
 
 
             return fileContext.imageBitmap;
             return fileContext.imageBitmap;
         } catch (e) {
         } catch (e) {

+ 2 - 7
web/apps/photos/src/services/machineLearning/yoloFaceDetectionService.ts

@@ -1,7 +1,4 @@
-import {
-    BLAZEFACE_FACE_SIZE,
-    MAX_FACE_DISTANCE_PERCENT,
-} from "constants/mlConfig";
+import { MAX_FACE_DISTANCE_PERCENT } from "constants/mlConfig";
 import { Dimensions } from "types/image";
 import { Dimensions } from "types/image";
 import {
 import {
     FaceDetection,
     FaceDetection,
@@ -35,14 +32,12 @@ class YoloFaceDetectionService implements FaceDetectionService {
     // private onnxInferenceSession?: ort.InferenceSession;
     // private onnxInferenceSession?: ort.InferenceSession;
     private onnxInferenceSession?: any;
     private onnxInferenceSession?: any;
     public method: Versioned<FaceDetectionMethod>;
     public method: Versioned<FaceDetectionMethod>;
-    private desiredFaceSize;
 
 
-    public constructor(desiredFaceSize: number = BLAZEFACE_FACE_SIZE) {
+    public constructor() {
         this.method = {
         this.method = {
             value: "YoloFace",
             value: "YoloFace",
             version: 1,
             version: 1,
         };
         };
-        this.desiredFaceSize = desiredFaceSize;
     }
     }
 
 
     private async initOnnx() {
     private async initOnnx() {

+ 0 - 0
web/apps/photos/src/types/machineLearning/archface.ts


+ 0 - 7
web/apps/photos/src/types/machineLearning/index.ts

@@ -1,5 +1,3 @@
-import * as tf from "@tensorflow/tfjs-core";
-
 import { DebugInfo } from "hdbscan";
 import { DebugInfo } from "hdbscan";
 import PQueue from "p-queue";
 import PQueue from "p-queue";
 import { EnteFile } from "types/file";
 import { EnteFile } from "types/file";
@@ -12,7 +10,6 @@ export interface MLSyncResult {
     nSyncedFaces: number;
     nSyncedFaces: number;
     nFaceClusters: number;
     nFaceClusters: number;
     nFaceNoise: number;
     nFaceNoise: number;
-    tsne?: any;
     error?: Error;
     error?: Error;
 }
 }
 
 
@@ -226,9 +223,6 @@ export interface MLSyncConfig {
     blurDetection: BlurDetectionConfig;
     blurDetection: BlurDetectionConfig;
     faceEmbedding: FaceEmbeddingConfig;
     faceEmbedding: FaceEmbeddingConfig;
     faceClustering: FaceClusteringConfig;
     faceClustering: FaceClusteringConfig;
-    objectDetection: ObjectDetectionConfig;
-    sceneDetection: SceneDetectionConfig;
-    tsne?: TSNEConfig;
     mlVersion: number;
     mlVersion: number;
 }
 }
 
 
@@ -254,7 +248,6 @@ export interface MLSyncContext {
     nSyncedFiles: number;
     nSyncedFiles: number;
     nSyncedFaces: number;
     nSyncedFaces: number;
     allSyncedFacesMap?: Map<number, Array<Face>>;
     allSyncedFacesMap?: Map<number, Array<Face>>;
-    tsne?: any;
 
 
     error?: Error;
     error?: Error;
 
 

+ 2 - 26
web/apps/photos/src/utils/machineLearning/index.ts

@@ -2,7 +2,6 @@ import log from "@/next/log";
 import { CACHES } from "@ente/shared/storage/cacheStorage/constants";
 import { CACHES } from "@ente/shared/storage/cacheStorage/constants";
 import { cached } from "@ente/shared/storage/cacheStorage/helpers";
 import { cached } from "@ente/shared/storage/cacheStorage/helpers";
 import { FILE_TYPE } from "constants/file";
 import { FILE_TYPE } from "constants/file";
-import { BLAZEFACE_FACE_SIZE } from "constants/mlConfig";
 import { euclidean } from "hdbscan";
 import { euclidean } from "hdbscan";
 import PQueue from "p-queue";
 import PQueue from "p-queue";
 import DownloadManager from "services/download";
 import DownloadManager from "services/download";
@@ -21,10 +20,10 @@ import {
     Versioned,
     Versioned,
 } from "types/machineLearning";
 } from "types/machineLearning";
 import { getRenderableImage } from "utils/file";
 import { getRenderableImage } from "utils/file";
-import { clamp, imageBitmapToBlob, warpAffineFloat32List } from "utils/image";
+import { clamp, warpAffineFloat32List } from "utils/image";
 import mlIDbStorage from "utils/storage/mlIDbStorage";
 import mlIDbStorage from "utils/storage/mlIDbStorage";
 import { Box, Point } from "../../../thirdparty/face-api/classes";
 import { Box, Point } from "../../../thirdparty/face-api/classes";
-import { ibExtractFaceImage, ibExtractFaceImages } from "./faceAlign";
+import { ibExtractFaceImages } from "./faceAlign";
 import { getFaceCropBlobFromStorage } from "./faceCrop";
 import { getFaceCropBlobFromStorage } from "./faceCrop";
 
 
 export function f32Average(descriptors: Float32Array[]) {
 export function f32Average(descriptors: Float32Array[]) {
@@ -105,29 +104,6 @@ export async function getLocalFile(fileId: number) {
     return localFiles.find((f) => f.id === fileId);
     return localFiles.find((f) => f.id === fileId);
 }
 }
 
 
-export async function getFaceImage(
-    face: AlignedFace,
-    token: string,
-    faceSize: number = BLAZEFACE_FACE_SIZE,
-    file?: EnteFile,
-): Promise<FaceImageBlob> {
-    if (!file) {
-        file = await getLocalFile(face.fileId);
-    }
-
-    const imageBitmap = await getOriginalImageBitmap(file);
-    const faceImageBitmap = ibExtractFaceImage(
-        imageBitmap,
-        face.alignment,
-        faceSize,
-    );
-    const faceImage = imageBitmapToBlob(faceImageBitmap);
-    faceImageBitmap.close();
-    imageBitmap.close();
-
-    return faceImage;
-}
-
 export async function extractFaceImages(
 export async function extractFaceImages(
     faces: Array<AlignedFace>,
     faces: Array<AlignedFace>,
     faceSize: number,
     faceSize: number,