Bladeren bron

Update ncnn detection (#296)

Lutz Roeder 4 jaren geleden
bovenliggende
commit
26ff06b6fc
2 gewijzigde bestanden met toevoegingen van 11 en 11 verwijderingen
  1. 10 10
      source/ncnn.js
  2. 1 1
      source/view.js

+ 10 - 10
source/ncnn.js

@@ -10,6 +10,16 @@ ncnn.ModelFactory = class {
 
     match(context) {
         const identifier = context.identifier.toLowerCase();
+        if (identifier.endsWith('.param.bin') || identifier.endsWith('.ncnnmodel')) {
+            const stream = context.stream;
+            if (stream.length > 4) {
+                const buffer = stream.peek(4);
+                const signature = (buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer [3] << 24) >>> 0;
+                if (signature == 0x007685DD) {
+                    return 'ncnn.model.bin';
+                }
+            }
+        }
         if (identifier.endsWith('.param') || identifier.endsWith('.cfg.ncnn')) {
             const reader = text.Reader.open(context.stream, 2048);
             const signature = reader.read();
@@ -23,16 +33,6 @@ ncnn.ModelFactory = class {
                 }
             }
         }
-        if (identifier.endsWith('.param.bin')) {
-            const stream = context.stream;
-            if (stream.length > 4) {
-                const buffer = stream.peek(4);
-                const signature = (buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer [3] << 24) >>> 0;
-                if (signature == 0x007685DD) {
-                    return 'ncnn.model.bin';
-                }
-            }
-        }
         if (identifier.endsWith('.bin') || identifier.endsWith('.weights.ncnn')) {
             if (identifier == 'snapshot_blob.bin' || identifier === 'v8_context_snapshot.bin') {
                 return undefined;

+ 1 - 1
source/view.js

@@ -1535,7 +1535,7 @@ view.ModelFactoryService = class {
         this.register('./dlc', [ '.dlc' ]);
         this.register('./armnn', [ '.armnn', '.json' ]);
         this.register('./mnn', ['.mnn']);
-        this.register('./ncnn', [ '.param', '.bin', '.cfg.ncnn', '.weights.ncnn' ]);
+        this.register('./ncnn', [ '.param', '.bin', '.cfg.ncnn', '.weights.ncnn', '.ncnnmodel' ]);
         this.register('./tnn', [ '.tnnproto', '.tnnmodel' ]);
         this.register('./tengine', ['.tmfile']);
         this.register('./mslite', [ '.ms']);