Ver código fonte

Add TensorFlow Lite attributes null check

Lutz Roeder 5 anos atrás
pai
commit
99277587e7
3 arquivos alterados com 17 adições e 17 exclusões
  1. 2 4
      src/tflite.js
  2. 8 7
      src/view-sidebar.js
  3. 7 6
      src/view.js

+ 2 - 4
src/tflite.js

@@ -153,6 +153,7 @@ tflite.Node = class {
         this._operator = operator;
         this._inputs = [];
         this._outputs = [];
+        this._attributes = [];
         if (node) {
             const schema = this._metadata.type(this.operator);
             let inputs = [];
@@ -185,7 +186,6 @@ tflite.Node = class {
                 inputName = inputName ? inputName : inputIndex.toString();
                 this._inputs.push(new tflite.Parameter(inputName, inputVisible, inputConnections));
             }
-            this._outputs = [];
             for (let k = 0; k < node.outputsLength(); k++) {
                 const outputIndex = node.outputs(k);
                 const argument = args[outputIndex];
@@ -198,7 +198,6 @@ tflite.Node = class {
                 }
                 this._outputs.push(new tflite.Parameter(outputName, true, [ argument ]));
             }
-            this._attributes = [];
             if (operator.custom && node.customOptionsLength() > 0) {
                 let custom = [];
                 for (let m = 0; m < node.customOptionsLength(); m++) {
@@ -225,8 +224,7 @@ tflite.Node = class {
             }
             const optionsType = tflite.schema[optionsTypeName] || null;
             if (typeof optionsType === 'function') {
-                let options = Reflect.construct(optionsType, []);
-                options = node.builtinOptions(options);
+                const options = node.builtinOptions(Reflect.construct(optionsType, []));
                 if (options) {
                     let attributeName;
                     let attributeNames = [];

+ 8 - 7
src/view-sidebar.js

@@ -167,15 +167,16 @@ sidebar.NodeSidebar = class {
             this._addProperty('device', new sidebar.ValueTextView(this._host, node.device));
         }
 
-        const attributes = node.attributes.slice();
-        attributes.sort((a, b) => { 
-            const au = a.name.toUpperCase();
-            const bu = b.name.toUpperCase();
-            return (au < bu) ? -1 : (au > bu) ? 1 : 0;
-        });
+        const attributes = node.attributes;
         if (attributes && attributes.length > 0) {
+            let sortedAttributes = node.attributes.slice();
+            sortedAttributes.sort((a, b) => { 
+                const au = a.name.toUpperCase();
+                const bu = b.name.toUpperCase();
+                return (au < bu) ? -1 : (au > bu) ? 1 : 0;
+            });
             this._addHeader('Attributes');
-            for (const attribute of attributes) {
+            for (const attribute of sortedAttributes) {
                 this._addAttribute(attribute.name, attribute);
             }
         }

+ 7 - 6
src/view.js

@@ -459,16 +459,17 @@ view.View = class {
                                 }
                             }
                         }
-                        let attributes = [];
-                        if (self.showAttributes && node.attributes) {
-                            attributes = node.attributes.filter((attribute) => attribute.visible).slice();
-                            attributes.sort((a, b) => { 
+                        let sortedAttributes = [];
+                        const attributes = node.attributes;
+                        if (self.showAttributes && attributes) {
+                            sortedAttributes = attributes.filter((attribute) => attribute.visible).slice();
+                            sortedAttributes.sort((a, b) => { 
                                 const au = a.name.toUpperCase();
                                 const bu = b.name.toUpperCase();
                                 return (au < bu) ? -1 : (au > bu) ? 1 : 0;
                             });
                         }
-                        if (initializers.length > 0 || hiddenInitializers || attributes.length > 0) {
+                        if (initializers.length > 0 || hiddenInitializers || sortedAttributes.length > 0) {
                             let block = element.block('list');
                             block.handler = () => {
                                 self.showNodeProperties(node);
@@ -497,7 +498,7 @@ view.View = class {
                                 block.add(null, '\u3008' + '\u2026' + '\u3009', '', null, '');
                             }
 
-                            for (const attribute of attributes) {
+                            for (const attribute of sortedAttributes) {
                                 if (attribute.visible) {
                                     let attributeValue = sidebar.NodeSidebar.formatAttributeValue(attribute.value, attribute.type);
                                     if (attributeValue && attributeValue.length > 25) {