diff --git a/web/apps/photos/src/services/machineLearning/machineLearningFactory.ts b/web/apps/photos/src/services/machineLearning/machineLearningFactory.ts index 7017bd1a6..96be5a0f5 100644 --- a/web/apps/photos/src/services/machineLearning/machineLearningFactory.ts +++ b/web/apps/photos/src/services/machineLearning/machineLearningFactory.ts @@ -22,8 +22,6 @@ import { MLLibraryData, MLSyncConfig, MLSyncContext, - ObjectDetectionMethod, - ObjectDetectionService, SceneDetectionMethod, SceneDetectionService, } from "types/machineLearning"; @@ -35,7 +33,6 @@ import hdbscanClusteringService from "./hdbscanClusteringService"; import imageSceneService from "./imageSceneService"; import laplacianBlurDetectionService from "./laplacianBlurDetectionService"; import mobileFaceNetEmbeddingService from "./mobileFaceNetEmbeddingService"; -import ssdMobileNetV2Service from "./ssdMobileNetV2Service"; import yoloFaceDetectionService from "./yoloFaceDetectionService"; export class MLFactory { @@ -49,16 +46,6 @@ export class MLFactory { throw Error("Unknon face detection method: " + method); } - public static getObjectDetectionService( - method: ObjectDetectionMethod, - ): ObjectDetectionService { - if (method === "SSDMobileNetV2") { - return ssdMobileNetV2Service; - } - - throw Error("Unknown object detection method: " + method); - } - public static getSceneDetectionService( method: SceneDetectionMethod, ): SceneDetectionService { @@ -147,7 +134,6 @@ export class LocalMLSyncContext implements MLSyncContext { public blurDetectionService: BlurDetectionService; public faceEmbeddingService: FaceEmbeddingService; public faceClusteringService: ClusteringService; - public objectDetectionService: ObjectDetectionService; public sceneDetectionService: SceneDetectionService; public localFilesMap: Map; @@ -202,9 +188,6 @@ export class LocalMLSyncContext implements MLSyncContext { this.config.faceClustering.method, ); - this.objectDetectionService = MLFactory.getObjectDetectionService( - this.config.objectDetection.method, - ); this.sceneDetectionService = MLFactory.getSceneDetectionService( this.config.sceneDetection.method, ); diff --git a/web/apps/photos/src/services/machineLearning/ssdMobileNetV2Service.ts b/web/apps/photos/src/services/machineLearning/ssdMobileNetV2Service.ts deleted file mode 100644 index 186656532..000000000 --- a/web/apps/photos/src/services/machineLearning/ssdMobileNetV2Service.ts +++ /dev/null @@ -1,66 +0,0 @@ -import log from "@/next/log"; -import * as tf from "@tensorflow/tfjs-core"; -import { - ObjectDetection, - ObjectDetectionMethod, - ObjectDetectionService, - Versioned, -} from "types/machineLearning"; - -import * as SSDMobileNet from "@tensorflow-models/coco-ssd"; -import { OBJECT_DETECTION_IMAGE_SIZE } from "constants/mlConfig"; -import { resizeToSquare } from "utils/image"; - -class SSDMobileNetV2 implements ObjectDetectionService { - private ssdMobileNetV2Model: SSDMobileNet.ObjectDetection; - public method: Versioned; - private ready: Promise; - - public constructor() { - this.method = { - value: "SSDMobileNetV2", - version: 1, - }; - } - - private async init() { - this.ssdMobileNetV2Model = await SSDMobileNet.load({ - base: "mobilenet_v2", - modelUrl: "/models/ssdmobilenet/model.json", - }); - log.info("loaded ssdMobileNetV2Model", tf.getBackend()); - } - - private async getSSDMobileNetV2Model() { - if (!this.ready) { - this.ready = this.init(); - } - await this.ready; - return this.ssdMobileNetV2Model; - } - - public async detectObjects( - image: ImageBitmap, - maxNumberBoxes: number, - minScore: number, - ): Promise { - const ssdMobileNetV2Model = await this.getSSDMobileNetV2Model(); - const resized = resizeToSquare(image, OBJECT_DETECTION_IMAGE_SIZE); - const tfImage = tf.browser.fromPixels(resized.image); - const detections = await ssdMobileNetV2Model.detect( - tfImage, - maxNumberBoxes, - minScore, - ); - tfImage.dispose(); - return detections; - } - - public async dispose() { - const ssdMobileNetV2Model = await this.getSSDMobileNetV2Model(); - ssdMobileNetV2Model?.dispose(); - this.ssdMobileNetV2Model = null; - } -} - -export default new SSDMobileNetV2(); diff --git a/web/apps/photos/src/types/machineLearning/index.ts b/web/apps/photos/src/types/machineLearning/index.ts index f1895cd41..c28627492 100644 --- a/web/apps/photos/src/types/machineLearning/index.ts +++ b/web/apps/photos/src/types/machineLearning/index.ts @@ -265,7 +265,6 @@ export interface MLSyncContext { faceEmbeddingService: FaceEmbeddingService; blurDetectionService: BlurDetectionService; faceClusteringService: ClusteringService; - objectDetectionService: ObjectDetectionService; sceneDetectionService: SceneDetectionService; localFilesMap: Map; @@ -273,7 +272,6 @@ export interface MLSyncContext { nSyncedFiles: number; nSyncedFaces: number; allSyncedFacesMap?: Map>; - allSyncedObjectsMap?: Map>; tsne?: any; error?: Error;