Lutz Roeder 5 лет назад
Родитель
Сommit
1a4b158017
2 измененных файлов с 32 добавлено и 1 удалено
  1. 28 0
      test/models.js
  2. 4 1
      test/models.json

+ 28 - 0
test/models.js

@@ -558,6 +558,34 @@ function loadModel(target, item) {
         if (item.runtime && model.runtime != item.runtime) {
             throw new Error("Invalid runtime '" + model.runtime + "'.");
         }
+        if (item.assert) {
+            for (const assert of item.assert) {
+                const parts = assert.split('=').map((item) => item.trim());
+                const properties = parts[0].split('.');
+                const value = parts[1];
+                let context = { model: model };
+                while (properties.length) {
+                    const property = properties.shift();
+                    if (context[property] !== undefined) {
+                        context = context[property];
+                        continue;
+                    }
+                    const match = /(.*)\[(.*)\]/.exec(property);
+                    if (match.length === 3 && context[match[1]] !== undefined) {
+                        const array = context[match[1]];
+                        const index = parseInt(match[2], 10);
+                        if (array[index] !== undefined) {
+                            context = array[index];
+                            continue;
+                        }
+                    }
+                    throw new Error("Invalid property path: '" + parts[0]);
+                }
+                if (context !== value.toString()) {
+                    throw new Error("Invalid '" + value.toString() + "' != '" + assert + "'.");
+                }
+            }
+        }
         model.version;
         model.description;
         model.author;

+ 4 - 1
test/models.json

@@ -3040,6 +3040,7 @@
     "target": "denotation_Add_ImageNet1920WithImageMetadataBgr8_SRGB_0_255.onnx",
     "source": "https://github.com/lutzroeder/netron/files/2587943/onnx_denotation_models.zip[denotation_Add_ImageNet1920WithImageMetadataBgr8_SRGB_0_255.onnx]",
     "format": "ONNX v3",
+    "assert": [ "model.graphs[0].nodes[0].outputs[0].arguments[0].type.denotation = Image(Bgr8,SRGB,NominalRange_0_255)" ],
     "link":   "https://github.com/lutzroeder/netron/issues/183"
   },
   {
@@ -5483,7 +5484,9 @@
     "type":   "tflite",
     "target": "densenet.tflite",
     "source": "https://storage.googleapis.com/download.tensorflow.org/models/tflite/model_zoo/upload_20180427/densenet_2018_04_27.tgz[densenet/densenet.tflite]",
-    "format": "TensorFlow Lite v3"
+    "format": "TensorFlow Lite v3",
+    "assert": [ "model.graphs[0].nodes[0].type=Conv2D" ],
+    "link":   "https://www.tensorflow.org/lite/guide/hosted_models"
   },
   {
     "type":   "tflite",