Lutz Roeder 3 роки тому
батько
коміт
ee4e975878
4 змінених файлів з 53 додано та 0 видалено
  1. 34 0
      source/cambricon.js
  2. 2 0
      source/tflite-schema.js
  3. 1 0
      source/view.js
  4. 16 0
      test/models.json

+ 34 - 0
source/cambricon.js

@@ -0,0 +1,34 @@
+
+var cambricon = cambricon || {};
+
+cambricon.ModelFactory = class {
+
+    match(context) {
+        const stream = context.stream;
+        const buffer = stream.peek(Math.min(20, stream.length));
+        const text = Array.from(buffer).map((c) => String.fromCharCode(c)).join('');
+        if (text.startsWith('\x7fMEF') || text.startsWith('cambricon_offline')) {
+            return 'cambricon';
+        }
+        return '';
+    }
+
+    open(/* context, match */) {
+        return Promise.resolve().then(() => {
+            throw new cambricon.Error("File contains undocumented Cambricon data.");
+        });
+    }
+};
+
+cambricon.Error = class extends Error {
+
+    constructor(message) {
+        super(message);
+        this.name = 'Error loading Cambricon model.';
+        this.stack = undefined;
+    }
+};
+
+if (typeof module !== 'undefined' && typeof module.exports === 'object') {
+    module.exports.ModelFactory = cambricon.ModelFactory;
+}

+ 2 - 0
source/tflite-schema.js

@@ -202,6 +202,7 @@ $root.tflite.Tensor = class Tensor {
         $.is_variable = reader.bool_(position, 14, false);
         $.sparsity = reader.table(position, 16, $root.tflite.SparsityParameters.decode);
         $.shape_signature = reader.typedArray(position, 18, Int32Array);
+        $.has_rank = reader.bool_(position, 20, false);
         return $;
     }
 
@@ -215,6 +216,7 @@ $root.tflite.Tensor = class Tensor {
         $.is_variable = reader.value(json.is_variable, false);
         $.sparsity = reader.object(json.sparsity, $root.tflite.SparsityParameters.decodeText);
         $.shape_signature = reader.typedArray(json.shape_signature, Int32Array);
+        $.has_rank = reader.value(json.has_rank, false);
         return $;
     }
 };

+ 1 - 0
source/view.js

@@ -1603,6 +1603,7 @@ view.ModelFactoryService = class {
         this.register('./flax', [ '.msgpack' ]);
         this.register('./om', [ '.om', '.onnx', '.pb', '.engine' ]);
         this.register('./nnabla', [ '.nntxt' ], [ '.nnp' ]);
+        this.register('./cambricon', [ '.cambricon' ]);
     }
 
     register(id, factories, containers) {

+ 16 - 0
test/models.json

@@ -893,6 +893,22 @@
     "format":   "Caffe2",
     "link":     "https://github.com/caffe2/models"
   },
+  {
+    "type":     "cambricon",
+    "target":   "deepsort_4c4b_bgr_270_v140.cambricon",
+    "source":   "https://github.com/lutzroeder/netron/files/8783170/deepsort_4c4b_bgr_270_v140.cambricon.zip[deepsort_4c4b_bgr_270_v140.cambricon]",
+    "format":   "Cambricon",
+    "error":    "File contains undocumented Cambricon data in 'deepsort_4c4b_bgr_270_v140.cambricon'.",
+    "link":     "https://github.com/lutzroeder/netron/issues/917"
+  },
+  {
+    "type":     "cambricon",
+    "target":   "SR_face_x3_530x530.cambricon",
+    "source":   "https://github.com/lutzroeder/netron/files/8783172/SR_face_x3_530x530.cambricon.zip[SR_face_x3_530x530.cambricon]",
+    "format":   "Cambricon",
+    "error":    "File contains undocumented Cambricon data in 'SR_face_x3_530x530.cambricon'.",
+    "link":     "https://github.com/lutzroeder/netron/issues/917"
+  },
   {
     "type":     "circle",
     "target":   "ArgMax_001.circle",