2020-08-20 02:10:42 +02:00
|
|
|
import { extendWithFaceExpressions } from '../factories/WithFaceExpressions';
|
|
|
|
import { ComposableTask } from './ComposableTask';
|
|
|
|
import { ComputeAllFaceDescriptorsTask, ComputeSingleFaceDescriptorTask } from './ComputeFaceDescriptorsTasks';
|
|
|
|
import { extractAllFacesAndComputeResults, extractSingleFaceAndComputeResult } from './extractFacesAndComputeResults';
|
|
|
|
import { nets } from './nets';
|
|
|
|
import { PredictAllAgeAndGenderTask, PredictAllAgeAndGenderWithFaceAlignmentTask, PredictSingleAgeAndGenderTask, PredictSingleAgeAndGenderWithFaceAlignmentTask, } from './PredictAgeAndGenderTask';
|
|
|
|
export class PredictFaceExpressionsTaskBase 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 PredictAllFaceExpressionsTask extends PredictFaceExpressionsTaskBase {
|
2020-08-18 14:04:33 +02:00
|
|
|
async run() {
|
|
|
|
const parentResults = await this.parentTask;
|
2020-08-20 02:10:42 +02:00
|
|
|
const faceExpressionsByFace = await extractAllFacesAndComputeResults(parentResults, this.input, async (faces) => await Promise.all(faces.map(face => nets.faceExpressionNet.predictExpressions(face))), this.extractedFaces);
|
|
|
|
return parentResults.map((parentResult, i) => extendWithFaceExpressions(parentResult, faceExpressionsByFace[i]));
|
2020-08-18 14:04:33 +02:00
|
|
|
}
|
|
|
|
withAgeAndGender() {
|
2020-08-20 02:10:42 +02:00
|
|
|
return new PredictAllAgeAndGenderTask(this, this.input);
|
2020-08-18 14:04:33 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-20 02:10:42 +02:00
|
|
|
export class PredictSingleFaceExpressionsTask extends PredictFaceExpressionsTaskBase {
|
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 faceExpressions = await extractSingleFaceAndComputeResult(parentResult, this.input, face => nets.faceExpressionNet.predictExpressions(face), this.extractedFaces);
|
|
|
|
return extendWithFaceExpressions(parentResult, faceExpressions);
|
2020-08-18 14:04:33 +02:00
|
|
|
}
|
|
|
|
withAgeAndGender() {
|
2020-08-20 02:10:42 +02:00
|
|
|
return new PredictSingleAgeAndGenderTask(this, this.input);
|
2020-08-18 14:04:33 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-20 02:10:42 +02:00
|
|
|
export class PredictAllFaceExpressionsWithFaceAlignmentTask extends PredictAllFaceExpressionsTask {
|
2020-08-18 14:04:33 +02:00
|
|
|
withAgeAndGender() {
|
2020-08-20 02:10:42 +02:00
|
|
|
return new PredictAllAgeAndGenderWithFaceAlignmentTask(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 PredictSingleFaceExpressionsWithFaceAlignmentTask extends PredictSingleFaceExpressionsTask {
|
2020-08-18 14:04:33 +02:00
|
|
|
withAgeAndGender() {
|
2020-08-20 02:10:42 +02:00
|
|
|
return new PredictSingleAgeAndGenderWithFaceAlignmentTask(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=PredictFaceExpressionsTask.js.map
|