imgdnn.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const imgdnn = {};
  2. imgdnn.ModelFactory = class {
  3. async 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.modules = [new imgdnn.Graph(metadata, model)];
  19. }
  20. };
  21. imgdnn.Graph = class {
  22. constructor(/* metadata, model */) {
  23. this.inputs = [];
  24. this.outputs = [];
  25. this.nodes = [];
  26. }
  27. };
  28. imgdnn.Error = class extends Error {
  29. constructor(message) {
  30. super(message);
  31. this.name = 'Error loading IMGDNN model.';
  32. }
  33. };
  34. export const ModelFactory = imgdnn.ModelFactory;