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