Lutz Roeder 4 лет назад
Родитель
Сommit
e217e668a8
3 измененных файлов с 84 добавлено и 22 удалено
  1. 15 0
      source/openvino-metadata.json
  2. 46 6
      source/openvino.js
  3. 23 16
      test/models.json

+ 15 - 0
source/openvino-metadata.json

@@ -530,6 +530,17 @@
         "type": "string"
       }
     ],
+    "inputs": [
+      {
+        "name": "inputs",
+        "list": true
+      }
+    ],
+    "outputs": [
+      {
+        "name": "output"
+      }
+    ],
     "support_level": "default"
   },
   {
@@ -1306,6 +1317,10 @@
         "name": "num_axes",
         "required": true,
         "type": "int32"
+      },
+      {
+        "name": "special_zero",
+        "type": "boolean"
       }
     ],
     "support_level": "default"

+ 46 - 6
source/openvino.js

@@ -125,8 +125,22 @@ openvino.Graph = class {
         this._outputs = [];
         this._arguments = {};
 
+        const layers = new Map(net.layers.map((entry) => [ entry.id, entry ]));
         for (const layer of this._const(net.layers, net.edges)) {
-            const inputs = layer.inputs.map((input) => this._argument(layer.id, layer.precision, input, net.edges));
+            const inputs = layer.inputs.map((input) => {
+                const to = layer.id + ':' + input.id;
+                if (net.edges[to]) {
+                    const output = net.edges[to] ? net.edges[to].split(':') : [];
+                    const outputLayerId = output[0];
+                    const outputId = output[1];
+                    const outputLayer = layers.get(outputLayerId);
+                    if (outputLayer && outputId) {
+                        const output = outputLayer.outputs.find((output) => output.id === outputId);
+                        input.precision = output.precision;
+                    }
+                }
+                return this._argument(layer.id, input.precision || layer.precision, input, net.edges);
+            });
             const outputs = layer.outputs.map((output) => this._argument(layer.id, output.precision || layer.precision, output, null));
             switch (layer.type) {
                 case 'Input': {
@@ -140,6 +154,11 @@ openvino.Graph = class {
                     this._inputs.push(new openvino.Parameter(name, outputs));
                     break;
                 }
+                case 'Parameter': {
+                    const name = layer.name || '';
+                    this._inputs.push(new openvino.Parameter(name, outputs));
+                    break;
+                }
                 default: {
                     this._nodes.push(new openvino.Node(this, metadata, bin, layer, inputs, outputs));
                     break;
@@ -478,14 +497,14 @@ openvino.Node = class {
         const precision = layer.precision;
         const schema = metadata.type(layer.type);
         for (let i = 0; i < inputs.length; ) {
-            const input = schema && schema.inputs && i < schema.inputs.length ? schema.inputs[i] : { name: i.toString() };
+            const input = schema && schema.inputs && i < schema.inputs.length ? schema.inputs[i] : inputs.length === 1 ? { name: 'input' } : { name: i.toString() };
             const count = input.list ? inputs.length - i : 1;
             const list = inputs.slice(i, i + count);
             this._inputs.push(new openvino.Parameter(input.name, list));
             i += count;
         }
         for (let i = 0; i < outputs.length; ) {
-            const output = schema && schema.outputs && i < schema.outputs.length ? schema.outputs[i] : { name: i.toString() };
+            const output = schema && schema.outputs && i < schema.outputs.length ? schema.outputs[i] : outputs.length === 1 ? { name: 'output' } : { name: i.toString() };
             const count = output.list ? outputs.length - i : 1;
             const list = outputs.slice(i, i + count);
             this._outputs.push(new openvino.Parameter(output.name, list));
@@ -660,10 +679,12 @@ openvino.Attribute = class {
                         switch (value) {
                             case '1':
                             case 'true':
+                            case 'True':
                                 this._value = true;
                                 break;
                             case '0':
                             case 'false':
+                            case 'False':
                                 this._value = false;
                                 break;
                         }
@@ -811,9 +832,26 @@ openvino.Tensor = class {
             return context;
         }
 
-        context.index = 0;
-        context.count = 0;
-        context.data = new DataView(this._data.buffer, this._data.byteOffset, this._data.byteLength);
+        switch(this._type.dataType) {
+            case 'float16':
+            case 'float32':
+            case 'int8':
+            case 'int16':
+            case 'int32':
+            case 'int64':
+            case 'uint8':
+            case 'uint16':
+            case 'uint32':
+            case 'uint64':
+                context.index = 0;
+                context.count = 0;
+                context.data = new DataView(this._data.buffer, this._data.byteOffset, this._data.byteLength);
+                break;
+            default:
+                context.state = 'Tensor data type is not implemented.';
+                break;
+        }
+
         context.dataType = this._type.dataType;
         context.shape = this._type.shape.dimensions;
 
@@ -936,11 +974,13 @@ openvino.TensorType = class {
             case 'f32':     this._dataType = 'float32'; break;
             case 'fp32':    this._dataType = 'float32'; break;
             case 'bf16':    this._dataType = 'bfloat16'; break;
+            case 'i4':      this._dataType = 'int4'; break;
             case 'i8':      this._dataType = 'int8'; break;
             case 'i16':     this._dataType = 'int16'; break;
             case 'i32':     this._dataType = 'int32'; break;
             case 'i64':     this._dataType = 'int64'; break;
             case 'u1':      this._dataType = 'boolean'; break;
+            case 'u4':      this._dataType = 'uint4'; break;
             case 'u8':      this._dataType = 'uint8'; break;
             case 'u16':     this._dataType = 'uint16'; break;
             case 'u32':     this._dataType = 'uint32'; break;

+ 23 - 16
test/models.json

@@ -3825,6 +3825,13 @@
     "format": "OpenVINO IR",
     "link":   "https://download.01.org/opencv"
   },
+  {
+    "type":   "openvino",
+    "target": "int4-model.xml,int4-model.bin",
+    "source": "https://github.com/lutzroeder/netron/files/6273773/int4-model.zip[int4-model.xml,int4-model.bin]",
+    "format": "OpenVINO IR",
+    "link":   "https://github.com/lutzroeder/netron/pull/715"
+  },
   {
     "type":   "openvino",
     "target": "netron_issue_372.xml",
@@ -3848,45 +3855,45 @@
   },
   {
     "type":   "openvino",
-    "target": "with_pad_simple.xml",
-    "source": "https://github.com/lutzroeder/netron/files/2871673/with_pad_simple.xml.zip[with_pad_simple.xml]",
+    "target": "text-recognition-0012.xml,text-recognition-0012.bin",
+    "source": "https://download.01.org/opencv/2020/openvinotoolkit/2020.2/open_model_zoo/models_bin/3/text-recognition-0012/FP16-INT8/text-recognition-0012.xml,https://download.01.org/opencv/2020/openvinotoolkit/2020.2/open_model_zoo/models_bin/3/text-recognition-0012/FP16-INT8/text-recognition-0012.bin",
     "format": "OpenVINO IR",
-    "link":   "https://download.01.org/openvinotoolkit"
+    "link":   "https://download.01.org/opencv/2020/openvinotoolkit/2020.2/open_model_zoo/models_bin/3/text-recognition-0012/FP16-INT8"
   },
   {
     "type":   "openvino",
-    "target": "with_nd_conv_simple.xml",
-    "source": "https://github.com/lutzroeder/netron/files/2871696/with_nd_conv_simple.xml.zip[with_nd_conv_simple.xml]",
+    "target": "text-spotting-0002-recognizer-decoder.xml,text-spotting-0002-recognizer-decoder.bin",
+    "source": "https://download.01.org/opencv/2020/openvinotoolkit/2020.2/open_model_zoo/models_bin/3/text-spotting-0002-recognizer-decoder/FP32/text-spotting-0002-recognizer-decoder.xml,https://download.01.org/opencv/2020/openvinotoolkit/2020.2/open_model_zoo/models_bin/3/text-spotting-0002-recognizer-decoder/FP32/text-spotting-0002-recognizer-decoder.bin",
     "format": "OpenVINO IR",
-    "link":   "https://download.01.org/openvinotoolkit"
+    "link":   "https://download.01.org/opencv/2020/openvinotoolkit/2020.2/open_model_zoo/models_bin/3/text-spotting-0002-recognizer-decoder/FP32"
   },
   {
     "type":   "openvino",
-    "target": "with_gather.xml",
-    "source": "https://github.com/lutzroeder/netron/files/2871676/with_gather.xml.zip[with_gather.xml]",
+    "target": "ti_with_large_body.xml",
+    "source": "https://github.com/lutzroeder/netron/files/2871678/ti_with_large_body.xml.zip[ti_with_large_body.xml]",
     "format": "OpenVINO IR",
     "link":   "https://download.01.org/openvinotoolkit"
   },
   {
     "type":   "openvino",
-    "target": "ti_with_large_body.xml",
-    "source": "https://github.com/lutzroeder/netron/files/2871678/ti_with_large_body.xml.zip[ti_with_large_body.xml]",
+    "target": "with_gather.xml",
+    "source": "https://github.com/lutzroeder/netron/files/2871676/with_gather.xml.zip[with_gather.xml]",
     "format": "OpenVINO IR",
     "link":   "https://download.01.org/openvinotoolkit"
   },
   {
     "type":   "openvino",
-    "target": "text-recognition-0012.xml,text-recognition-0012.bin",
-    "source": "https://download.01.org/opencv/2020/openvinotoolkit/2020.2/open_model_zoo/models_bin/3/text-recognition-0012/FP16-INT8/text-recognition-0012.xml,https://download.01.org/opencv/2020/openvinotoolkit/2020.2/open_model_zoo/models_bin/3/text-recognition-0012/FP16-INT8/text-recognition-0012.bin",
+    "target": "with_nd_conv_simple.xml",
+    "source": "https://github.com/lutzroeder/netron/files/2871696/with_nd_conv_simple.xml.zip[with_nd_conv_simple.xml]",
     "format": "OpenVINO IR",
-    "link":   "https://download.01.org/opencv/2020/openvinotoolkit/2020.2/open_model_zoo/models_bin/3/text-recognition-0012/FP16-INT8"
+    "link":   "https://download.01.org/openvinotoolkit"
   },
   {
     "type":   "openvino",
-    "target": "text-spotting-0002-recognizer-decoder.xml,text-spotting-0002-recognizer-decoder.bin",
-    "source": "https://download.01.org/opencv/2020/openvinotoolkit/2020.2/open_model_zoo/models_bin/3/text-spotting-0002-recognizer-decoder/FP32/text-spotting-0002-recognizer-decoder.xml,https://download.01.org/opencv/2020/openvinotoolkit/2020.2/open_model_zoo/models_bin/3/text-spotting-0002-recognizer-decoder/FP32/text-spotting-0002-recognizer-decoder.bin",
+    "target": "with_pad_simple.xml",
+    "source": "https://github.com/lutzroeder/netron/files/2871673/with_pad_simple.xml.zip[with_pad_simple.xml]",
     "format": "OpenVINO IR",
-    "link":   "https://download.01.org/opencv/2020/openvinotoolkit/2020.2/open_model_zoo/models_bin/3/text-spotting-0002-recognizer-decoder/FP32"
+    "link":   "https://download.01.org/openvinotoolkit"
   },
   {
     "type":   "paddle",