Ver Fonte

Update ONNX detection (#6)

Lutz Roeder há 3 anos atrás
pai
commit
afdefc23cd
2 ficheiros alterados com 19 adições e 1 exclusões
  1. 18 0
      source/onnx.js
  2. 1 1
      source/view.js

+ 18 - 0
source/onnx.js

@@ -138,6 +138,24 @@ onnx.ModelFactory = class {
         if (tags.has('graph') && extension !== 'model') {
             return 'onnx.pbtxt.ModelProto';
         }
+        if (stream.length > 8) {
+            const buffer = stream.peek(4);
+            const length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24);
+            if (length === stream.length - 4) {
+                stream.seek(4);
+                try {
+                    const reader = protobuf.BinaryReader.open(stream);
+                    tags = reader.signature();
+                    if (tags.get(7) === 2) {
+                        stream.seek(4);
+                        return 'onnx.pb.ModelProto';
+                    }
+                }
+                catch (error) {
+                    // continue regardless of error
+                }
+            }
+        }
         return undefined;
     }
 

+ 1 - 1
source/view.js

@@ -1513,7 +1513,7 @@ view.ModelFactoryService = class {
         this._extensions = new Set([ '.zip', '.tar', '.tar.gz', '.tgz', '.gz' ]);
         this._factories = [];
         this.register('./pytorch', [ '.pt', '.pth', '.ptl', '.pt1', '.pyt', '.pyth', '.pkl', '.pickle', '.h5', '.t7', '.model', '.dms', '.tar', '.ckpt', '.chkpt', '.tckpt', '.bin', '.pb', '.zip', '.nn', '.torchmodel', '.torchscript', '.pytorch', '.ot', '.params', '.trt' ], [ '.model' ]);
-        this.register('./onnx', [ '.onnx', '.onn', '.pb', '.onnxtxt', '.pbtxt', '.prototxt', '.txt', '.model', '.pt', '.pth', '.pkl', '.ort', '.ort.onnx' ]);
+        this.register('./onnx', [ '.onnx', '.onn', '.pb', '.onnxtxt', '.pbtxt', '.prototxt', '.txt', '.model', '.pt', '.pth', '.pkl', '.ort', '.ort.onnx', 'onnxmodel' ]);
         this.register('./mxnet', [ '.json', '.params' ], [ '.mar'] );
         this.register('./coreml', [ '.mlmodel', '.bin', 'manifest.json', 'metadata.json', 'featuredescriptions.json', '.pb' ], [ '.mlpackage' ]);
         this.register('./caffe', [ '.caffemodel', '.pbtxt', '.prototxt', '.pt', '.txt' ]);