face-api/build/globalApi/PredictAgeAndGenderTask.js

66 lines
3.6 KiB
JavaScript
Raw Normal View History

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PredictSingleAgeAndGenderWithFaceAlignmentTask = exports.PredictAllAgeAndGenderWithFaceAlignmentTask = exports.PredictSingleAgeAndGenderTask = exports.PredictAllAgeAndGenderTask = exports.PredictAgeAndGenderTaskBase = void 0;
const WithAge_1 = require("../factories/WithAge");
const WithGender_1 = require("../factories/WithGender");
const ComposableTask_1 = require("./ComposableTask");
const ComputeFaceDescriptorsTasks_1 = require("./ComputeFaceDescriptorsTasks");
const extractFacesAndComputeResults_1 = require("./extractFacesAndComputeResults");
const nets_1 = require("./nets");
const PredictFaceExpressionsTask_1 = require("./PredictFaceExpressionsTask");
class PredictAgeAndGenderTaskBase extends ComposableTask_1.ComposableTask {
2020-08-18 14:04:33 +02:00
constructor(parentTask, input, extractedFaces) {
super();
this.parentTask = parentTask;
this.input = input;
this.extractedFaces = extractedFaces;
}
}
exports.PredictAgeAndGenderTaskBase = PredictAgeAndGenderTaskBase;
class PredictAllAgeAndGenderTask extends PredictAgeAndGenderTaskBase {
2020-08-18 14:04:33 +02:00
async run() {
const parentResults = await this.parentTask;
const ageAndGenderByFace = await extractFacesAndComputeResults_1.extractAllFacesAndComputeResults(parentResults, this.input, async (faces) => await Promise.all(faces.map(face => nets_1.nets.ageGenderNet.predictAgeAndGender(face))), this.extractedFaces);
2020-08-18 14:04:33 +02:00
return parentResults.map((parentResult, i) => {
const { age, gender, genderProbability } = ageAndGenderByFace[i];
return WithAge_1.extendWithAge(WithGender_1.extendWithGender(parentResult, gender, genderProbability), age);
2020-08-18 14:04:33 +02:00
});
}
withFaceExpressions() {
return new PredictFaceExpressionsTask_1.PredictAllFaceExpressionsTask(this, this.input);
2020-08-18 14:04:33 +02:00
}
}
exports.PredictAllAgeAndGenderTask = PredictAllAgeAndGenderTask;
class PredictSingleAgeAndGenderTask extends PredictAgeAndGenderTaskBase {
2020-08-18 14:04:33 +02:00
async run() {
const parentResult = await this.parentTask;
if (!parentResult) {
return;
}
const { age, gender, genderProbability } = await extractFacesAndComputeResults_1.extractSingleFaceAndComputeResult(parentResult, this.input, face => nets_1.nets.ageGenderNet.predictAgeAndGender(face), this.extractedFaces);
return WithAge_1.extendWithAge(WithGender_1.extendWithGender(parentResult, gender, genderProbability), age);
2020-08-18 14:04:33 +02:00
}
withFaceExpressions() {
return new PredictFaceExpressionsTask_1.PredictSingleFaceExpressionsTask(this, this.input);
2020-08-18 14:04:33 +02:00
}
}
exports.PredictSingleAgeAndGenderTask = PredictSingleAgeAndGenderTask;
class PredictAllAgeAndGenderWithFaceAlignmentTask extends PredictAllAgeAndGenderTask {
2020-08-18 14:04:33 +02:00
withFaceExpressions() {
return new PredictFaceExpressionsTask_1.PredictAllFaceExpressionsWithFaceAlignmentTask(this, this.input);
2020-08-18 14:04:33 +02:00
}
withFaceDescriptors() {
return new ComputeFaceDescriptorsTasks_1.ComputeAllFaceDescriptorsTask(this, this.input);
2020-08-18 14:04:33 +02:00
}
}
exports.PredictAllAgeAndGenderWithFaceAlignmentTask = PredictAllAgeAndGenderWithFaceAlignmentTask;
class PredictSingleAgeAndGenderWithFaceAlignmentTask extends PredictSingleAgeAndGenderTask {
2020-08-18 14:04:33 +02:00
withFaceExpressions() {
return new PredictFaceExpressionsTask_1.PredictSingleFaceExpressionsWithFaceAlignmentTask(this, this.input);
2020-08-18 14:04:33 +02:00
}
withFaceDescriptor() {
return new ComputeFaceDescriptorsTasks_1.ComputeSingleFaceDescriptorTask(this, this.input);
2020-08-18 14:04:33 +02:00
}
}
exports.PredictSingleAgeAndGenderWithFaceAlignmentTask = PredictSingleAgeAndGenderWithFaceAlignmentTask;
2020-08-18 14:04:33 +02:00
//# sourceMappingURL=PredictAgeAndGenderTask.js.map