PredictFaceExpressionsTask.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var tslib_1 = require("tslib");
  4. var WithFaceExpressions_1 = require("../factories/WithFaceExpressions");
  5. var ComposableTask_1 = require("./ComposableTask");
  6. var ComputeFaceDescriptorsTasks_1 = require("./ComputeFaceDescriptorsTasks");
  7. var extractFacesAndComputeResults_1 = require("./extractFacesAndComputeResults");
  8. var nets_1 = require("./nets");
  9. var PredictAgeAndGenderTask_1 = require("./PredictAgeAndGenderTask");
  10. var PredictFaceExpressionsTaskBase = /** @class */ (function (_super) {
  11. tslib_1.__extends(PredictFaceExpressionsTaskBase, _super);
  12. function PredictFaceExpressionsTaskBase(parentTask, input, extractedFaces) {
  13. var _this = _super.call(this) || this;
  14. _this.parentTask = parentTask;
  15. _this.input = input;
  16. _this.extractedFaces = extractedFaces;
  17. return _this;
  18. }
  19. return PredictFaceExpressionsTaskBase;
  20. }(ComposableTask_1.ComposableTask));
  21. exports.PredictFaceExpressionsTaskBase = PredictFaceExpressionsTaskBase;
  22. var PredictAllFaceExpressionsTask = /** @class */ (function (_super) {
  23. tslib_1.__extends(PredictAllFaceExpressionsTask, _super);
  24. function PredictAllFaceExpressionsTask() {
  25. return _super !== null && _super.apply(this, arguments) || this;
  26. }
  27. PredictAllFaceExpressionsTask.prototype.run = function () {
  28. return tslib_1.__awaiter(this, void 0, void 0, function () {
  29. var parentResults, faceExpressionsByFace;
  30. var _this = this;
  31. return tslib_1.__generator(this, function (_a) {
  32. switch (_a.label) {
  33. case 0: return [4 /*yield*/, this.parentTask];
  34. case 1:
  35. parentResults = _a.sent();
  36. return [4 /*yield*/, extractFacesAndComputeResults_1.extractAllFacesAndComputeResults(parentResults, this.input, function (faces) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
  37. return tslib_1.__generator(this, function (_a) {
  38. switch (_a.label) {
  39. case 0: return [4 /*yield*/, Promise.all(faces.map(function (face) { return nets_1.nets.faceExpressionNet.predictExpressions(face); }))];
  40. case 1: return [2 /*return*/, _a.sent()];
  41. }
  42. });
  43. }); }, this.extractedFaces)];
  44. case 2:
  45. faceExpressionsByFace = _a.sent();
  46. return [2 /*return*/, parentResults.map(function (parentResult, i) { return WithFaceExpressions_1.extendWithFaceExpressions(parentResult, faceExpressionsByFace[i]); })];
  47. }
  48. });
  49. });
  50. };
  51. PredictAllFaceExpressionsTask.prototype.withAgeAndGender = function () {
  52. return new PredictAgeAndGenderTask_1.PredictAllAgeAndGenderTask(this, this.input);
  53. };
  54. return PredictAllFaceExpressionsTask;
  55. }(PredictFaceExpressionsTaskBase));
  56. exports.PredictAllFaceExpressionsTask = PredictAllFaceExpressionsTask;
  57. var PredictSingleFaceExpressionsTask = /** @class */ (function (_super) {
  58. tslib_1.__extends(PredictSingleFaceExpressionsTask, _super);
  59. function PredictSingleFaceExpressionsTask() {
  60. return _super !== null && _super.apply(this, arguments) || this;
  61. }
  62. PredictSingleFaceExpressionsTask.prototype.run = function () {
  63. return tslib_1.__awaiter(this, void 0, void 0, function () {
  64. var parentResult, faceExpressions;
  65. return tslib_1.__generator(this, function (_a) {
  66. switch (_a.label) {
  67. case 0: return [4 /*yield*/, this.parentTask];
  68. case 1:
  69. parentResult = _a.sent();
  70. if (!parentResult) {
  71. return [2 /*return*/];
  72. }
  73. return [4 /*yield*/, extractFacesAndComputeResults_1.extractSingleFaceAndComputeResult(parentResult, this.input, function (face) { return nets_1.nets.faceExpressionNet.predictExpressions(face); }, this.extractedFaces)];
  74. case 2:
  75. faceExpressions = _a.sent();
  76. return [2 /*return*/, WithFaceExpressions_1.extendWithFaceExpressions(parentResult, faceExpressions)];
  77. }
  78. });
  79. });
  80. };
  81. PredictSingleFaceExpressionsTask.prototype.withAgeAndGender = function () {
  82. return new PredictAgeAndGenderTask_1.PredictSingleAgeAndGenderTask(this, this.input);
  83. };
  84. return PredictSingleFaceExpressionsTask;
  85. }(PredictFaceExpressionsTaskBase));
  86. exports.PredictSingleFaceExpressionsTask = PredictSingleFaceExpressionsTask;
  87. var PredictAllFaceExpressionsWithFaceAlignmentTask = /** @class */ (function (_super) {
  88. tslib_1.__extends(PredictAllFaceExpressionsWithFaceAlignmentTask, _super);
  89. function PredictAllFaceExpressionsWithFaceAlignmentTask() {
  90. return _super !== null && _super.apply(this, arguments) || this;
  91. }
  92. PredictAllFaceExpressionsWithFaceAlignmentTask.prototype.withAgeAndGender = function () {
  93. return new PredictAgeAndGenderTask_1.PredictAllAgeAndGenderWithFaceAlignmentTask(this, this.input);
  94. };
  95. PredictAllFaceExpressionsWithFaceAlignmentTask.prototype.withFaceDescriptors = function () {
  96. return new ComputeFaceDescriptorsTasks_1.ComputeAllFaceDescriptorsTask(this, this.input);
  97. };
  98. return PredictAllFaceExpressionsWithFaceAlignmentTask;
  99. }(PredictAllFaceExpressionsTask));
  100. exports.PredictAllFaceExpressionsWithFaceAlignmentTask = PredictAllFaceExpressionsWithFaceAlignmentTask;
  101. var PredictSingleFaceExpressionsWithFaceAlignmentTask = /** @class */ (function (_super) {
  102. tslib_1.__extends(PredictSingleFaceExpressionsWithFaceAlignmentTask, _super);
  103. function PredictSingleFaceExpressionsWithFaceAlignmentTask() {
  104. return _super !== null && _super.apply(this, arguments) || this;
  105. }
  106. PredictSingleFaceExpressionsWithFaceAlignmentTask.prototype.withAgeAndGender = function () {
  107. return new PredictAgeAndGenderTask_1.PredictSingleAgeAndGenderWithFaceAlignmentTask(this, this.input);
  108. };
  109. PredictSingleFaceExpressionsWithFaceAlignmentTask.prototype.withFaceDescriptor = function () {
  110. return new ComputeFaceDescriptorsTasks_1.ComputeSingleFaceDescriptorTask(this, this.input);
  111. };
  112. return PredictSingleFaceExpressionsWithFaceAlignmentTask;
  113. }(PredictSingleFaceExpressionsTask));
  114. exports.PredictSingleFaceExpressionsWithFaceAlignmentTask = PredictSingleFaceExpressionsWithFaceAlignmentTask;
  115. //# sourceMappingURL=PredictFaceExpressionsTask.js.map