add logs and refactor code
This commit is contained in:
parent
4fb7655081
commit
b506d8586e
|
@ -34,6 +34,7 @@ import PeopleService from './peopleService';
|
|||
import ObjectService from './objectService';
|
||||
// import TextService from './textService';
|
||||
import ReaderService from './readerService';
|
||||
import { logError } from 'utils/sentry';
|
||||
class MachineLearningService {
|
||||
private initialized = false;
|
||||
// private faceDetectionService: FaceDetectionService;
|
||||
|
@ -361,6 +362,7 @@ class MachineLearningService {
|
|||
syncContext.nSyncedFiles += 1;
|
||||
return mlFileData;
|
||||
} catch (e) {
|
||||
logError(e, 'ML syncFile failed');
|
||||
let error = e;
|
||||
console.error('Error in ml sync, fileId: ', enteFile.id, error);
|
||||
if ('status' in error) {
|
||||
|
@ -409,30 +411,10 @@ class MachineLearningService {
|
|||
newMlFile.mlVersion = fileContext.oldMlFile.mlVersion;
|
||||
}
|
||||
|
||||
await ReaderService.getImageBitmap(syncContext, fileContext);
|
||||
|
||||
const faceDetection = async () => {
|
||||
console.time(`face detection time taken ${enteFile.id}`);
|
||||
await FaceService.syncFileFaceDetections(syncContext, fileContext);
|
||||
|
||||
if (newMlFile.faces && newMlFile.faces.length > 0) {
|
||||
await FaceService.syncFileFaceCrops(syncContext, fileContext);
|
||||
|
||||
await FaceService.syncFileFaceAlignments(
|
||||
syncContext,
|
||||
fileContext
|
||||
);
|
||||
|
||||
await FaceService.syncFileFaceEmbeddings(
|
||||
syncContext,
|
||||
fileContext
|
||||
);
|
||||
}
|
||||
console.timeEnd(`face detection time taken ${enteFile.id}`);
|
||||
};
|
||||
try {
|
||||
await ReaderService.getImageBitmap(syncContext, fileContext);
|
||||
await Promise.all([
|
||||
faceDetection(),
|
||||
this.syncFaceDetections(syncContext, fileContext),
|
||||
ObjectService.syncFileObjectDetections(
|
||||
syncContext,
|
||||
fileContext
|
||||
|
@ -447,6 +429,7 @@ class MachineLearningService {
|
|||
newMlFile.lastErrorMessage = undefined;
|
||||
await this.persistMLFileData(syncContext, newMlFile);
|
||||
} catch (e) {
|
||||
logError(e, 'ml detection failed');
|
||||
newMlFile.mlVersion = oldMlFile.mlVersion;
|
||||
throw e;
|
||||
} finally {
|
||||
|
@ -561,6 +544,25 @@ class MachineLearningService {
|
|||
syncContext.tsne = toTSNE(input, syncContext.config.tsne);
|
||||
console.log('tsne: ', syncContext.tsne);
|
||||
}
|
||||
|
||||
private async syncFaceDetections(
|
||||
syncContext: MLSyncContext,
|
||||
fileContext: MLSyncFileContext
|
||||
) {
|
||||
console.time(`object detection time taken ${fileContext.enteFile.id}`);
|
||||
const { newMlFile } = fileContext;
|
||||
console.time(`face detection time taken ${fileContext.enteFile.id}`);
|
||||
await FaceService.syncFileFaceDetections(syncContext, fileContext);
|
||||
|
||||
if (newMlFile.faces && newMlFile.faces.length > 0) {
|
||||
await FaceService.syncFileFaceCrops(syncContext, fileContext);
|
||||
|
||||
await FaceService.syncFileFaceAlignments(syncContext, fileContext);
|
||||
|
||||
await FaceService.syncFileFaceEmbeddings(syncContext, fileContext);
|
||||
}
|
||||
console.timeEnd(`face detection time taken ${fileContext.enteFile.id}`);
|
||||
}
|
||||
}
|
||||
|
||||
export default new MachineLearningService();
|
||||
|
|
|
@ -5,19 +5,25 @@ import {
|
|||
getOriginalImageBitmap,
|
||||
getThumbnailImageBitmap,
|
||||
} from 'utils/machineLearning';
|
||||
import { logError } from 'utils/sentry';
|
||||
|
||||
class ReaderService {
|
||||
async getImageBitmap(
|
||||
syncContext: MLSyncContext,
|
||||
fileContext: MLSyncFileContext
|
||||
) {
|
||||
try {
|
||||
if (fileContext.imageBitmap) {
|
||||
return fileContext.imageBitmap;
|
||||
}
|
||||
// console.log('1 TF Memory stats: ', tf.memory());
|
||||
if (fileContext.localFile) {
|
||||
if (fileContext.enteFile.metadata.fileType !== FILE_TYPE.IMAGE) {
|
||||
throw new Error('Local file of only image type is supported');
|
||||
if (
|
||||
fileContext.enteFile.metadata.fileType !== FILE_TYPE.IMAGE
|
||||
) {
|
||||
throw new Error(
|
||||
'Local file of only image type is supported'
|
||||
);
|
||||
}
|
||||
fileContext.imageBitmap = await getLocalFileImageBitmap(
|
||||
fileContext.enteFile,
|
||||
|
@ -47,6 +53,10 @@ class ReaderService {
|
|||
// console.log('2 TF Memory stats: ', tf.memory());
|
||||
|
||||
return fileContext.imageBitmap;
|
||||
} catch (e) {
|
||||
logError(e, 'failed to create image bitmap');
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
export default new ReaderService();
|
||||
|
|
Loading…
Reference in a new issue