fix(face-landmarks): dispose tensors to avoid memory leaks
Also send only expressions with score grater than 50%.
This commit is contained in:
parent
4f49cde73e
commit
8a503e7b40
|
@ -99,8 +99,14 @@ const detectFaceBox = async ({ detections, threshold }: Detection) => {
|
||||||
return faceBox;
|
return faceBox;
|
||||||
};
|
};
|
||||||
|
|
||||||
const detectFaceExpression = async ({ detections }: Detection) =>
|
const detectFaceExpression = async ({ detections }: Detection) => {
|
||||||
detections[0]?.emotion && FACE_EXPRESSIONS_NAMING_MAPPING[detections[0]?.emotion[0].emotion];
|
if (!detections[0]?.emotion || detections[0]?.emotion[0].score < 0.5) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FACE_EXPRESSIONS_NAMING_MAPPING[detections[0]?.emotion[0].emotion];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const detect = async ({ image, threshold } : DetectInput) => {
|
const detect = async ({ image, threshold } : DetectInput) => {
|
||||||
let detections;
|
let detections;
|
||||||
|
@ -108,6 +114,7 @@ const detect = async ({ image, threshold } : DetectInput) => {
|
||||||
let faceBox;
|
let faceBox;
|
||||||
|
|
||||||
detectionInProgress = true;
|
detectionInProgress = true;
|
||||||
|
human.tf.engine().startScope();
|
||||||
|
|
||||||
const imageTensor = human.tf.browser.fromPixels(image);
|
const imageTensor = human.tf.browser.fromPixels(image);
|
||||||
|
|
||||||
|
@ -131,6 +138,8 @@ const detect = async ({ image, threshold } : DetectInput) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
human.tf.engine().endScope()
|
||||||
|
|
||||||
if (faceBox || faceExpression) {
|
if (faceBox || faceExpression) {
|
||||||
self.postMessage({
|
self.postMessage({
|
||||||
faceBox,
|
faceBox,
|
||||||
|
|
Loading…
Reference in New Issue