imgdnn.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. const imgdnn = {};
  2. imgdnn.ModelFactory = class {
  3. match(context) {
  4. const stream = context.stream;
  5. const signature = [ 0x49, 0x4d, 0x47, 0x44, 0x4e, 0x4e ]; // IMGDNN
  6. if (stream && stream.length >= signature.length && stream.peek(6).every((value, index) => value === signature[index])) {
  7. return 'imgdnn';
  8. }
  9. return null;
  10. }
  11. open(/* context */) {
  12. throw new imgdnn.Error('Invalid file content. File contains undocumented IMGDNN data.');
  13. }
  14. };
  15. imgdnn.Model = class {
  16. constructor(metadata, model) {
  17. this._format = 'IMGDNN';
  18. this._graphs = [ new imgdnn.Graph(metadata, model) ];
  19. }
  20. get format() {
  21. return this._format;
  22. }
  23. get graphs() {
  24. return this._graphs;
  25. }
  26. };
  27. imgdnn.Graph = class {
  28. constructor(/* metadata, model */) {
  29. this._inputs = [];
  30. this._outputs = [];
  31. this._nodes = [];
  32. }
  33. get inputs() {
  34. return this._inputs;
  35. }
  36. get outputs() {
  37. return this._outputs;
  38. }
  39. get nodes() {
  40. return this._nodes;
  41. }
  42. };
  43. imgdnn.Error = class extends Error {
  44. constructor(message) {
  45. super(message);
  46. this.name = 'Error loading IMGDNN model.';
  47. }
  48. };
  49. export const ModelFactory = imgdnn.ModelFactory;