Parcourir la source

Rename context target to value

Lutz Roeder il y a 1 an
Parent
commit
db1d9bb999
65 fichiers modifiés avec 222 ajouts et 226 suppressions
  1. 2 2
      source/acuity.js
  2. 2 2
      source/armnn.js
  3. 2 1
      source/barracuda.js
  4. 1 1
      source/bigdl.js
  5. 3 3
      source/caffe.js
  6. 3 4
      source/caffe2.js
  7. 2 1
      source/catboost.js
  8. 3 3
      source/circle.js
  9. 2 2
      source/cntk.js
  10. 8 8
      source/coreml.js
  11. 3 3
      source/darknet.js
  12. 3 3
      source/dl4j.js
  13. 3 3
      source/dlc.js
  14. 1 1
      source/dnn.js
  15. 1 1
      source/dot.js
  16. 6 6
      source/espresso.js
  17. 6 6
      source/executorch.js
  18. 2 1
      source/flax.js
  19. 2 1
      source/flux.js
  20. 2 2
      source/gguf.js
  21. 2 2
      source/hailo.js
  22. 2 2
      source/hickle.js
  23. 2 2
      source/kann.js
  24. 16 16
      source/keras.js
  25. 3 3
      source/kmodel.js
  26. 2 2
      source/lasagne.js
  27. 3 3
      source/lightgbm.js
  28. 1 1
      source/mediapipe.js
  29. 4 4
      source/megengine.js
  30. 2 2
      source/message.js
  31. 2 2
      source/mlir.js
  32. 2 2
      source/mlnet.js
  33. 3 3
      source/mnn.js
  34. 2 2
      source/modular.js
  35. 2 2
      source/mslite.js
  36. 3 3
      source/mxnet.js
  37. 6 6
      source/ncnn.js
  38. 1 1
      source/nnabla.js
  39. 1 8
      source/nnc.js
  40. 3 3
      source/nnef.js
  41. 3 3
      source/numpy.js
  42. 3 3
      source/om.js
  43. 2 2
      source/onednn.js
  44. 2 2
      source/onnx.js
  45. 4 4
      source/openvino.js
  46. 11 11
      source/paddle.js
  47. 2 2
      source/pickle.js
  48. 2 2
      source/pytorch.js
  49. 5 5
      source/qnn.js
  50. 2 2
      source/rknn.js
  51. 4 4
      source/safetensors.js
  52. 1 1
      source/sentencepiece.js
  53. 4 4
      source/sklearn.js
  54. 3 3
      source/tengine.js
  55. 3 4
      source/tensorrt.js
  56. 17 17
      source/tf.js
  57. 4 4
      source/tflite.js
  58. 2 2
      source/tnn.js
  59. 2 2
      source/torch.js
  60. 3 3
      source/tvm.js
  61. 2 2
      source/uff.js
  62. 12 11
      source/view.js
  63. 2 2
      source/weka.js
  64. 1 1
      source/xmodel.js
  65. 7 7
      test/models.json

+ 2 - 2
source/acuity.js

@@ -6,14 +6,14 @@ acuity.ModelFactory = class {
     async match(context) {
         const obj = await context.peek('json');
         if (obj && obj.MetaData && obj.Layers) {
-            return context.match('acuity', obj);
+            return context.set('acuity', obj);
         }
         return null;
     }
 
     async open(context) {
         const metadata = await context.metadata('acuity-metadata.json');
-        return new acuity.Model(metadata, context.target);
+        return new acuity.Model(metadata, context.value);
     }
 };
 

+ 2 - 2
source/armnn.js

@@ -9,13 +9,13 @@ armnn.ModelFactory = class {
         if (extension === 'armnn') {
             const reader = await context.peek('flatbuffers.binary');
             if (reader) {
-                return context.match('armnn.flatbuffers', reader);
+                return context.set('armnn.flatbuffers', reader);
             }
         }
         if (extension === 'json') {
             const obj = await context.peek('json');
             if (obj && obj.layers && obj.inputIds && obj.outputIds) {
-                return context.match('armnn.flatbuffers.json', obj);
+                return context.set('armnn.flatbuffers.json', obj);
             }
         }
         return null;

+ 2 - 1
source/barracuda.js

@@ -10,9 +10,10 @@ barracuda.ModelFactory = class {
         if (stream && stream.length > 12) {
             const buffer = stream.peek(12);
             if (buffer[0] <= 0x20 && buffer.subarray(1, 8).every((value) => value === 0x00)) {
-                context.type = 'barracuda';
+                return context.set('barracuda');
             }
         }
+        return null;
     }
 
     async open(context) {

+ 1 - 1
source/bigdl.js

@@ -9,7 +9,7 @@ bigdl.ModelFactory = class {
         const tags = await context.tags('pb');
         if (tags.has(2) && tags.has(7) && tags.has(8) &&
             tags.has(9) && tags.has(10) && tags.has(11) && tags.has(12)) {
-            return context.match('bigdl');
+            return context.set('bigdl');
         }
         return null;
     }

+ 3 - 3
source/caffe.js

@@ -7,7 +7,7 @@ caffe.ModelFactory = class {
         const identifier = context.identifier;
         const extension = identifier.split('.').pop().toLowerCase();
         if (extension === 'caffemodel') {
-            return context.match('caffe.pb');
+            return context.set('caffe.pb');
         }
         if (identifier === 'saved_model.pbtxt' || identifier === 'saved_model.prototxt' ||
             identifier.endsWith('predict_net.pbtxt') || identifier.endsWith('predict_net.prototxt') ||
@@ -16,9 +16,9 @@ caffe.ModelFactory = class {
         }
         const tags = await context.tags('pbtxt');
         if (tags.has('layer') || tags.has('layers')) {
-            return context.match('caffe.pbtxt');
+            return context.set('caffe.pbtxt');
         } else if (tags.has('net') || tags.has('train_net') || tags.has('net_param')) {
-            return context.match('caffe.pbtxt.solver');
+            return context.set('caffe.pbtxt.solver');
         }
         return null;
     }

+ 3 - 4
source/caffe2.js

@@ -11,7 +11,7 @@ caffe2.ModelFactory = class {
             case 'prototxt': {
                 const tags = await context.tags('pbtxt');
                 if (tags.has('op') && !tags.has('op.attr') && !tags.has('op.graph_op_name') && !tags.has('op.endpoint')) {
-                    return context.match('caffe2.pbtxt');
+                    return context.set('caffe2.pbtxt');
                 }
                 break;
             }
@@ -35,12 +35,11 @@ caffe2.ModelFactory = class {
                                         buffer.length > 2 + size + 1 &&
                                         buffer.slice(2, 2 + size).every((c) => c >= 32 && c <= 127) &&
                                         buffer[2 + size] === 0x12) {
-                                        context.type = 'caffe2.pb';
+                                        return context.set('caffe2.pb');
                                     }
                                     break;
                                 case 0x12:
-                                    context.type = 'caffe2.pb';
-                                    break;
+                                    return context.set('caffe2.pb');
                                 default:
                                     break;
                             }

+ 2 - 1
source/catboost.js

@@ -11,9 +11,10 @@ catboost.ModelFactory = class {
             const buffer = stream.peek(4);
             const signature = Array.from(buffer).map((c) => String.fromCharCode(c)).join('');
             if (signature === 'CBM1') {
-                context.type = 'catboost';
+                return context.set('catboost');
             }
         }
+        return null;
     }
 
     async open(context) {

+ 3 - 3
source/circle.js

@@ -10,11 +10,11 @@ circle.ModelFactory = class {
     async match(context) {
         const reader = await context.peek('flatbuffers.binary');
         if (reader && reader.identifier === 'CIR0') {
-            return context.match('circle.flatbuffers', reader);
+            return context.set('circle.flatbuffers', reader);
         }
         const obj = await context.peek('json');
         if (obj && obj.subgraphs && obj.operator_codes) {
-            return context.match('circle.flatbuffers.json', obj);
+            return context.set('circle.flatbuffers.json', obj);
         }
         return null;
     }
@@ -37,7 +37,7 @@ circle.ModelFactory = class {
             }
             case 'circle.flatbuffers': {
                 try {
-                    const reader = context.target;
+                    const reader = context.value;
                     model = circle.schema.Model.create(reader);
                 } catch (error) {
                     const message = error && error.message ? error.message : error.toString();

+ 2 - 2
source/cntk.js

@@ -8,12 +8,12 @@ cntk.ModelFactory = class {
         // CNTK v1
         const signature = [0x42, 0x00, 0x43, 0x00, 0x4e, 0x00, 0x00, 0x00];
         if (stream && signature.length <= stream.length && stream.peek(signature.length).every((value, index) => value === signature[index])) {
-            return context.match('cntk.v1');
+            return context.set('cntk.v1');
         }
         // CNTK v2
         const tags = await context.tags('pb');
         if (tags.get(1) === 0 && tags.get(2) === 2) {
-            return context.match('cntk.v2');
+            return context.set('cntk.v2');
         }
         return null;
     }

+ 8 - 8
source/coreml.js

@@ -19,12 +19,12 @@ coreml.ModelFactory = class {
             if (extension === 'pb' && Array.from(tags.keys()).every((key) => !match(key))) {
                 return null;
             }
-            return context.match('coreml.pb');
+            return context.set('coreml.pb');
         }
         if (extension === 'pbtxt') {
             const tags = await context.tags('pbtxt');
             if (tags.has('specificationVersion') && tags.has('description')) {
-                return context.match('coreml.pbtxt');
+                return context.set('coreml.pbtxt');
             }
         }
         if (identifier === 'manifest.json') {
@@ -32,7 +32,7 @@ coreml.ModelFactory = class {
             if (obj && obj.rootModelIdentifier && obj.itemInfoEntries) {
                 const entries = Object.keys(obj.itemInfoEntries).map((key) => obj.itemInfoEntries[key]);
                 if (entries.filter((entry) => entry.path.toLowerCase().endsWith('.mlmodel').length === 1)) {
-                    return context.match('coreml.manifest');
+                    return context.set('coreml.manifest');
                 }
             }
         }
@@ -41,7 +41,7 @@ coreml.ModelFactory = class {
                 const reader = await context.read('text', 2048);
                 const signature = reader.read('\n');
                 if (signature && signature.trim().startsWith('program')) {
-                    return context.match('coreml.mil');
+                    return context.set('coreml.mil');
                 }
             } catch {
                 // continue regardless of error
@@ -50,16 +50,16 @@ coreml.ModelFactory = class {
         if (identifier === 'featuredescriptions.json') {
             const obj = await context.peek('json');
             if (obj && (obj.Inputs || obj.Outputs)) {
-                return context.match('coreml.featuredescriptions');
+                return context.set('coreml.featuredescriptions');
             }
         }
         if (identifier === 'metadata.json') {
             const obj = await context.peek('json');
             if (obj && obj.rootModelIdentifier && obj.itemInfoEntries) {
-                return context.match('coreml.metadata');
+                return context.set('coreml.metadata');
             }
             if (Array.isArray(obj) && obj.some((item) => item && item.metadataOutputVersion && item.specificationVersion)) {
-                return context.match('coreml.metadata.mlmodelc');
+                return context.set('coreml.metadata.mlmodelc');
             }
         }
         if (extension === 'bin' && stream.length > 16) {
@@ -67,7 +67,7 @@ coreml.ModelFactory = class {
             for (let i = 0; i < buffer.length - 4; i++) {
                 const signature = (buffer[i] | buffer[i + 1] << 8 | buffer[i + 2] << 16 | buffer [i + 3] << 24) >>> 0;
                 if (signature === 0xdeadbeef) {
-                    return context.match('coreml.weights');
+                    return context.set('coreml.weights');
                 }
             }
         }

+ 3 - 3
source/darknet.js

@@ -9,7 +9,7 @@ darknet.ModelFactory = class {
         if (extension === 'weights' && !identifier.toLowerCase().endsWith('.espresso.weights')) {
             const weights = await darknet.Weights.open(context);
             if (weights) {
-                return context.match('darknet.weights', weights);
+                return context.set('darknet.weights', weights);
             }
             return null;
         }
@@ -20,7 +20,7 @@ darknet.ModelFactory = class {
                     const content = line.trim();
                     if (content.length > 0 && !content.startsWith('#')) {
                         if (content.startsWith('[') && content.endsWith(']')) {
-                            return context.match('darknet.model');
+                            return context.set('darknet.model');
                         }
                         return null;
                     }
@@ -40,7 +40,7 @@ darknet.ModelFactory = class {
         const basename = parts.join('.');
         switch (context.type) {
             case 'darknet.weights': {
-                const weights = context.target;
+                const weights = context.value;
                 const name = `${basename}.cfg`;
                 const content = await context.fetch(name);
                 const reader = await content.read('text');

+ 3 - 3
source/dl4j.js

@@ -10,13 +10,13 @@ dl4j.ModelFactory = class {
         if (identifier === 'configuration.json') {
             const obj = await context.peek('json');
             if (obj && (obj.confs || obj.vertices)) {
-                return context.match('dl4j.configuration', obj);
+                return context.set('dl4j.configuration', obj);
             }
         } else if (identifier === 'coefficients.bin') {
             const signature = [0x00, 0x07, 0x4A, 0x41, 0x56, 0x41, 0x43, 0x50, 0x50]; // JAVACPP
             const stream = context.stream;
             if (signature.length <= stream.length && stream.peek(signature.length).every((value, index) => value === signature[index])) {
-                return context.match('dl4j.coefficients');
+                return context.set('dl4j.coefficients');
             }
         }
         return null;
@@ -30,7 +30,7 @@ dl4j.ModelFactory = class {
         const metadata = await context.metadata('dl4j-metadata.json');
         switch (context.type) {
             case 'dl4j.configuration': {
-                const obj = context.target;
+                const obj = context.value;
                 try {
                     const content = await context.fetch('coefficients.bin');
                     const reader = await content.read('binary.big-endian');

+ 3 - 3
source/dlc.js

@@ -9,7 +9,7 @@ dlc.ModelFactory = class {
     async match(context) {
         const container = await dlc.Container.open(context);
         if (container) {
-            return context.match('dlc', container);
+            return context.set('dlc', container);
         }
         return null;
     }
@@ -17,9 +17,9 @@ dlc.ModelFactory = class {
     async open(context) {
         dlc.schema = await context.require('./dlc-schema');
         dlc.schema = dlc.schema.dlc;
-        await context.target.read();
+        await context.value.read();
         const metadata = await context.metadata('dlc-metadata.json');
-        return new dlc.Model(metadata, context.target);
+        return new dlc.Model(metadata, context.value);
     }
 };
 

+ 1 - 1
source/dnn.js

@@ -8,7 +8,7 @@ dnn.ModelFactory = class {
     async match(context) {
         const tags = await context.tags('pb');
         if (tags.get(4) === 0 && tags.get(10) === 2) {
-            return context.match('dnn');
+            return context.set('dnn');
         }
         return null;
     }

+ 1 - 1
source/dot.js

@@ -16,7 +16,7 @@ dot.ModelFactory = class {
                         continue;
                     }
                     if (line.trim().match(/^(strict)?\s*digraph/)) {
-                        return context.match('dot');
+                        return context.set('dot');
                     }
                 }
             } catch {

+ 6 - 6
source/espresso.js

@@ -8,18 +8,18 @@ espresso.ModelFactory = class {
         if (identifier.endsWith('.espresso.net')) {
             const obj = await context.peek('json');
             if (obj && Array.isArray(obj.layers) && obj.format_version) {
-                return context.match('espresso.net', obj);
+                return context.set('espresso.net', obj);
             }
         }
         if (identifier.endsWith('.espresso.shape')) {
             const obj = await context.peek('json');
             if (obj && obj.layer_shapes) {
-                return context.match('espresso.shape', obj);
+                return context.set('espresso.shape', obj);
             }
         }
         if (identifier.endsWith('.espresso.weights')) {
             const target = await context.read('binary');
-            return context.match('espresso.weights', target);
+            return context.set('espresso.weights', target);
         }
         return null;
     }
@@ -38,17 +38,17 @@ espresso.ModelFactory = class {
         const metadata = await context.metadata('espresso-metadata.json');
         switch (context.type) {
             case 'espresso.net': {
-                const reader = new espresso.Reader(context.target, null, null);
+                const reader = new espresso.Reader(context.value, null, null);
                 await reader.read(context);
                 return new espresso.Model(metadata, reader);
             }
             case 'espresso.weights': {
-                const reader = new espresso.Reader(null, context.target, null);
+                const reader = new espresso.Reader(null, context.value, null);
                 await reader.read(context);
                 return new espresso.Model(metadata, reader);
             }
             case 'espresso.shape': {
-                const reader = new espresso.Reader(null, null, context.target);
+                const reader = new espresso.Reader(null, null, context.value);
                 await reader.read(context);
                 return new espresso.Model(metadata, reader);
             }

+ 6 - 6
source/executorch.js

@@ -15,14 +15,14 @@ executorch.ModelFactory = class {
     async match(context) {
         const reader = await executorch.Reader.open(context);
         if (reader) {
-            return context.match('executorch', reader);
+            return context.set('executorch', reader);
         }
         return null;
     }
 
     async open(context) {
         executorch.schema = await context.require('./executorch-schema');
-        const target = context.target;
+        const target = context.value;
         await target.read();
         return new executorch.Model(target);
     }
@@ -862,9 +862,9 @@ coreml.Reader = class {
             const locals = new Map(Array.from(entries).filter(([key]) => key.startsWith(folder)).map(([key, value]) => [key.substring(folder.length), value]));
             const context = new coreml.Context(this, identifier, value, locals, protobuf);
             /* eslint-disable no-await-in-loop */
-            await factory.match(context);
+            const type = await factory.match(context);
             /* eslint-enable no-await-in-loop */
-            if (context.type === 'coreml.manifest') {
+            if (type === 'coreml.manifest') {
                 /* eslint-disable no-await-in-loop */
                 const model = await factory.open(context);
                 /* eslint-enable no-await-in-loop */
@@ -988,9 +988,9 @@ coreml.Context = class {
         return this._reader.target.context.metadata(name);
     }
 
-    match(type, target) {
+    set(type, value) {
         this.type = type;
-        this.target = target;
+        this.value = value;
         return type;
     }
 };

+ 2 - 1
source/flax.js

@@ -12,9 +12,10 @@ flax.ModelFactory = class {
         if (stream.length > 4) {
             const buffer = stream.peek(1);
             if (buffer[0] === 0xDE || buffer[0] === 0xDF || ((buffer[0] & 0x80) === 0x80)) {
-                context.type = 'flax.msgpack.map';
+                return context.set('flax.msgpack.map');
             }
         }
+        return null;
     }
 
     async open(context) {

+ 2 - 1
source/flux.js

@@ -10,8 +10,9 @@ flux.ModelFactory = class {
         const extension = identifier.split('.').pop().toLowerCase();
         const stream = context.stream;
         if (stream && extension === 'bson') {
-            context.type = 'flux.bson';
+            return context.set('flux.bson');
         }
+        return null;
     }
 
     async open(context) {

+ 2 - 2
source/gguf.js

@@ -6,13 +6,13 @@ gguf.ModelFactory = class {
     async match(context) {
         const reader = gguf.Reader.open(context);
         if (reader) {
-            return context.match('gguf', reader);
+            return context.set('gguf', reader);
         }
         return null;
     }
 
     async open(context) {
-        const target = context.target;
+        const target = context.value;
         await target.read();
         return new gguf.Model(target);
     }

+ 2 - 2
source/hailo.js

@@ -7,7 +7,7 @@ hailo.ModelFactory = class {
     async match(context) {
         const container = await hailo.Container.open(context);
         if (container) {
-            return context.match(container.type, container);
+            return context.set(container.type, container);
         }
         return null;
     }
@@ -24,7 +24,7 @@ hailo.ModelFactory = class {
 
     async open(context) {
         const metadata = await context.metadata('hailo-metadata.json');
-        const target = context.target;
+        const target = context.value;
         await target.read();
         return new hailo.Model(metadata, target);
     }

+ 2 - 2
source/hickle.js

@@ -6,13 +6,13 @@ hickle.ModelFactory = class {
     async match(context) {
         const group = await context.peek('hdf5');
         if (group && group.attributes && group.attributes.get('CLASS') === 'hickle') {
-            return context.match('hickle', group);
+            return context.set('hickle', group);
         }
         return null;
     }
 
     async open(context) {
-        return new hickle.Model(context.target);
+        return new hickle.Model(context.value);
     }
 };
 

+ 2 - 2
source/kann.js

@@ -6,7 +6,7 @@ kann.ModelFactory = class {
     async match(context) {
         const reader = await context.peek('flatbuffers.binary');
         if (reader && reader.identifier === 'KaNN') {
-            return context.match('kann.flatbuffers', reader);
+            return context.set('kann.flatbuffers', reader);
         }
         return null;
     }
@@ -18,7 +18,7 @@ kann.ModelFactory = class {
         switch (context.type) {
             case 'kann.flatbuffers': {
                 try {
-                    const reader = context.target;
+                    const reader = context.value;
                     model = kann.schema.Model.create(reader);
                 } catch (error) {
                     const message = error && error.message ? error.message : error.toString();

+ 16 - 16
source/keras.js

@@ -13,12 +13,12 @@ keras.ModelFactory = class {
         const group = await context.peek('hdf5');
         if (group && group.attributes && group.attributes.get('CLASS') !== 'hickle') {
             if (identifier === 'model.weights.h5') {
-                return context.match('keras.model.weights.h5', group);
+                return context.set('keras.model.weights.h5', group);
             }
             if (identifier === 'parameter.h5') {
-                return context.match('hdf5.parameter.h5', group);
+                return context.set('hdf5.parameter.h5', group);
             }
-            return context.match('keras.h5', group);
+            return context.set('keras.h5', group);
         }
         const json = await context.peek('json');
         if (json) {
@@ -26,27 +26,27 @@ keras.ModelFactory = class {
                 return null;
             }
             if (json.model_config || (json.class_name && json.config)) {
-                return context.match('keras.config.json', json);
+                return context.set('keras.config.json', json);
             }
             if (identifier === 'metadata.json' && json.keras_version) {
-                return context.match('keras.metadata.json', json);
+                return context.set('keras.metadata.json', json);
             }
         }
         const container = await tfjs.Container.open(context);
         if (container) {
-            return context.match('tfjs', container);
+            return context.set('tfjs', container);
         }
         const pickle = await context.peek('pkl');
         if (pickle && pickle.__class__ &&
             pickle.__class__.__module__ === 'keras.engine.sequential' &&
             pickle.__class__.__name__ === 'Sequential') {
-            return context.match('tfjs.pickle', pickle);
+            return context.set('tfjs.pickle', pickle);
         }
         // model.weights.npz
         const entries = await context.peek('npz');
         const regex = /^(__root__|layers\/.+|_layer_checkpoint_dependencies\/.+)\.npy$/;
         if (entries instanceof Map && entries.size > 0 && Array.from(entries).every(([name]) => regex.test(name))) {
-            return context.match('keras.model.weights.npz', entries);
+            return context.set('keras.model.weights.npz', entries);
         }
         // keras_metadata.pb
         if (extension === 'pb' && context.stream && context.stream.length > 16) {
@@ -56,7 +56,7 @@ keras.ModelFactory = class {
                 const buffer = stream.peek(Math.min(stream.length, 1024));
                 const content = String.fromCharCode.apply(null, buffer);
                 if (/root"/.test(content) && /\{\s*"class_name"\s*:/.test(content)) {
-                    return context.match('keras.pb.SavedMetadata');
+                    return context.set('keras.pb.SavedMetadata');
                 }
             }
         }
@@ -222,7 +222,7 @@ keras.ModelFactory = class {
         };
         switch (context.type) {
             case 'keras.config.json': {
-                const obj = context.target;
+                const obj = context.value;
                 const config = obj.model_config ? obj.model_config : obj;
                 const backend = obj.backend || '';
                 let version = obj.keras_version ? obj.keras_version : null;
@@ -238,7 +238,7 @@ keras.ModelFactory = class {
                 return open_model(format, '', backend, config, null);
             }
             case 'keras.model.weights.h5': {
-                const group = context.target;
+                const group = context.value;
                 const weights_store = read_weights_hdf5(group);
                 const metadata = await request_json(context, 'metadata.json');
                 let config = await request_json(context, 'config.json');
@@ -252,7 +252,7 @@ keras.ModelFactory = class {
                 return await open_model(format, '', '', config, null);
             }
             case 'keras.model.weights.npz': {
-                const entries = context.target;
+                const entries = context.value;
                 const weights_store = read_weights_numpy(entries);
                 const metadata = await request_json(context, 'metadata.json');
                 let config = await request_json(context, 'config.json');
@@ -266,7 +266,7 @@ keras.ModelFactory = class {
                 return await open_model(format, '', '', config, null);
             }
             case 'keras.metadata.json': {
-                const metadata = context.target;
+                const metadata = context.value;
                 let config = await request_json(context, 'config.json');
                 const name = config ? 'Keras' : 'Keras Weights';
                 const format = name + (metadata.keras_version ? ` v${metadata.keras_version}` : '');
@@ -317,7 +317,7 @@ keras.ModelFactory = class {
                     return null;
                 };
                 const weights = new keras.Weights();
-                const group = context.target;
+                const group = context.value;
                 const root_group = find_root_group(group);
                 const model_config = read_model_config(root_group);
                 if (model_config) {
@@ -452,12 +452,12 @@ keras.ModelFactory = class {
                 return open_model(format, '', '', null, weights);
             }
             case 'tfjs': {
-                const target = context.target;
+                const target = context.value;
                 await target.read();
                 return open_model(target.format, target.producer, target.backend, target.config, target.weights);
             }
             case 'keras.pickle': {
-                const obj = context.target;
+                const obj = context.value;
                 const execution = new python.Execution();
                 const decoder = new TextDecoder('utf-8');
                 const format = `Keras Pickle${obj.keras_version ? ` v${decoder.decode(obj.keras_version)}` : ''}`;

+ 3 - 3
source/kmodel.js

@@ -8,13 +8,13 @@ kmodel.ModelFactory = class {
     async match(context) {
         const reader = kmodel.Reader.open(context.stream);
         if (reader) {
-            context.type = 'kmodel';
-            context.target = reader;
+            return context.set('kmodel', reader);
         }
+        return null;
     }
 
     async open(context) {
-        const target = context.target;
+        const target = context.value;
         target.read();
         return new kmodel.Model(target);
     }

+ 2 - 2
source/lasagne.js

@@ -8,14 +8,14 @@ lasagne.ModelFactory = class {
     async match(context) {
         const obj = await context.peek('pkl');
         if (obj && obj.__class__ && obj.__class__.__module__ === 'nolearn.lasagne.base' && obj.__class__.__name__ === 'NeuralNet') {
-            return context.match('lasagne', obj);
+            return context.set('lasagne', obj);
         }
         return null;
     }
 
     async open(context) {
         const metadata = await context.metadata('lasagne-metadata.json');
-        return new lasagne.Model(metadata, context.target);
+        return new lasagne.Model(metadata, context.value);
     }
 };
 

+ 3 - 3
source/lightgbm.js

@@ -9,11 +9,11 @@ lightgbm.ModelFactory = class {
         const stream = context.stream;
         const signature = [0x74, 0x72, 0x65, 0x65, 0x0A];
         if (stream && stream.length >= signature.length && stream.peek(signature.length).every((value, index) => value === signature[index])) {
-            return context.match('lightgbm.text');
+            return context.set('lightgbm.text');
         }
         const obj = await context.peek('pkl');
         if (obj && obj.__class__ && obj.__class__.__module__ && obj.__class__.__module__.startsWith('lightgbm.')) {
-            return context.match('lightgbm.pickle', obj);
+            return context.set('lightgbm.pickle', obj);
         }
         return null;
     }
@@ -21,7 +21,7 @@ lightgbm.ModelFactory = class {
     async open(context) {
         switch (context.type) {
             case 'lightgbm.pickle': {
-                const obj = context.target;
+                const obj = context.value;
                 return new lightgbm.Model(obj, 'LightGBM Pickle');
             }
             case 'lightgbm.text': {

+ 1 - 1
source/mediapipe.js

@@ -8,7 +8,7 @@ mediapipe.ModelFactory = class {
     async match(context) {
         const tags = await context.tags('pbtxt');
         if (tags.has('node') && ['input_stream', 'output_stream', 'input_side_packet', 'output_side_packet'].some((key) => tags.has(key) || tags.has(`node.${key}`))) {
-            return context.match('mediapipe.pbtxt');
+            return context.set('mediapipe.pbtxt');
         }
         return null;
     }

+ 4 - 4
source/megengine.js

@@ -19,19 +19,19 @@ megengine.ModelFactory = class {
                 if (position > 0 || size === (stream.length - position - 4)) {
                     const reader = flatbuffers.BinaryReader.open(stream, position + 4);
                     if (reader.identifier === 'mgv2') {
-                        return context.match('megengine.mge', reader);
+                        return context.set('megengine.mge', reader);
                     }
                 }
             }
             for (const value of ['mgb0001', 'mgb0000a', 'MGBS', 'MGBC']) {
                 if (tag.startsWith(value)) {
-                    return context.match(`megengine.${value}`);
+                    return context.set(`megengine.${value}`);
                 }
             }
         }
         const obj = await context.peek('pkl');
         if (obj && obj.__class__ && obj.__class__.__module__ === 'megengine.traced_module.traced_module' && obj.__class__.__name__ === 'TracedModule') {
-            return context.match('megengine.tm');
+            return context.set('megengine.tm');
         }
         return null;
     }
@@ -48,7 +48,7 @@ megengine.ModelFactory = class {
                 megengine.schema = megengine.schema.mgb.serialization.fbs;
                 let model = null;
                 try {
-                    const reader = context.target;
+                    const reader = context.value;
                     model = megengine.schema.v2.Model.create(reader);
                 } catch (error) {
                     const message = error && error.message ? error.message : error.toString();

+ 2 - 2
source/message.js

@@ -14,7 +14,7 @@ message.ModelFactory = class {
             if (match && match[1].startsWith('netron:')) {
                 const obj = await context.peek('json');
                 if (obj && obj.signature && obj.signature.startsWith('netron:')) {
-                    return context.match('message', obj);
+                    return context.set('message', obj);
                 }
             }
         }
@@ -22,7 +22,7 @@ message.ModelFactory = class {
     }
 
     async open(context) {
-        return new message.Model(context.target);
+        return new message.Model(context.value);
     }
 };
 

+ 2 - 2
source/mlir.js

@@ -12,14 +12,14 @@ mlir.ModelFactory = class {
             const buffer = stream.peek(4);
             const signature = String.fromCharCode.apply(null, buffer);
             if (signature === 'ML\xEFR') {
-                return context.match('mlir.binary');
+                return context.set('mlir.binary');
             }
         }
         try {
             const reader = await context.read('text', 0x10000);
             for (let line = reader.read('\n'); line !== undefined; line = reader.read('\n')) {
                 if (/module\s+(\w+\s+)?{/.test(line) || /tensor<\w+>/.test(line) || /func\s*@\w+/.test(line)) {
-                    return context.match('mlir.text');
+                    return context.set('mlir.text');
                 }
             }
         } catch {

+ 2 - 2
source/mlnet.js

@@ -12,7 +12,7 @@ mlnet.ModelFactory = class {
         if (entries instanceof Map && entries.size > 0) {
             const root = new Set(['TransformerChain', 'Predictor']);
             if (Array.from(entries.keys()).some((name) => root.has(name.split('\\').shift().split('/').shift()))) {
-                return context.match('mlnet', entries);
+                return context.set('mlnet', entries);
             }
         }
         return null;
@@ -20,7 +20,7 @@ mlnet.ModelFactory = class {
 
     async open(context) {
         const metadata = await context.metadata('mlnet-metadata.json');
-        const reader = new mlnet.ModelReader(context.target);
+        const reader = new mlnet.ModelReader(context.value);
         return new mlnet.Model(metadata, reader);
     }
 };

+ 3 - 3
source/mnn.js

@@ -6,11 +6,11 @@ mnn.ModelFactory = class {
     async match(context) {
         const reader = await context.peek('flatbuffers.binary');
         if (reader) {
-            return context.match('mnn.flatbuffers', reader);
+            return context.set('mnn.flatbuffers', reader);
         }
         const obj = await context.peek('json');
         if (obj && obj.sourceType && Array.isArray(obj.oplists) && Array.isArray(obj.tensorName)) {
-            return context.match('mnn.flatbuffers.json', obj);
+            return context.set('mnn.flatbuffers.json', obj);
         }
         return null;
     }
@@ -22,7 +22,7 @@ mnn.ModelFactory = class {
         switch (context.type) {
             case 'mnn.flatbuffers': {
                 try {
-                    const reader = context.target;
+                    const reader = context.value;
                     net = mnn.schema.Net.create(reader);
                 } catch (error) {
                     const message = error && error.message ? error.message : error.toString();

+ 2 - 2
source/modular.js

@@ -6,13 +6,13 @@ modular.ModelFactory = class {
     async match(context) {
         const obj = await context.peek('json');
         if (obj && obj.signature === "netron:modular") {
-            return context.match('modular', obj);
+            return context.set('modular', obj);
         }
         return null;
     }
 
     async open(context) {
-        return new modular.Model(context.target);
+        return new modular.Model(context.value);
     }
 };
 

+ 2 - 2
source/mslite.js

@@ -9,14 +9,14 @@ mslite.ModelFactory = class {
         if (reader) {
             const identifier = reader.identifier;
             if (identifier === 'MSL1' || identifier === 'MSL2' || (identifier === '' && extension === 'ms')) {
-                return context.match('mslite', reader);
+                return context.set('mslite', reader);
             }
         }
         return null;
     }
 
     async open(context) {
-        const reader = context.target;
+        const reader = context.value;
         switch (reader.identifier) {
             case '': {
                 throw new mslite.Error('MSL0 format is deprecated.');

+ 3 - 3
source/mxnet.js

@@ -11,13 +11,13 @@ mxnet.ModelFactory = class {
         if (extension === 'json') {
             const obj = await context.peek('json');
             if (obj && Array.isArray(obj.nodes) && Array.isArray(obj.arg_nodes) && Array.isArray(obj.heads) && !obj.nodes.some((node) => node && node.op === 'tvm_op')) {
-                return context.match('mxnet.json', obj);
+                return context.set('mxnet.json', obj);
             }
         }
         const stream = context.stream;
         const signature = [0x12, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
         if (stream && stream.length > signature.length && stream.peek(signature.length).every((value, index) => value === signature[index])) {
-            return context.match('mxnet.params');
+            return context.set('mxnet.params');
         }
         return null;
     }
@@ -183,7 +183,7 @@ mxnet.ModelFactory = class {
             case 'mxnet.json': {
                 let symbol = null;
                 try {
-                    symbol = context.target;
+                    symbol = context.value;
                 } catch (error) {
                     const message = error && error.message ? error.message : error.toString();
                     throw new mxnet.Error(`Failed to load symbol entry (${message.replace(/\.$/, '')}).`);

+ 6 - 6
source/ncnn.js

@@ -19,7 +19,7 @@ ncnn.ModelFactory = class {
                 const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
                 const signature = view.getUint32(0, true);
                 if (signature === 0x007685dd) {
-                    return context.match('ncnn.model.bin');
+                    return context.set('ncnn.model.bin');
                 }
             }
         } else if (identifier.endsWith('.param') || identifier.endsWith('.cfg.ncnn')) {
@@ -56,15 +56,15 @@ ncnn.ModelFactory = class {
                     // continue regardless of error
                 }
                 if (type) {
-                    return context.match(type);
+                    return context.set(type);
                 }
             }
         } else if (identifier.endsWith('.ncnn.bin')) {
-            return context.match('ncnn.weights');
+            return context.set('ncnn.weights');
         } else if (identifier.endsWith('.pnnx.bin')) {
             const entries = await context.peek('zip');
             if (entries) { // can be empty
-                return context.match('pnnx.weights', entries);
+                return context.set('pnnx.weights', entries);
             }
         } else if (identifier.endsWith('.bin') || identifier.endsWith('.weights.ncnn')) {
             const stream = context.stream;
@@ -81,7 +81,7 @@ ncnn.ModelFactory = class {
                         f32[i] = view.getFloat32(i << 2, true);
                     }
                     if (f32.every((value) => !Number.isNaN(value) && Number.isFinite(value) && value > -20.0 && value < 20.0)) {
-                        return context.match('ncnn.weights');
+                        return context.set('ncnn.weights');
                     }
                 } else {
                     for (let i = 0; i < buffer.length - 4; i++) {
@@ -90,7 +90,7 @@ ncnn.ModelFactory = class {
                             return null;
                         }
                         if (signature === 0x01306b47 || signature === 0x000d4b38 || signature === 0x0002c056) { // ncnn
-                            return context.match('ncnn.weights');
+                            return context.set('ncnn.weights');
                         }
                     }
                 }

+ 1 - 1
source/nnabla.js

@@ -8,7 +8,7 @@ nnabla.ModelFactory = class {
         if (identifier.endsWith('.nntxt')) {
             const tags = await context.tags('pbtxt');
             if (tags.has('network')) {
-                return context.match('nnabla.pbtxt');
+                return context.set('nnabla.pbtxt');
             }
         }
         return null;

+ 1 - 8
source/nnc.js

@@ -4,14 +4,7 @@ const nnc = {};
 nnc.ModelFactory = class {
 
     async match(context) {
-        const stream = context.stream;
-        const signatures = [
-            [0xC0, 0x0F, 0x00, 0x00, 0x45, 0x4E, 0x4E, 0x43],
-            [0xBC, 0x0F, 0x00, 0x00, 0x45, 0x4E, 0x4E, 0x43],
-        ];
-        if (stream && stream.length >= 8 && signatures.some((signature) => stream.peek(signature.length).every((value, index) => value === signature[index]))) {
-            context.type = 'nnc';
-        }
+        return context.set('nnc');
     }
 
     async open(/* context */) {

+ 3 - 3
source/nnef.js

@@ -10,7 +10,7 @@ nnef.ModelFactory = class {
             case 'nnef': {
                 const reader = await nnef.TextReader.open(context);
                 if (reader) {
-                    return context.match('nnef.graph', reader);
+                    return context.set('nnef.graph', reader);
                 }
                 break;
             }
@@ -19,7 +19,7 @@ nnef.ModelFactory = class {
                 if (stream && stream.length > 2) {
                     const buffer = stream.peek(2);
                     if (buffer[0] === 0x4E && buffer[1] === 0xEF) {
-                        return context.match('nnef.dat', stream);
+                        return context.set('nnef.dat', stream);
                     }
                 }
                 break;
@@ -37,7 +37,7 @@ nnef.ModelFactory = class {
     async open(context) {
         switch (context.type) {
             case 'nnef.graph': {
-                const reader = context.target;
+                const reader = context.value;
                 throw new nnef.Error(`NNEF v${reader.version} support not implemented.`);
             }
             case 'nnef.dat': {

+ 3 - 3
source/numpy.js

@@ -11,11 +11,11 @@ numpy.ModelFactory = class {
         const stream = context.stream;
         const signature = [0x93, 0x4E, 0x55, 0x4D, 0x50, 0x59];
         if (stream && signature.length <= stream.length && stream.peek(signature.length).every((value, index) => value === signature[index])) {
-            return context.match('npy');
+            return context.set('npy');
         }
         const entries = await context.peek('npz');
         if (entries && entries.size > 0) {
-            return context.match('npz', entries);
+            return context.set('npz', entries);
         }
         return null;
     }
@@ -43,7 +43,7 @@ numpy.ModelFactory = class {
             case 'npz': {
                 format = 'NumPy Zip';
                 const layers = new Map();
-                const entries = Array.from(context.target);
+                const entries = Array.from(context.value);
                 const separator = entries.every(([name]) => name.endsWith('.weight.npy')) ? '.' : '/';
                 for (const [key, array] of entries) {
                     const name = key.replace(/\.npy$/, '');

+ 3 - 3
source/om.js

@@ -12,13 +12,13 @@ om.ModelFactory = class {
     async match(context) {
         const container = om.Container.open(context);
         if (container) {
-            context.type = 'om';
-            context.target = container;
+            return context.set('om', container);
         }
+        return null;
     }
 
     async open(context) {
-        const target = context.target;
+        const target = context.value;
         await target.read();
         const metadata = await context.metadata('om-metadata.json');
         return new om.Model(metadata, target);

+ 2 - 2
source/onednn.js

@@ -6,14 +6,14 @@ onednn.ModelFactory = class {
     async match(context) {
         const obj = await context.peek('json');
         if (obj && obj.version && obj.engine_kind && obj.fpmath_mode && obj.graph) {
-            return context.match('onednn', obj);
+            return context.set('onednn', obj);
         }
         return null;
     }
 
     async open(context) {
         const metadata = await context.metadata('onednn-metadata.json');
-        return new onednn.Model(metadata, context.target);
+        return new onednn.Model(metadata, context.value);
     }
 };
 

+ 2 - 2
source/onnx.js

@@ -25,7 +25,7 @@ onnx.ModelFactory = class {
                 const reader = await entry.open(context);
                 /* eslint-enable no-await-in-loop */
                 if (reader) {
-                    return context.match(reader.name, reader);
+                    return context.set(reader.name, reader);
                 }
             }
         }
@@ -33,7 +33,7 @@ onnx.ModelFactory = class {
     }
 
     async open(context) {
-        const target = context.target;
+        const target = context.value;
         await target.read();
         const metadata = await onnx.Metadata.open(context);
         return new onnx.Model(metadata, target);

+ 4 - 4
source/openvino.js

@@ -42,7 +42,7 @@ openvino.ModelFactory = class {
                     { identifier: 'text-recognition-0012.bin', signature: [0x0B, 0x21, 0xC6, 0xBC, 0xD0, 0xBB, 0xC1, 0x3B] },
                 ];
                 if (include.some((pattern) => match(pattern, identifier, buffer))) {
-                    return context.match('openvino.bin');
+                    return context.set('openvino.bin');
                 }
                 const exclude = [
                     { identifier: '__model__.bin' },
@@ -63,7 +63,7 @@ openvino.ModelFactory = class {
                 const size = Math.min(buffer.length & 0xfffffffc, 128);
                 buffer = buffer.subarray(0, size);
                 if (Array.from(buffer).every((value) => value === 0)) {
-                    return context.match('openvino.bin');
+                    return context.set('openvino.bin');
                 }
                 const f32 = new Array(buffer.length >> 2);
                 for (let i = 0; i < f32.length; i++) {
@@ -83,14 +83,14 @@ openvino.ModelFactory = class {
                 const validateInt = (array) => array.length > 32 &&
                     array.slice(0, 32).every((x) => x === 0 || x === 1 || x === 2 || x === 0x7fffffff);
                 if (validateFloat(f32) || validateFloat(f16) || validateInt(i32)) {
-                    return context.match('openvino.bin');
+                    return context.set('openvino.bin');
                 }
             }
             return null;
         }
         const tags = await context.tags('xml');
         if (tags.has('net')) {
-            return context.match('openvino.xml');
+            return context.set('openvino.xml');
         }
         return null;
     }

+ 11 - 11
source/paddle.js

@@ -14,34 +14,34 @@ paddle.ModelFactory = class {
         if (identifier === '__model__' || extension === '__model__' || extension === 'paddle' || extension === 'pdmodel') {
             const tags = await context.tags('pb');
             if (tags.get(1) === 2) {
-                return context.match('paddle.pb');
+                return context.set('paddle.pb');
             }
         }
         if (extension === 'pbtxt' || extension === 'txt') {
             const tags = await context.tags('pbtxt');
             if (tags.has('blocks')) {
-                return context.match('paddle.pbtxt');
+                return context.set('paddle.pbtxt');
             }
         }
         const stream = context.stream;
         if (stream && stream.length > 16 && stream.peek(16).every((value) => value === 0x00)) {
-            return context.match('paddle.params');
+            return context.set('paddle.params');
         }
         const pickle = await paddle.Pickle.open(context);
         if (pickle) {
-            return context.match(pickle.name, pickle);
+            return context.set(pickle.name, pickle);
         }
         const entries = await paddle.Entries.open(context);
         if (entries) {
-            return context.match(entries.name, entries);
+            return context.set(entries.name, entries);
         }
         const naive = await paddle.NaiveBuffer.open(context);
         if (naive) {
-            return context.match(naive.name, naive);
+            return context.set(naive.name, naive);
         }
         const obj = await context.peek('json');
         if (obj && obj.base_code && obj.program) {
-            return context.match('paddle.ir', obj);
+            return context.set('paddle.ir', obj);
         }
         return null;
     }
@@ -64,12 +64,12 @@ paddle.ModelFactory = class {
             case 'paddle.naive.param': {
                 paddle.schema = await context.require('./paddle-schema');
                 paddle.schema = paddle.schema.paddle.lite.fbs.proto;
-                const target = context.target;
+                const target = context.value;
                 target.read();
                 return new paddle.Model(metadata, target.format, target.model, target.weights);
             }
             case 'paddle.ir': {
-                const ir = new paddle.IR(context.target);
+                const ir = new paddle.IR(context.value);
                 const format = `PaddlePaddle IR v${ir.version}`;
                 return new paddle.Model(metadata, format, ir.desc, ir.tensors);
             }
@@ -165,11 +165,11 @@ paddle.ModelFactory = class {
                 };
                 switch (context.type) {
                     case 'paddle.pickle': {
-                        const target = context.target;
+                        const target = context.value;
                         return new paddle.Model(metadata, target.format, null, target.weights);
                     }
                     case 'paddle.entries': {
-                        const target = context.target;
+                        const target = context.value;
                         target.read();
                         return new paddle.Model(metadata, target.format, null, target.weights);
                     }

+ 2 - 2
source/pickle.js

@@ -16,7 +16,7 @@ pickle.ModelFactory = class {
         if (obj !== undefined) {
             const name = obj && obj.__class__ && obj.__class__.__module__ && obj.__class__.__name__ ? `${obj.__class__.__module__}.${obj.__class__.__name__}` : '';
             if (!name.startsWith('__torch__.')) {
-                return context.match('pickle', obj);
+                return context.set('pickle', obj);
             }
         }
         return null;
@@ -24,7 +24,7 @@ pickle.ModelFactory = class {
 
     async open(context) {
         let format = 'Pickle';
-        const obj = context.target;
+        const obj = context.value;
         if (obj === null || obj === undefined) {
             context.error(new pickle.Error("Unsupported Pickle null object."));
         } else if (obj instanceof Error) {

+ 2 - 2
source/pytorch.js

@@ -13,7 +13,7 @@ pytorch.ModelFactory = class {
     async match(context) {
         const container = await pytorch.Container.open(context);
         if (container) {
-            return context.match(container.type, container);
+            return context.set(container.type, container);
         }
         return null;
     }
@@ -36,7 +36,7 @@ pytorch.ModelFactory = class {
 
     async open(context) {
         const metadata = await pytorch.Metadata.open(context);
-        const target = context.target;
+        const target = context.value;
         target.on('resolve', (_, name) => {
             context.error(new pytorch.Error(`Unknown type name '${name}'.`), false);
         });

+ 5 - 5
source/qnn.js

@@ -8,11 +8,11 @@ qnn.ModelFactory = class {
     async match(context) {
         const obj = await context.peek('json');
         if (obj && obj['model.cpp'] && obj.graph) {
-            return context.match('qnn.json', obj);
+            return context.set('qnn.json', obj);
         }
         const entries = await context.peek('tar');
         if (entries && entries.size > 0 && Array.from(entries).every(([name]) => name.endsWith('.raw'))) {
-            return context.match('qnn.weights', entries);
+            return context.set('qnn.weights', entries);
         }
         const identifier = context.identifier.toLowerCase();
         if (identifier.endsWith('.bin') || identifier.endsWith('.serialized')) {
@@ -24,7 +24,7 @@ qnn.ModelFactory = class {
                 [0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01],
             ];
             if (stream.length >= 16 && signatures.some((signature) => stream.peek(signature.length).every((value, index) => value === signature[index]))) {
-                context.type = 'qnn.serialized';
+                return context.set('qnn.serialized');
             }
         }
         return null;
@@ -34,7 +34,7 @@ qnn.ModelFactory = class {
         const metadata = await context.metadata('qnn-metadata.json');
         switch (context.type) {
             case 'qnn.json': {
-                const obj = context.target;
+                const obj = context.value;
                 let weights = new Map();
                 try {
                     if (obj['model.bin']) {
@@ -48,7 +48,7 @@ qnn.ModelFactory = class {
                 return new qnn.Model(metadata, obj, weights);
             }
             case 'qnn.weights': {
-                const weights = context.target;
+                const weights = context.value;
                 const identifier = context.identifier;
                 const parts = identifier.split('.');
                 parts.pop();

+ 2 - 2
source/rknn.js

@@ -11,7 +11,7 @@ rknn.ModelFactory = class {
     async match(context) {
         const container = await rknn.Container.open(context);
         if (container) {
-            return context.match('rknn', container);
+            return context.set('rknn', container);
         }
         return null;
     }
@@ -20,7 +20,7 @@ rknn.ModelFactory = class {
         rknn.schema = await context.require('./rknn-schema');
         rknn.schema = rknn.schema.rknn;
         const metadata = await context.metadata('rknn-metadata.json');
-        const target = context.target;
+        const target = context.value;
         target.read();
         if (target.has('json')) {
             const buffer = target.get('json');

+ 4 - 4
source/safetensors.js

@@ -8,13 +8,13 @@ safetensors.ModelFactory = class {
     async match(context) {
         const container = safetensors.Container.open(context);
         if (container) {
-            return context.match('safetensors', container);
+            return context.set('safetensors', container);
         }
         const obj = await context.peek('json');
         if (obj && obj.weight_map) {
             const entries = Object.entries(obj.weight_map);
             if (entries.length > 0 && entries.every(([, value]) => typeof value === 'string' && value.endsWith('.safetensors'))) {
-                return context.match('safetensors.json', entries);
+                return context.set('safetensors.json', entries);
             }
         }
         return null;
@@ -23,12 +23,12 @@ safetensors.ModelFactory = class {
     async open(context) {
         switch (context.type) {
             case 'safetensors': {
-                const container = context.target;
+                const container = context.value;
                 await container.read();
                 return new safetensors.Model(container.entries);
             }
             case 'safetensors.json': {
-                const weight_map = new Map(context.target);
+                const weight_map = new Map(context.value);
                 const keys = new Set(weight_map.keys());
                 const files = Array.from(new Set(weight_map.values()));
                 const contexts = await Promise.all(files.map((name) => context.fetch(name)));

+ 1 - 1
source/sentencepiece.js

@@ -13,7 +13,7 @@ sentencepiece.ModelFactory = class {
                 model['1'] && model['1']['1'] === 2 && model['1']['2'] === 5 && model['1']['3'] === 0 &&
                 model['2'] && model['2']['3'] === 0 && model['2']['4'] === 0 &&
                 model['3'] && model['3']['1'] === 2) {
-                return context.match('sentencepiece');
+                return context.set('sentencepiece');
             }
         }
         return null;

+ 4 - 4
source/sklearn.js

@@ -23,15 +23,15 @@ sklearn.ModelFactory = class {
         ];
         for (const format of formats) {
             if (validate(obj, format.name)) {
-                return context.match(format.format, obj);
+                return context.set(format.format, obj);
             }
             if (Array.isArray(obj) && obj.length > 0 && obj.every((item) => validate(item, format.name))) {
-                return context.match(`${format.format}.list`, obj);
+                return context.set(`${format.format}.list`, obj);
             }
             if (Object(obj) === obj || obj instanceof Map) {
                 const entries = obj instanceof Map ? Array.from(obj) : Object.entries(obj);
                 if (entries.length > 0 && entries.every(([, value]) => validate(value, format.name))) {
-                    return context.match(`${format.format}.map`, obj);
+                    return context.set(`${format.format}.map`, obj);
                 }
             }
         }
@@ -40,7 +40,7 @@ sklearn.ModelFactory = class {
 
     async open(context) {
         const metadata = await context.metadata('sklearn-metadata.json');
-        return new sklearn.Model(metadata, context.type, context.target);
+        return new sklearn.Model(metadata, context.type, context.value);
     }
 };
 

+ 3 - 3
source/tengine.js

@@ -8,14 +8,14 @@ tengine.ModelFactory = class {
     async match(context) {
         const reader = tengine.Reader.open(context);
         if (reader) {
-            context.type = 'tengine';
-            context.target = reader;
+            return context.set('tengine', reader);
         }
+        return null;
     }
 
     async open(context) {
         const metadata = await tengine.Metadata.open(context);
-        const reader = context.target;
+        const reader = context.value;
         await reader.read();
         return new tengine.Model(metadata, reader);
     }

+ 3 - 4
source/tensorrt.js

@@ -13,15 +13,14 @@ tensorrt.ModelFactory = class {
         for (const entry of entries) {
             const target = entry.open(context);
             if (target) {
-                context.type = target.type;
-                context.target = target;
-                break;
+                return context.set(target.type, target);
             }
         }
+        return null;
     }
 
     async open(context) {
-        const target = context.target;
+        const target = context.value;
         await target.read();
         return new tensorrt.Model(null, target);
     }

+ 17 - 17
source/tf.js

@@ -22,13 +22,13 @@ tf.ModelFactory = class {
                 return null;
             }
             if (tags.has('saved_model_schema_version') || tags.has('meta_graphs')) {
-                return context.match('tf.pbtxt.SavedModel');
+                return context.set('tf.pbtxt.SavedModel');
             }
             if (tags.has('graph_def')) {
-                return context.match('tf.pbtxt.MetaGraphDef');
+                return context.set('tf.pbtxt.MetaGraphDef');
             }
             if (tags.has('node')) {
-                return context.match('tf.pbtxt.GraphDef');
+                return context.set('tf.pbtxt.GraphDef');
             }
         }
         if (extension === 'pb' || extension === 'pbtxt' || extension === 'prototxt' || extension === 'graphdef' || extension === 'meta') {
@@ -111,7 +111,7 @@ tf.ModelFactory = class {
                     if ((!tags.has(1) || tags.get(1) === 0) && tags.get(2) === 2) {
                         const tags = await context.tags('pb+');
                         if (match(tags, signatureSavedModel)) {
-                            return context.match('tf.pb.SavedModel');
+                            return context.set('tf.pb.SavedModel');
                         }
                     }
                     if ((!tags.has(1) || tags.get(1) === 2) &&
@@ -120,20 +120,20 @@ tf.ModelFactory = class {
                         (!tags.has(4) || tags.get(4) === 2)) {
                         const tags = await context.tags('pb+');
                         if (match(tags, signatureMetaGraphDef)) {
-                            return context.match('tf.pb.MetaGraphDef');
+                            return context.set('tf.pb.MetaGraphDef');
                         }
                     }
                     if (tags.get(1) !== 2) {
                         const tags = await context.tags('pb+');
                         if (match(tags, signatureGraphDef)) {
-                            return context.match('tf.pb.GraphDef');
+                            return context.set('tf.pb.GraphDef');
                         }
                     }
                     // tensorflow.FingerprintDef
                     if (identifier === 'fingerprint.pb' &&
                         tags.get(1) === 0 && tags.get(2) === 0 &&
                         tags.get(3) === 0 && tags.get(5) === 0 && tags.get(6) === 2) {
-                        return context.match('tf.pb.FingerprintDef');
+                        return context.set('tf.pb.FingerprintDef');
                     }
                     const decode = (buffer, value) => {
                         try {
@@ -162,7 +162,7 @@ tf.ModelFactory = class {
                             const decoder = new TextDecoder('utf-8');
                             const name = decoder.decode(nameBuffer);
                             if (Array.from(name).filter((c) => c <= ' ').length < 256) {
-                                return context.match('tf.pb.GraphDef');
+                                return context.set('tf.pb.GraphDef');
                             }
                         }
                     }
@@ -173,13 +173,13 @@ tf.ModelFactory = class {
                     return null;
                 }
                 if (tags.has('node')) {
-                    return context.match('tf.pbtxt.GraphDef');
+                    return context.set('tf.pbtxt.GraphDef');
                 }
                 if (tags.has('graph_def')) {
-                    return context.match('tf.pbtxt.MetaGraphDef');
+                    return context.set('tf.pbtxt.MetaGraphDef');
                 }
                 if (tags.has('saved_model_schema_version') || tags.has('meta_graphs')) {
-                    return context.match('tf.pbtxt.SavedModel');
+                    return context.set('tf.pbtxt.SavedModel');
                 }
             }
         }
@@ -189,7 +189,7 @@ tf.ModelFactory = class {
                 const obj = await context.peek(type);
                 /* eslint-enable no-await-in-loop */
                 if (obj && obj.modelTopology && (obj.format === 'graph-model' || Array.isArray(obj.modelTopology.node))) {
-                    return context.match(`tf.${type}`);
+                    return context.set(`tf.${type}`);
                 }
             }
         }
@@ -201,17 +201,17 @@ tf.ModelFactory = class {
                 stream.seek(0);
                 const signature = [0x57, 0xfb, 0x80, 0x8b, 0x24, 0x75, 0x47, 0xdb];
                 if (buffer.every((value, index) => value === signature[index])) {
-                    return context.match('tf.bundle');
+                    return context.set('tf.bundle');
                 }
             }
         }
         if (/.data-[0-9][0-9][0-9][0-9][0-9]-of-[0-9][0-9][0-9][0-9][0-9]$/.exec(identifier)) {
-            return context.match('tf.data');
+            return context.set('tf.data');
         }
         if (/^events.out.tfevents./.exec(identifier)) {
             const stream = context.stream;
             if (tf.EventFileReader.open(stream)) {
-                return context.match('tf.events');
+                return context.set('tf.events');
             }
         }
         if (extension === 'pbmm') {
@@ -223,12 +223,12 @@ tf.ModelFactory = class {
                 const reader = base.BinaryReader.open(buffer);
                 const offset = reader.uint64().toNumber();
                 if (offset < stream.length) {
-                    return context.match('tf.pb.mmap');
+                    return context.set('tf.pb.mmap');
                 }
             }
         }
         if (/^.*group\d+-shard\d+of\d+(\.bin)?$/.test(identifier)) {
-            return context.match('tf.tfjs.weights');
+            return context.set('tf.tfjs.weights');
         }
         return null;
     }

+ 4 - 4
source/tflite.js

@@ -10,19 +10,19 @@ tflite.ModelFactory = class {
     async match(context) {
         const reader = await context.peek('flatbuffers.binary');
         if (reader && reader.identifier === 'TFL3') {
-            return context.match('tflite.flatbuffers', reader);
+            return context.set('tflite.flatbuffers', reader);
         }
         const identifier = context.identifier;
         const extension = identifier.split('.').pop().toLowerCase();
         if (extension === 'tflite' && reader && reader.identifier === '') {
             const version = reader.uint32_(reader.root, 4, 0);
             if (version === 3) {
-                return context.match('tflite.flatbuffers', reader);
+                return context.set('tflite.flatbuffers', reader);
             }
         }
         const obj = await context.peek('json');
         if (obj && obj.subgraphs && obj.operator_codes) {
-            return context.match('tflite.flatbuffers.json', obj);
+            return context.set('tflite.flatbuffers.json', obj);
         }
         return null;
     }
@@ -45,7 +45,7 @@ tflite.ModelFactory = class {
             }
             case 'tflite.flatbuffers': {
                 try {
-                    const reader = context.target;
+                    const reader = context.value;
                     model = tflite.schema.Model.create(reader);
                 } catch (error) {
                     const message = error && error.message ? error.message : error.toString();

+ 2 - 2
source/tnn.js

@@ -15,7 +15,7 @@ tnn.ModelFactory = class {
                     if (line.startsWith('"') && line.endsWith('"')) {
                         const header = line.replace(/(^")|("$)/g, '').split(',').shift().trim().split(' ');
                         if (header.length === 3 || (header.length >= 4 && (header[3] === '4206624770' || header[3] === '4206624772'))) {
-                            return context.match('tnn.model');
+                            return context.set('tnn.model');
                         }
                     }
                 }
@@ -26,7 +26,7 @@ tnn.ModelFactory = class {
         if (stream && identifier.endsWith('.tnnmodel')) {
             for (const signature of [[0x02, 0x00, 0xbc, 0xfa], [0x04, 0x00, 0xbc, 0xfa]]) {
                 if (signature.length <= stream.length && stream.peek(signature.length).every((value, index) => value === signature[index])) {
-                    return context.match('tnn.params');
+                    return context.set('tnn.params');
                 }
             }
         }

+ 2 - 2
source/torch.js

@@ -8,14 +8,14 @@ torch.ModelFactory = class {
     async match(context) {
         const reader = torch.T7Reader.open(context);
         if (reader) {
-            return context.match('torch', reader);
+            return context.set('torch', reader);
         }
         return null;
     }
 
     async open(context) {
         const metadata = await context.metadata('torch-metadata.json');
-        const reader = context.target;
+        const reader = context.value;
         reader.callback = (name) => {
             if (name && name !== 'nn.JointTrainModule' && !name.startsWith('nn.MSDNet_') && !name.startsWith('onmt.')) {
                 context.error(new torch.Error(`Unsupported type '${name}'.`));

+ 3 - 3
source/tvm.js

@@ -10,13 +10,13 @@ tvm.ModelFactory = class {
             const obj = await context.peek('json');
             if (obj && Array.isArray(obj.nodes) && Array.isArray(obj.arg_nodes) && Array.isArray(obj.heads) &&
                 obj.nodes.every((node) => node && (node.op === 'null' || node.op === 'tvm_op'))) {
-                return context.match('tvm.json');
+                return context.set('tvm.json');
             }
         }
         const stream = context.stream;
         const signature = [0xB7, 0x9C, 0x04, 0x05, 0x4F, 0x8D, 0xE5, 0xF7];
         if (stream && signature.length <= stream.length && stream.peek(signature.length).every((value, index) => value === signature[index])) {
-            return context.match('tvm.params');
+            return context.set('tvm.params');
         }
         return null;
     }
@@ -31,7 +31,7 @@ tvm.ModelFactory = class {
         let params = null;
         switch (context.type) {
             case 'tvm.json': {
-                obj = context.target;
+                obj = context.value;
                 const identifier = context.identifier.replace(/\.json$/, '.params');
                 try {
                     const content = await context.fetch(identifier);

+ 2 - 2
source/uff.js

@@ -14,12 +14,12 @@ uff.ModelFactory = class {
                 tags.has(3) && tags.get(3) === 2 &&
                 tags.has(4) && tags.get(4) === 2 &&
                 (!tags.has(5) || tags.get(5) === 2)) {
-                return context.match('uff.pb');
+                return context.set('uff.pb');
             }
         } else if (extension === 'pbtxt' || identifier.toLowerCase().endsWith('.uff.txt')) {
             const tags = await context.tags('pbtxt');
             if (tags.has('version') && tags.has('descriptors') && tags.has('graphs')) {
-                context.match('uff.pbtxt');
+                return context.set('uff.pbtxt');
             }
         }
         return null;

+ 12 - 11
source/view.js

@@ -5354,9 +5354,9 @@ view.Context = class {
         this._context.error(error, fatal);
     }
 
-    match(type, target) {
+    set(type, value) {
         this.type = type;
-        this.target = target;
+        this.value = value;
         return type;
     }
 
@@ -5866,7 +5866,6 @@ view.ModelFactoryService = class {
         this.register('./mlir', ['.mlir', '.mlir.txt', '.mlirbc']);
         this.register('./sentencepiece', ['.model']);
         this.register('./hailo', ['.hn', '.har', '.metadata.json']);
-        this.register('./nnc', ['.nnc','.tflite']);
         this.register('./safetensors', ['.safetensors', '.safetensors.index.json']);
         this.register('./tvm', ['.json', '.params']);
         this.register('./dot', ['.dot'], [], [/^\s*(\/\*[\s\S]*?\*\/|\/\/.*|#.*)?\s*digraph\s*([A-Za-z][A-Za-z0-9-_]*|".*?")?\s*{/m]);
@@ -5874,7 +5873,7 @@ view.ModelFactoryService = class {
         this.register('./weka', ['.model']);
         this.register('./qnn', ['.json', '.bin', '.serialized']);
         this.register('./kann', ['.kann', '.bin', '.kgraph']);
-        this.register('', ['.cambricon', '.vnnmodel']);
+        this.register('', ['.cambricon', '.vnnmodel', '.nnc']);
         /* eslint-enable no-control-regex */
     }
 
@@ -6219,12 +6218,12 @@ view.ModelFactoryService = class {
         for (const module of modules) {
             /* eslint-disable no-await-in-loop */
             const factory = await this._require(module);
-            await factory.match(context);
+            const type = await factory.match(context);
             /* eslint-enable no-await-in-loop */
             if (context.stream && context.stream.position !== 0) {
                 throw new view.Error('Invalid stream position.');
             }
-            if (context.type) {
+            if (type) {
                 try {
                     /* eslint-disable no-await-in-loop */
                     const model = await factory.open(context);
@@ -6235,7 +6234,7 @@ view.ModelFactoryService = class {
                     return model;
                 } catch (error) {
                     delete context.type;
-                    delete context.target;
+                    delete context.value;
                     const stream = context.stream;
                     if (stream && stream.position !== 0) {
                         stream.seek(0);
@@ -6281,13 +6280,13 @@ view.ModelFactoryService = class {
                     for (const module of modules) {
                         /* eslint-disable no-await-in-loop */
                         const factory = await this._require(module);
-                        await factory.match(context);
+                        const type = await factory.match(context);
                         /* eslint-enable no-await-in-loop */
                         if (context.stream && context.stream.position !== 0) {
                             throw new view.Error('Invalid stream position.');
                         }
-                        delete context.target;
-                        if (context.type) {
+                        delete context.value;
+                        if (type) {
                             matches = matches.filter((match) => !factory.filter || factory.filter(context, match.type));
                             if (matches.every((match) => !match.factory.filter || match.factory.filter(match, context.type))) {
                                 context.factory = factory;
@@ -6414,7 +6413,9 @@ view.ModelFactoryService = class {
                 { name: 'XGBoost model', value: /^binf/ }, // https://github.com/dmlc/xgboost/blob/master/src/learner.cc
                 { name: 'XGBoost model', value: /^bs64/ }, // https://github.com/dmlc/xgboost/blob/master/src/learner.cc
                 { name: 'SQLite data', value: /^SQLite format/ },
-                { name: 'Optimium model', value: /^EZMODEL/ }, // https://github.com/EZ-Optimium/Optimium
+                { name: 'Optimium model', value: /^EZMODEL/ }, // https://github.com/EZ-Optimium/Optimium,
+                { name: 'undocumented NNC data', value: /^\xC0\x0F\x00\x00ENNC/ },
+                { name: 'undocumented NNC data', value: /^\xBC\x0F\x00\x00ENNC/ }
             ];
             /* eslint-enable no-control-regex */
             const buffer = stream.peek(Math.min(4096, stream.length));

+ 2 - 2
source/weka.js

@@ -15,7 +15,7 @@ weka.ModelFactory = class {
                     const reader = new java.io.InputObjectStream(stream);
                     const obj = reader.read();
                     if (obj && obj.$class && obj.$class.name) {
-                        return context.match('weka', obj);
+                        return context.set('weka', obj);
                     }
                 }
             }
@@ -26,7 +26,7 @@ weka.ModelFactory = class {
     }
 
     async open(context) {
-        const obj = context.target;
+        const obj = context.value;
         throw new weka.Error(`Unsupported type '${obj.$class.name}'.`);
     }
 };

+ 1 - 1
source/xmodel.js

@@ -6,7 +6,7 @@ xmodel.ModelFactory = class {
     async match(context) {
         const tags = await context.tags('pb');
         if (tags.get(5) === 2) {
-            return context.match('xmodel.pb');
+            return context.set('xmodel.pb');
         }
         return null;
     }

+ 7 - 7
test/models.json

@@ -180,6 +180,13 @@
     "error":    "Invalid file content. File contains Tokenizers data.",
     "link":     "https://github.com/lutzroeder/netron/issues/458"
   },
+  {
+    "type":     "_",
+    "target":   "sm_uint8_fence.nnc",
+    "source":   "https://github.com/lutzroeder/netron/files/12446059/sm_uint8_fence.nnc.zip[sm_uint8_fence.nnc]",
+    "error":    "Invalid file content. File contains undocumented NNC data.",
+    "link":     "https://github.com/lutzroeder/netron/issues/1144"
+  },
   {
     "type":     "_",
     "target":   "SR_face_x3_530x530.cambricon",
@@ -3919,13 +3926,6 @@
     "error":    "NNEF v1.0 support not implemented.",
     "link":     "https://github.com/lutzroeder/netron/issues/1274"
   },
-  {
-    "type":     "nnc",
-    "target":   "sm_uint8_fence.nnc",
-    "source":   "https://github.com/lutzroeder/netron/files/12446059/sm_uint8_fence.nnc.zip[sm_uint8_fence.nnc]",
-    "error":    "File contains undocumented NNC data.",
-    "link":     "https://github.com/lutzroeder/netron/issues/1144"
-  },
   {
     "type":     "numpy",
     "target":   "complex128.npy",