TinyYolov2.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { __awaiter, __extends, __generator } from "tslib";
  2. import { FaceDetection } from '../classes';
  3. import { BOX_ANCHORS, BOX_ANCHORS_SEPARABLE, DEFAULT_MODEL_NAME, DEFAULT_MODEL_NAME_SEPARABLE_CONV, IOU_THRESHOLD, MEAN_RGB_SEPARABLE, } from './const';
  4. import { TinyYolov2Base } from './TinyYolov2Base';
  5. var TinyYolov2 = /** @class */ (function (_super) {
  6. __extends(TinyYolov2, _super);
  7. function TinyYolov2(withSeparableConvs) {
  8. if (withSeparableConvs === void 0) { withSeparableConvs = true; }
  9. var _this = this;
  10. var config = Object.assign({}, {
  11. withSeparableConvs: withSeparableConvs,
  12. iouThreshold: IOU_THRESHOLD,
  13. classes: ['face']
  14. }, withSeparableConvs
  15. ? {
  16. anchors: BOX_ANCHORS_SEPARABLE,
  17. meanRgb: MEAN_RGB_SEPARABLE
  18. }
  19. : {
  20. anchors: BOX_ANCHORS,
  21. withClassScores: true
  22. });
  23. _this = _super.call(this, config) || this;
  24. return _this;
  25. }
  26. Object.defineProperty(TinyYolov2.prototype, "withSeparableConvs", {
  27. get: function () {
  28. return this.config.withSeparableConvs;
  29. },
  30. enumerable: true,
  31. configurable: true
  32. });
  33. Object.defineProperty(TinyYolov2.prototype, "anchors", {
  34. get: function () {
  35. return this.config.anchors;
  36. },
  37. enumerable: true,
  38. configurable: true
  39. });
  40. TinyYolov2.prototype.locateFaces = function (input, forwardParams) {
  41. return __awaiter(this, void 0, void 0, function () {
  42. var objectDetections;
  43. return __generator(this, function (_a) {
  44. switch (_a.label) {
  45. case 0: return [4 /*yield*/, this.detect(input, forwardParams)];
  46. case 1:
  47. objectDetections = _a.sent();
  48. return [2 /*return*/, objectDetections.map(function (det) { return new FaceDetection(det.score, det.relativeBox, { width: det.imageWidth, height: det.imageHeight }); })];
  49. }
  50. });
  51. });
  52. };
  53. TinyYolov2.prototype.getDefaultModelName = function () {
  54. return this.withSeparableConvs ? DEFAULT_MODEL_NAME_SEPARABLE_CONV : DEFAULT_MODEL_NAME;
  55. };
  56. TinyYolov2.prototype.extractParamsFromWeigthMap = function (weightMap) {
  57. return _super.prototype.extractParamsFromWeigthMap.call(this, weightMap);
  58. };
  59. return TinyYolov2;
  60. }(TinyYolov2Base));
  61. export { TinyYolov2 };
  62. //# sourceMappingURL=TinyYolov2.js.map