2
0
Lutz Roeder 5 сар өмнө
parent
commit
4ca0920678
3 өөрчлөгдсөн 24 нэмэгдсэн , 7 устгасан
  1. 1 1
      source/dnn.js
  2. 9 6
      source/protobuf.js
  3. 14 0
      test/models.json

+ 1 - 1
source/dnn.js

@@ -196,7 +196,7 @@ dnn.Tensor = class {
         const itemsize = Math.floor(this.values.length / size);
         const remainder = this.values.length - (itemsize * size);
         if (remainder < 0 || remainder > itemsize) {
-            throw new dnn.Error('Invalid tensor data size.');
+            throw new dnn.Error(`Invalid tensor data size '${this.values.length}' tensor shape '[${shape.dimensions}]' '.`);
         }
         let dataType = '?';
         switch (itemsize) {

+ 9 - 6
source/protobuf.js

@@ -405,10 +405,11 @@ protobuf.BinaryReader = class {
                 break;
             }
             case 1: {
-                if (this._position + 8 >= this._length) {
+                const position = this._position + 8;
+                if (position > this._length) {
                     return false;
                 }
-                this._position += 8;
+                this._position = position;
                 break;
             }
             case 2: {
@@ -416,10 +417,11 @@ protobuf.BinaryReader = class {
                 if (length === undefined) {
                     return false;
                 }
-                if (this._position + length > this._end) {
+                const position = this._position + length;
+                if (position > this._end) {
                     return false;
                 }
-                this._position += length;
+                this._position = position;
                 break;
             }
             case 3: {
@@ -439,10 +441,11 @@ protobuf.BinaryReader = class {
                 break;
             }
             case 5: {
-                this._position += 4;
-                if (this._position > this._length) {
+                const position = this._position + 4;
+                if (position > this._length) {
                     return false;
                 }
+                this._position = position;
                 break;
             }
             default: {

+ 14 - 0
test/models.json

@@ -1987,6 +1987,13 @@
     "assert":   "model.modules[0].nodes[0].inputs[1].value[0].initializer.type.shape.dimensions[3] == 16",
     "link":     "https://github.com/lutzroeder/netron/issues/1037"
   },
+  {
+    "type":     "dnn",
+    "target":   "add_beard_model.dnn",
+    "source":   "https://github.com/user-attachments/files/22800584/add_beard_model.dnn.zip[add_beard_model.dnn]",
+    "format":   "SnapML v1",
+    "link":     "https://github.com/lutzroeder/netron/issues/581"
+  },
   {
     "type":     "dnn",
     "target":   "brows_model.dnn",
@@ -1994,6 +2001,13 @@
     "format":   "SnapML v1",
     "link":     "https://github.com/lutzroeder/netron/issues/581"
   },
+  {
+    "type":     "dnn",
+    "target":   "remove_beard_model.dnn",
+    "source":   "https://github.com/user-attachments/files/22800588/remove_beard_model.dnn.zip[remove_beard_model.dnn]",
+    "format":   "SnapML v1",
+    "link":     "https://github.com/lutzroeder/netron/issues/581"
+  },
   {
     "type":     "dot",
     "target":   "chart_fr1.dot",