fix(face-landmarks): human helper tensor disposal and async functions (#11596)

* fix(face-landmarks): human helper tensor disposal and async functions

* fix(face-landmarks): rename functions in interface
This commit is contained in:
Gabriel Borlea 2022-05-30 16:04:20 +03:00 committed by GitHub
parent b5f3cd14c2
commit 11d61d6d7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 6 deletions

View File

@ -30,8 +30,8 @@ type DetectOutput = {
};
export interface FaceLandmarksHelper {
detectFaceBox({ detections, threshold }: Detection): Promise<FaceBox | undefined>;
detectFaceExpression({ detections }: Detection): Promise<string | undefined>;
getFaceBox({ detections, threshold }: Detection): FaceBox | undefined;
getFaceExpression({ detections }: Detection): string | undefined;
init(): Promise<void>;
detect({ image, threshold } : DetectInput): Promise<DetectOutput | undefined>;
getDetectionInProgress(): boolean;
@ -118,7 +118,7 @@ export class HumanHelper implements FaceLandmarksHelper {
}
}
async detectFaceBox({ detections, threshold }: Detection): Promise<FaceBox | undefined> {
getFaceBox({ detections, threshold }: Detection): FaceBox | undefined {
if (!detections.length) {
return;
}
@ -140,7 +140,7 @@ export class HumanHelper implements FaceLandmarksHelper {
return faceBox;
}
async detectFaceExpression({ detections }: Detection): Promise<string | undefined> {
getFaceExpression({ detections }: Detection): string | undefined {
if (detections[0]?.emotion) {
return FACE_EXPRESSIONS_NAMING_MAPPING[detections[0]?.emotion[0].emotion];
}
@ -156,6 +156,7 @@ export class HumanHelper implements FaceLandmarksHelper {
}
this.detectionInProgress = true;
this.human.tf.engine().startScope();
const imageTensor = this.human.tf.browser.fromPixels(image);
@ -163,7 +164,7 @@ export class HumanHelper implements FaceLandmarksHelper {
const { face } = await this.human.detect(imageTensor, this.config);
detections = face;
faceExpression = await this.detectFaceExpression({ detections });
faceExpression = this.getFaceExpression({ detections });
}
if (this.faceDetectionTypes.includes(DETECTION_TYPES.FACE_BOX)) {
@ -173,12 +174,13 @@ export class HumanHelper implements FaceLandmarksHelper {
detections = face;
}
faceBox = await this.detectFaceBox({
faceBox = this.getFaceBox({
detections,
threshold
});
}
this.human.tf.engine().endScope();
this.detectionInProgress = false;
return {