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 ObjectService from './objectService';
|
||||||
// import TextService from './textService';
|
// import TextService from './textService';
|
||||||
import ReaderService from './readerService';
|
import ReaderService from './readerService';
|
||||||
|
import { logError } from 'utils/sentry';
|
||||||
class MachineLearningService {
|
class MachineLearningService {
|
||||||
private initialized = false;
|
private initialized = false;
|
||||||
// private faceDetectionService: FaceDetectionService;
|
// private faceDetectionService: FaceDetectionService;
|
||||||
|
@ -361,6 +362,7 @@ class MachineLearningService {
|
||||||
syncContext.nSyncedFiles += 1;
|
syncContext.nSyncedFiles += 1;
|
||||||
return mlFileData;
|
return mlFileData;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
logError(e, 'ML syncFile failed');
|
||||||
let error = e;
|
let error = e;
|
||||||
console.error('Error in ml sync, fileId: ', enteFile.id, error);
|
console.error('Error in ml sync, fileId: ', enteFile.id, error);
|
||||||
if ('status' in error) {
|
if ('status' in error) {
|
||||||
|
@ -409,30 +411,10 @@ class MachineLearningService {
|
||||||
newMlFile.mlVersion = fileContext.oldMlFile.mlVersion;
|
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 {
|
try {
|
||||||
|
await ReaderService.getImageBitmap(syncContext, fileContext);
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
faceDetection(),
|
this.syncFaceDetections(syncContext, fileContext),
|
||||||
ObjectService.syncFileObjectDetections(
|
ObjectService.syncFileObjectDetections(
|
||||||
syncContext,
|
syncContext,
|
||||||
fileContext
|
fileContext
|
||||||
|
@ -447,6 +429,7 @@ class MachineLearningService {
|
||||||
newMlFile.lastErrorMessage = undefined;
|
newMlFile.lastErrorMessage = undefined;
|
||||||
await this.persistMLFileData(syncContext, newMlFile);
|
await this.persistMLFileData(syncContext, newMlFile);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
logError(e, 'ml detection failed');
|
||||||
newMlFile.mlVersion = oldMlFile.mlVersion;
|
newMlFile.mlVersion = oldMlFile.mlVersion;
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -561,6 +544,25 @@ class MachineLearningService {
|
||||||
syncContext.tsne = toTSNE(input, syncContext.config.tsne);
|
syncContext.tsne = toTSNE(input, syncContext.config.tsne);
|
||||||
console.log('tsne: ', syncContext.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();
|
export default new MachineLearningService();
|
||||||
|
|
|
@ -5,19 +5,25 @@ import {
|
||||||
getOriginalImageBitmap,
|
getOriginalImageBitmap,
|
||||||
getThumbnailImageBitmap,
|
getThumbnailImageBitmap,
|
||||||
} from 'utils/machineLearning';
|
} from 'utils/machineLearning';
|
||||||
|
import { logError } from 'utils/sentry';
|
||||||
|
|
||||||
class ReaderService {
|
class ReaderService {
|
||||||
async getImageBitmap(
|
async getImageBitmap(
|
||||||
syncContext: MLSyncContext,
|
syncContext: MLSyncContext,
|
||||||
fileContext: MLSyncFileContext
|
fileContext: MLSyncFileContext
|
||||||
) {
|
) {
|
||||||
|
try {
|
||||||
if (fileContext.imageBitmap) {
|
if (fileContext.imageBitmap) {
|
||||||
return fileContext.imageBitmap;
|
return fileContext.imageBitmap;
|
||||||
}
|
}
|
||||||
// console.log('1 TF Memory stats: ', tf.memory());
|
// console.log('1 TF Memory stats: ', tf.memory());
|
||||||
if (fileContext.localFile) {
|
if (fileContext.localFile) {
|
||||||
if (fileContext.enteFile.metadata.fileType !== FILE_TYPE.IMAGE) {
|
if (
|
||||||
throw new Error('Local file of only image type is supported');
|
fileContext.enteFile.metadata.fileType !== FILE_TYPE.IMAGE
|
||||||
|
) {
|
||||||
|
throw new Error(
|
||||||
|
'Local file of only image type is supported'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
fileContext.imageBitmap = await getLocalFileImageBitmap(
|
fileContext.imageBitmap = await getLocalFileImageBitmap(
|
||||||
fileContext.enteFile,
|
fileContext.enteFile,
|
||||||
|
@ -47,6 +53,10 @@ class ReaderService {
|
||||||
// console.log('2 TF Memory stats: ', tf.memory());
|
// console.log('2 TF Memory stats: ', tf.memory());
|
||||||
|
|
||||||
return fileContext.imageBitmap;
|
return fileContext.imageBitmap;
|
||||||
|
} catch (e) {
|
||||||
|
logError(e, 'failed to create image bitmap');
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export default new ReaderService();
|
export default new ReaderService();
|
||||||
|
|
Loading…
Reference in a new issue