config.js 1.6 KB

12345678910111213141516171819202122232425262728293031
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var isNumber = function (arg) { return typeof arg === 'number'; };
  4. function validateConfig(config) {
  5. if (!config) {
  6. throw new Error("invalid config: " + config);
  7. }
  8. if (typeof config.withSeparableConvs !== 'boolean') {
  9. throw new Error("config.withSeparableConvs has to be a boolean, have: " + config.withSeparableConvs);
  10. }
  11. if (!isNumber(config.iouThreshold) || config.iouThreshold < 0 || config.iouThreshold > 1.0) {
  12. throw new Error("config.iouThreshold has to be a number between [0, 1], have: " + config.iouThreshold);
  13. }
  14. if (!Array.isArray(config.classes)
  15. || !config.classes.length
  16. || !config.classes.every(function (c) { return typeof c === 'string'; })) {
  17. throw new Error("config.classes has to be an array class names: string[], have: " + JSON.stringify(config.classes));
  18. }
  19. if (!Array.isArray(config.anchors)
  20. || !config.anchors.length
  21. || !config.anchors.map(function (a) { return a || {}; }).every(function (a) { return isNumber(a.x) && isNumber(a.y); })) {
  22. throw new Error("config.anchors has to be an array of { x: number, y: number }, have: " + JSON.stringify(config.anchors));
  23. }
  24. if (config.meanRgb && (!Array.isArray(config.meanRgb)
  25. || config.meanRgb.length !== 3
  26. || !config.meanRgb.every(isNumber))) {
  27. throw new Error("config.meanRgb has to be an array of shape [number, number, number], have: " + JSON.stringify(config.meanRgb));
  28. }
  29. }
  30. exports.validateConfig = validateConfig;
  31. //# sourceMappingURL=config.js.map