2020-08-20 02:05:34 +02:00
|
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
exports.DetectSingleFaceLandmarksTask = exports.DetectAllFaceLandmarksTask = exports.DetectFaceLandmarksTaskBase = void 0;
|
|
|
|
const tf = require("@tensorflow/tfjs-core");
|
|
|
|
const dom_1 = require("../dom");
|
|
|
|
const WithFaceLandmarks_1 = require("../factories/WithFaceLandmarks");
|
|
|
|
const ComposableTask_1 = require("./ComposableTask");
|
|
|
|
const ComputeFaceDescriptorsTasks_1 = require("./ComputeFaceDescriptorsTasks");
|
|
|
|
const nets_1 = require("./nets");
|
|
|
|
const PredictAgeAndGenderTask_1 = require("./PredictAgeAndGenderTask");
|
|
|
|
const PredictFaceExpressionsTask_1 = require("./PredictFaceExpressionsTask");
|
|
|
|
class DetectFaceLandmarksTaskBase extends ComposableTask_1.ComposableTask {
|
2020-08-18 14:04:33 +02:00
|
|
|
constructor(parentTask, input, useTinyLandmarkNet) {
|
|
|
|
super();
|
|
|
|
this.parentTask = parentTask;
|
|
|
|
this.input = input;
|
|
|
|
this.useTinyLandmarkNet = useTinyLandmarkNet;
|
|
|
|
}
|
|
|
|
get landmarkNet() {
|
|
|
|
return this.useTinyLandmarkNet
|
2020-08-20 02:05:34 +02:00
|
|
|
? nets_1.nets.faceLandmark68TinyNet
|
|
|
|
: nets_1.nets.faceLandmark68Net;
|
2020-08-18 14:04:33 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-20 02:05:34 +02:00
|
|
|
exports.DetectFaceLandmarksTaskBase = DetectFaceLandmarksTaskBase;
|
|
|
|
class DetectAllFaceLandmarksTask extends DetectFaceLandmarksTaskBase {
|
2020-08-18 14:04:33 +02:00
|
|
|
async run() {
|
|
|
|
const parentResults = await this.parentTask;
|
|
|
|
const detections = parentResults.map(res => res.detection);
|
|
|
|
const faces = this.input instanceof tf.Tensor
|
2020-08-20 02:05:34 +02:00
|
|
|
? await dom_1.extractFaceTensors(this.input, detections)
|
|
|
|
: await dom_1.extractFaces(this.input, detections);
|
2020-08-18 14:04:33 +02:00
|
|
|
const faceLandmarksByFace = await Promise.all(faces.map(face => this.landmarkNet.detectLandmarks(face)));
|
|
|
|
faces.forEach(f => f instanceof tf.Tensor && f.dispose());
|
2020-08-20 02:05:34 +02:00
|
|
|
return parentResults.map((parentResult, i) => WithFaceLandmarks_1.extendWithFaceLandmarks(parentResult, faceLandmarksByFace[i]));
|
2020-08-18 14:04:33 +02:00
|
|
|
}
|
|
|
|
withFaceExpressions() {
|
2020-08-20 02:05:34 +02:00
|
|
|
return new PredictFaceExpressionsTask_1.PredictAllFaceExpressionsWithFaceAlignmentTask(this, this.input);
|
2020-08-18 14:04:33 +02:00
|
|
|
}
|
|
|
|
withAgeAndGender() {
|
2020-08-20 02:05:34 +02:00
|
|
|
return new PredictAgeAndGenderTask_1.PredictAllAgeAndGenderWithFaceAlignmentTask(this, this.input);
|
2020-08-18 14:04:33 +02:00
|
|
|
}
|
|
|
|
withFaceDescriptors() {
|
2020-08-20 02:05:34 +02:00
|
|
|
return new ComputeFaceDescriptorsTasks_1.ComputeAllFaceDescriptorsTask(this, this.input);
|
2020-08-18 14:04:33 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-20 02:05:34 +02:00
|
|
|
exports.DetectAllFaceLandmarksTask = DetectAllFaceLandmarksTask;
|
|
|
|
class DetectSingleFaceLandmarksTask extends DetectFaceLandmarksTaskBase {
|
2020-08-18 14:04:33 +02:00
|
|
|
async run() {
|
|
|
|
const parentResult = await this.parentTask;
|
|
|
|
if (!parentResult) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const { detection } = parentResult;
|
|
|
|
const faces = this.input instanceof tf.Tensor
|
2020-08-20 02:05:34 +02:00
|
|
|
? await dom_1.extractFaceTensors(this.input, [detection])
|
|
|
|
: await dom_1.extractFaces(this.input, [detection]);
|
2020-08-18 14:04:33 +02:00
|
|
|
const landmarks = await this.landmarkNet.detectLandmarks(faces[0]);
|
|
|
|
faces.forEach(f => f instanceof tf.Tensor && f.dispose());
|
2020-08-20 02:05:34 +02:00
|
|
|
return WithFaceLandmarks_1.extendWithFaceLandmarks(parentResult, landmarks);
|
2020-08-18 14:04:33 +02:00
|
|
|
}
|
|
|
|
withFaceExpressions() {
|
2020-08-20 02:05:34 +02:00
|
|
|
return new PredictFaceExpressionsTask_1.PredictSingleFaceExpressionsWithFaceAlignmentTask(this, this.input);
|
2020-08-18 14:04:33 +02:00
|
|
|
}
|
|
|
|
withAgeAndGender() {
|
2020-08-20 02:05:34 +02:00
|
|
|
return new PredictAgeAndGenderTask_1.PredictSingleAgeAndGenderWithFaceAlignmentTask(this, this.input);
|
2020-08-18 14:04:33 +02:00
|
|
|
}
|
|
|
|
withFaceDescriptor() {
|
2020-08-20 02:05:34 +02:00
|
|
|
return new ComputeFaceDescriptorsTasks_1.ComputeSingleFaceDescriptorTask(this, this.input);
|
2020-08-18 14:04:33 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-20 02:05:34 +02:00
|
|
|
exports.DetectSingleFaceLandmarksTask = DetectSingleFaceLandmarksTask;
|
2020-08-18 14:04:33 +02:00
|
|
|
//# sourceMappingURL=DetectFaceLandmarksTasks.js.map
|