config.js 1.5 KB

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