2020-08-20 02:10:42 +02:00
|
|
|
import { extendWithAge } from '../factories/WithAge';
|
|
|
|
import { extendWithGender } from '../factories/WithGender';
|
|
|
|
import { ComposableTask } from './ComposableTask';
|
|
|
|
import { ComputeAllFaceDescriptorsTask, ComputeSingleFaceDescriptorTask } from './ComputeFaceDescriptorsTasks';
|
|
|
|
import { extractAllFacesAndComputeResults, extractSingleFaceAndComputeResult } from './extractFacesAndComputeResults';
|
|
|
|
import { nets } from './nets';
|
|
|
|
import { PredictAllFaceExpressionsTask, PredictAllFaceExpressionsWithFaceAlignmentTask, PredictSingleFaceExpressionsTask, PredictSingleFaceExpressionsWithFaceAlignmentTask, } from './PredictFaceExpressionsTask';
|
|
|
|
export class PredictAgeAndGenderTaskBase extends ComposableTask {
|
2020-08-18 14:04:33 +02:00
|
|
|
constructor(parentTask, input, extractedFaces) {
|
|
|
|
super();
|
|
|
|
this.parentTask = parentTask;
|
|
|
|
this.input = input;
|
|
|
|
this.extractedFaces = extractedFaces;
|
|
|
|
}
|
|
|
|
}
|
2020-08-20 02:10:42 +02:00
|
|
|
export class PredictAllAgeAndGenderTask extends PredictAgeAndGenderTaskBase {
|
2020-08-18 14:04:33 +02:00
|
|
|
async run() {
|
|
|
|
const parentResults = await this.parentTask;
|
2020-08-20 02:10:42 +02:00
|
|
|
const ageAndGenderByFace = await extractAllFacesAndComputeResults(parentResults, this.input, async (faces) => await Promise.all(faces.map(face => 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];
|
2020-08-20 02:10:42 +02:00
|
|
|
return extendWithAge(extendWithGender(parentResult, gender, genderProbability), age);
|
2020-08-18 14:04:33 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
withFaceExpressions() {
|
2020-08-20 02:10:42 +02:00
|
|
|
return new PredictAllFaceExpressionsTask(this, this.input);
|
2020-08-18 14:04:33 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-20 02:10:42 +02:00
|
|
|
export class PredictSingleAgeAndGenderTask extends PredictAgeAndGenderTaskBase {
|
2020-08-18 14:04:33 +02:00
|
|
|
async run() {
|
|
|
|
const parentResult = await this.parentTask;
|
|
|
|
if (!parentResult) {
|
|
|
|
return;
|
|
|
|
}
|
2020-08-20 02:10:42 +02:00
|
|
|
const { age, gender, genderProbability } = await extractSingleFaceAndComputeResult(parentResult, this.input, face => nets.ageGenderNet.predictAgeAndGender(face), this.extractedFaces);
|
|
|
|
return extendWithAge(extendWithGender(parentResult, gender, genderProbability), age);
|
2020-08-18 14:04:33 +02:00
|
|
|
}
|
|
|
|
withFaceExpressions() {
|
2020-08-20 02:10:42 +02:00
|
|
|
return new PredictSingleFaceExpressionsTask(this, this.input);
|
2020-08-18 14:04:33 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-20 02:10:42 +02:00
|
|
|
export class PredictAllAgeAndGenderWithFaceAlignmentTask extends PredictAllAgeAndGenderTask {
|
2020-08-18 14:04:33 +02:00
|
|
|
withFaceExpressions() {
|
2020-08-20 02:10:42 +02:00
|
|
|
return new PredictAllFaceExpressionsWithFaceAlignmentTask(this, this.input);
|
2020-08-18 14:04:33 +02:00
|
|
|
}
|
|
|
|
withFaceDescriptors() {
|
2020-08-20 02:10:42 +02:00
|
|
|
return new ComputeAllFaceDescriptorsTask(this, this.input);
|
2020-08-18 14:04:33 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-20 02:10:42 +02:00
|
|
|
export class PredictSingleAgeAndGenderWithFaceAlignmentTask extends PredictSingleAgeAndGenderTask {
|
2020-08-18 14:04:33 +02:00
|
|
|
withFaceExpressions() {
|
2020-08-20 02:10:42 +02:00
|
|
|
return new PredictSingleFaceExpressionsWithFaceAlignmentTask(this, this.input);
|
2020-08-18 14:04:33 +02:00
|
|
|
}
|
|
|
|
withFaceDescriptor() {
|
2020-08-20 02:10:42 +02:00
|
|
|
return new ComputeSingleFaceDescriptorTask(this, this.input);
|
2020-08-18 14:04:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//# sourceMappingURL=PredictAgeAndGenderTask.js.map
|