Inline
This commit is contained in:
@@ -10,12 +10,12 @@ import {
|
||||
type Versioned,
|
||||
} from "services/ml/types";
|
||||
import { imageBitmapToBlob, warpAffineFloat32List } from "utils/image";
|
||||
import { DEFAULT_ML_SYNC_CONFIG } from "./machineLearningService";
|
||||
import ReaderService, {
|
||||
fetchImageBitmap,
|
||||
getFaceId,
|
||||
getLocalFile,
|
||||
} from "./readerService";
|
||||
import { DEFAULT_ML_SYNC_CONFIG } from "./machineLearningService";
|
||||
|
||||
class FaceService {
|
||||
async syncFileFaceDetections(
|
||||
@@ -44,10 +44,7 @@ class FaceService {
|
||||
|
||||
newMlFile.faceDetectionMethod = syncContext.faceDetectionService.method;
|
||||
fileContext.newDetection = true;
|
||||
const imageBitmap = await ReaderService.getImageBitmap(
|
||||
syncContext,
|
||||
fileContext,
|
||||
);
|
||||
const imageBitmap = await ReaderService.getImageBitmap(fileContext);
|
||||
const timerId = `faceDetection-${fileContext.enteFile.id}`;
|
||||
console.time(timerId);
|
||||
const faceDetections =
|
||||
@@ -93,10 +90,7 @@ class FaceService {
|
||||
return;
|
||||
}
|
||||
|
||||
const imageBitmap = await ReaderService.getImageBitmap(
|
||||
syncContext,
|
||||
fileContext,
|
||||
);
|
||||
const imageBitmap = await ReaderService.getImageBitmap(fileContext);
|
||||
newMlFile.faceCropMethod = syncContext.faceCropService.method;
|
||||
|
||||
for (const face of newMlFile.faces) {
|
||||
@@ -128,7 +122,7 @@ class FaceService {
|
||||
fileContext.newAlignment = true;
|
||||
const imageBitmap =
|
||||
fileContext.imageBitmap ||
|
||||
(await ReaderService.getImageBitmap(syncContext, fileContext));
|
||||
(await ReaderService.getImageBitmap(fileContext));
|
||||
|
||||
// Execute the face alignment calculations
|
||||
for (const face of newMlFile.faces) {
|
||||
@@ -179,7 +173,7 @@ class FaceService {
|
||||
newMlFile.faceEmbeddingMethod = syncContext.faceEmbeddingService.method;
|
||||
// TODO: when not storing face crops, image will be needed to extract faces
|
||||
// fileContext.imageBitmap ||
|
||||
// (await this.getImageBitmap(syncContext, fileContext));
|
||||
// (await this.getImageBitmap(fileContext));
|
||||
|
||||
const embeddings =
|
||||
await syncContext.faceEmbeddingService.getFaceEmbeddings(
|
||||
|
||||
@@ -181,15 +181,6 @@ export class MLFactory {
|
||||
|
||||
throw Error("Unknon clustering method: " + method);
|
||||
}
|
||||
|
||||
public static getMLSyncContext(
|
||||
token: string,
|
||||
userID: number,
|
||||
config: MLSyncConfig,
|
||||
shouldUpdateMLVersion: boolean = true,
|
||||
) {
|
||||
return new LocalMLSyncContext(token, userID, shouldUpdateMLVersion);
|
||||
}
|
||||
}
|
||||
|
||||
export class LocalMLSyncContext implements MLSyncContext {
|
||||
@@ -465,17 +456,9 @@ class MachineLearningService {
|
||||
if (!this.syncContext) {
|
||||
log.info("Creating syncContext");
|
||||
|
||||
const mlSyncConfig = DEFAULT_ML_SYNC_CONFIG;
|
||||
// TODO-ML(MR): Keep as promise for now.
|
||||
this.syncContext = new Promise((resolve) => {
|
||||
resolve(
|
||||
MLFactory.getMLSyncContext(
|
||||
token,
|
||||
userID,
|
||||
mlSyncConfig,
|
||||
true,
|
||||
),
|
||||
);
|
||||
resolve(new LocalMLSyncContext(token, userID, true));
|
||||
});
|
||||
} else {
|
||||
log.info("reusing existing syncContext");
|
||||
@@ -488,15 +471,7 @@ class MachineLearningService {
|
||||
log.info("Creating localSyncContext");
|
||||
// TODO-ML(MR):
|
||||
this.localSyncContext = new Promise((resolve) => {
|
||||
const mlSyncConfig = DEFAULT_ML_SYNC_CONFIG;
|
||||
resolve(
|
||||
MLFactory.getMLSyncContext(
|
||||
token,
|
||||
userID,
|
||||
mlSyncConfig,
|
||||
false,
|
||||
),
|
||||
);
|
||||
resolve(new LocalMLSyncContext(token, userID, false));
|
||||
});
|
||||
} else {
|
||||
log.info("reusing existing localSyncContext");
|
||||
@@ -610,7 +585,7 @@ class MachineLearningService {
|
||||
}
|
||||
|
||||
try {
|
||||
await ReaderService.getImageBitmap(syncContext, fileContext);
|
||||
await ReaderService.getImageBitmap(fileContext);
|
||||
await Promise.all([
|
||||
this.syncFileAnalyzeFaces(syncContext, fileContext),
|
||||
]);
|
||||
|
||||
@@ -4,21 +4,14 @@ import log from "@/next/log";
|
||||
import DownloadManager from "services/download";
|
||||
import { getLocalFiles } from "services/fileService";
|
||||
import { Dimensions } from "services/ml/geom";
|
||||
import {
|
||||
DetectedFace,
|
||||
MLSyncContext,
|
||||
MLSyncFileContext,
|
||||
} from "services/ml/types";
|
||||
import { DetectedFace, MLSyncFileContext } from "services/ml/types";
|
||||
import { EnteFile } from "types/file";
|
||||
import { getRenderableImage } from "utils/file";
|
||||
import { clamp } from "utils/image";
|
||||
import { DEFAULT_ML_SYNC_CONFIG } from "./machineLearningService";
|
||||
|
||||
class ReaderService {
|
||||
async getImageBitmap(
|
||||
syncContext: MLSyncContext,
|
||||
fileContext: MLSyncFileContext,
|
||||
) {
|
||||
async getImageBitmap(fileContext: MLSyncFileContext) {
|
||||
try {
|
||||
if (fileContext.imageBitmap) {
|
||||
return fileContext.imageBitmap;
|
||||
|
||||
@@ -208,7 +208,6 @@ export interface MLSearchConfig {
|
||||
export interface MLSyncContext {
|
||||
token: string;
|
||||
userID: number;
|
||||
config: MLSyncConfig;
|
||||
shouldUpdateMLVersion: boolean;
|
||||
|
||||
faceDetectionService: FaceDetectionService;
|
||||
|
||||
Reference in New Issue
Block a user