Bläddra i källkod

Add ONNX test file (#914)

Lutz Roeder 3 år sedan
förälder
incheckning
7c99c371cf
4 ändrade filer med 34 tillägg och 1 borttagningar
  1. 5 1
      source/coreml.js
  2. 18 0
      source/onnx.js
  3. 4 0
      source/view-sidebar.js
  4. 7 0
      test/models.json

+ 5 - 1
source/coreml.js

@@ -1443,8 +1443,12 @@ coreml.OptionalType = class {
         this._type = type;
     }
 
+    get type() {
+        return this._type;
+    }
+
     toString() {
-        return this._type.toString() + '?';
+        return 'optional<' + this._type.toString() + '>';
     }
 };
 

+ 18 - 0
source/onnx.js

@@ -1265,6 +1265,21 @@ onnx.OpaqueType = class {
     }
 };
 
+onnx.OptionalType = class {
+
+    constructor(type) {
+        this._type = type;
+    }
+
+    get type() {
+        return this._type;
+    }
+
+    toString() {
+        return 'optional<' + this._type.toString() + '>';
+    }
+};
+
 onnx.Function = class {
 
     constructor(context, func) {
@@ -1672,6 +1687,9 @@ onnx.GraphContext = class {
         else if (type.opaque_type) {
             return new onnx.OpaqueType(type.opaque_type.domain, type.opaque_type.name);
         }
+        else if (type.optional_type) {
+            return new onnx.OptionalType(this.createType(type.optional_type.elem_type), denotation);
+        }
         throw new onnx.Error("Unsupported tensor type '" + JSON.stringify(type) + "'.");
     }
 

+ 4 - 0
source/view-sidebar.js

@@ -1418,6 +1418,10 @@ sidebar.Formatter = class {
                 return value.type.name;
             case 'function[]':
                 return value ? value.map((item) => item.type.name).join(', ') : '(null)';
+            case 'type':
+                return value ? value.toString() : '(null)';
+            case 'type[]':
+                return value ? value.map((item) => item.toString()).join(', ') : '(null)';
             default:
                 break;
         }

+ 7 - 0
test/models.json

@@ -3518,6 +3518,13 @@
     "format":   "ONNX v3",
     "link":     "https://github.com/microsoft/onnxruntime/tree/master/onnxruntime/test/testdata"
   },
+  {
+    "type":     "onnx",
+    "target":   "optional_type.onnx",
+    "source":   "https://github.com/lutzroeder/netron/files/8746170/optional_type.onnx.zip[optional_type.onnx]",
+    "format":   "ONNX v8",
+    "link":     "https://github.com/lutzroeder/netron/issues/914"
+  },
   {
     "type":     "onnx",
     "target":   "ort_github_issue_4031.onnx.ort",