From cd7697a330d6b6aa392b441eb0116609b4798b15 Mon Sep 17 00:00:00 2001 From: Lutz Roeder Date: Sat, 15 Jul 2023 21:50:57 -0700 Subject: [PATCH] Update attribute visible --- source/armnn.js | 5 ----- source/barracuda.js | 4 ---- source/bigdl.js | 4 ---- source/caffe.js | 2 +- source/caffe2.js | 2 +- source/circle.js | 4 ++-- source/cntk.js | 14 +++++++------- source/coreml.js | 2 +- source/darknet.js | 12 ++++++------ source/dl4j.js | 9 +++------ source/hailo.js | 4 +++- source/keras.js | 4 ++-- source/mediapipe.js | 4 ---- source/mlnet.js | 4 ---- source/ncnn.js | 2 +- source/om.js | 4 ---- source/openvino.js | 2 +- source/pytorch.js | 5 ++++- source/server.js | 8 -------- source/tengine.js | 16 ++++++++-------- source/tf.js | 2 +- source/tflite.js | 21 +++++++++++---------- source/tnn.js | 16 ++++++++-------- source/torch.js | 12 ++++++------ source/uff.js | 4 ---- source/view.js | 4 ++-- 26 files changed, 68 insertions(+), 102 deletions(-) diff --git a/source/armnn.js b/source/armnn.js index c38b062dac..ce12398c2b 100644 --- a/source/armnn.js +++ b/source/armnn.js @@ -67,10 +67,6 @@ armnn.Model = class { return 'Arm NN'; } - get description() { - return ''; - } - get graphs() { return this._graphs; } @@ -83,7 +79,6 @@ armnn.Graph = class { this._nodes = []; this._inputs = []; this._outputs = []; - const counts = new Map(); for (const layer of graph.layers) { const base = armnn.Node.getBase(layer); diff --git a/source/barracuda.js b/source/barracuda.js index 6bb0db5cc3..3b28b87451 100755 --- a/source/barracuda.js +++ b/source/barracuda.js @@ -240,10 +240,6 @@ barracuda.Attribute = class { get value() { return this._value; } - - get visible() { - return true; - } }; barracuda.Tensor = class { diff --git a/source/bigdl.js b/source/bigdl.js index 42fa39dc1d..762692b2f4 100644 --- a/source/bigdl.js +++ b/source/bigdl.js @@ -314,10 +314,6 @@ bigdl.Attribute = class { get value() { return this._value; } - - get visible() { - return true; - } }; bigdl.Tensor = class { diff --git a/source/caffe.js b/source/caffe.js index a0c3ad97cd..0f93b6a1a8 100644 --- a/source/caffe.js +++ b/source/caffe.js @@ -543,7 +543,7 @@ caffe.Attribute = class { this._value = new caffe.TensorShape(value.dim.map((dim) => dim.toNumber())); this._type = 'shape'; } - if (metadata && Object.prototype.hasOwnProperty.call(metadata, 'visible') && !metadata.visible) { + if (metadata && metadata.visible === false) { this._visible = false; } if (metadata && Object.prototype.hasOwnProperty.call(metadata, 'default')) { diff --git a/source/caffe2.js b/source/caffe2.js index 36b2d0c7ce..cd19db81d8 100644 --- a/source/caffe2.js +++ b/source/caffe2.js @@ -504,7 +504,7 @@ caffe2.Attribute = class { } if (metadata) { - if (Object.prototype.hasOwnProperty.call(metadata, 'visible') && !metadata.visible) { + if (metadata.visible === false) { this._visible = false; } else if (metadata.default !== undefined) { if (this._value == metadata.default || (this._value && this._value.toString() == metadata.default.toString())) { diff --git a/source/circle.js b/source/circle.js index 92179bb0fd..4b25b67c05 100644 --- a/source/circle.js +++ b/source/circle.js @@ -291,7 +291,7 @@ circle.Node = class { if (input.option == 'variadic') { count = inputs.length - inputIndex; } - if (Object.prototype.hasOwnProperty.call(input, 'visible') && !input.visible) { + if (input && input.visible === false) { inputVisible = false; } } @@ -415,7 +415,7 @@ circle.Attribute = class { this._value = circle.Utility.enum(this._type, this._value); } if (metadata) { - if (Object.prototype.hasOwnProperty.call(metadata, 'visible') && !metadata.visible) { + if (metadata.visible === false) { this._visible = false; } else if (Object.prototype.hasOwnProperty.call(metadata, 'default')) { value = this._value; diff --git a/source/cntk.js b/source/cntk.js index 5589af6e36..2b56d79b7b 100644 --- a/source/cntk.js +++ b/source/cntk.js @@ -444,7 +444,7 @@ cntk.Node = class { cntk.Attribute = class { - constructor(schema, name, value) { + constructor(metadata, name, value) { this._name = name; this._value = value; this._type = null; @@ -463,18 +463,18 @@ cntk.Attribute = class { } this._value = axis; } - if (schema) { - if (schema.type) { - this._type = schema.type; + if (metadata) { + if (metadata.type) { + this._type = metadata.type; const type = cntk_v1[this._type] || cntk_v2[this._type]; if (type && type[this._value]) { this._value = type[this._value]; } } - if (Object.prototype.hasOwnProperty.call(schema, 'visible') && !schema.visible) { + if (metadata.visible === false) { this._visible = false; - } else if (Object.prototype.hasOwnProperty.call(schema, 'default')) { - let defaultValue = schema.default; + } else if (Object.prototype.hasOwnProperty.call(metadata, 'default')) { + let defaultValue = metadata.default; value = this._value; if (typeof value == 'function') { value = value(); diff --git a/source/coreml.js b/source/coreml.js index 9efc4457e5..fb144587fd 100644 --- a/source/coreml.js +++ b/source/coreml.js @@ -1176,7 +1176,7 @@ coreml.Attribute = class { if (this._type && coreml.proto) { this._value = coreml.Utility.enum(this._type, this._value); } - if (Object.prototype.hasOwnProperty.call(metadata, 'visible') && !metadata.visible) { + if (metadata.visible === false) { this._visible = false; } else if (Object.prototype.hasOwnProperty.call(metadata, 'default')) { if (Array.isArray(value)) { diff --git a/source/darknet.js b/source/darknet.js index 3598ecb3de..9453c63e9a 100644 --- a/source/darknet.js +++ b/source/darknet.js @@ -932,11 +932,11 @@ darknet.Node = class { darknet.Attribute = class { - constructor(schema, name, value) { + constructor(metadata, name, value) { this._name = name; this._value = value; - if (schema) { - this._type = schema.type || ''; + if (metadata) { + this._type = metadata.type || ''; switch (this._type) { case '': case 'string': { @@ -967,10 +967,10 @@ darknet.Attribute = class { throw new darknet.Error("Unsupported attribute type '" + this._type + "'."); } } - if (Object.prototype.hasOwnProperty.call(schema, 'visible') && !schema.visible) { + if (metadata && metadata.visible === false) { this._visible = false; - } else if (Object.prototype.hasOwnProperty.call(schema, 'default')) { - if (this._value == schema.default) { + } else if (Object.prototype.hasOwnProperty.call(metadata, 'default')) { + if (this._value == metadata.default) { this._visible = false; } } diff --git a/source/dl4j.js b/source/dl4j.js index 0bae6dcdf4..3aa6c164ac 100644 --- a/source/dl4j.js +++ b/source/dl4j.js @@ -346,14 +346,11 @@ dl4j.Node = class { dl4j.Attribute = class { - constructor(schema, name, value) { + constructor(metadata, name, value) { this._name = name; this._value = value; - this._visible = false; - if (schema) { - if (schema.visible) { - this._visible = true; - } + if (metadata && metadata.visible === false) { + this._visible = false; } } diff --git a/source/hailo.js b/source/hailo.js index 95956039e0..c589f5a510 100644 --- a/source/hailo.js +++ b/source/hailo.js @@ -240,7 +240,9 @@ hailo.Attribute = class { this._name = name; this._value = value; this._type = metadata && metadata.type ? metadata.type : ''; - this._visible = metadata && metadata.visible !== false ? true : false; + if (metadata && metadata.visible === false) { + this._visible = false; + } if (name === 'original_names') { this._visible = false; } diff --git a/source/keras.js b/source/keras.js index 6e99c415fe..e3666f7b59 100644 --- a/source/keras.js +++ b/source/keras.js @@ -904,8 +904,8 @@ keras.Attribute = class { if (metadata.type) { this._type = metadata.type; } - if (Object.prototype.hasOwnProperty.call(metadata, 'visible')) { - this._visible = metadata.visible; + if (metadata.visible === false) { + this._visible = false; } else if (metadata.default !== undefined) { if (Array.isArray(value)) { if (Array.isArray(metadata.default)) { diff --git a/source/mediapipe.js b/source/mediapipe.js index 034d41372b..2e1f4ba78b 100644 --- a/source/mediapipe.js +++ b/source/mediapipe.js @@ -260,10 +260,6 @@ mediapipe.Argument = class { return this._name; } - get visible() { - return true; - } - get value() { return this._value; } diff --git a/source/mlnet.js b/source/mlnet.js index 400f264680..b7427c3192 100644 --- a/source/mlnet.js +++ b/source/mlnet.js @@ -269,10 +269,6 @@ mlnet.Attribute = class { get value() { return this._value; } - - get visible() { - return true; - } }; mlnet.TensorType = class { diff --git a/source/ncnn.js b/source/ncnn.js index 6df035a534..91a6e695c0 100644 --- a/source/ncnn.js +++ b/source/ncnn.js @@ -612,7 +612,7 @@ ncnn.Attribute = class { break; } } - if (Object.prototype.hasOwnProperty.call(metadata, 'visible') && !metadata.visible) { + if (metadata && metadata.visible === false) { this._visible = false; } else if (Object.prototype.hasOwnProperty.call(metadata, 'default')) { if (this._value == metadata.default || (this._value && this._value.toString() == metadata.default.toString())) { diff --git a/source/om.js b/source/om.js index 9aec21ebe4..2520d50db5 100644 --- a/source/om.js +++ b/source/om.js @@ -317,10 +317,6 @@ om.Attribute = class { get value() { return this._value; } - - get visible() { - return true; - } }; om.Argument = class { diff --git a/source/openvino.js b/source/openvino.js index c920ae1a8d..00480f40e6 100644 --- a/source/openvino.js +++ b/source/openvino.js @@ -741,7 +741,7 @@ openvino.Attribute = class { throw new openvino.Error("Unsupported attribute type '" + schema.type + "'."); } } - if (Object.prototype.hasOwnProperty.call(schema, 'visible') && schema.visible == false) { + if (schema && schema.visible == false) { this._visible = false; } else if (Object.prototype.hasOwnProperty.call(schema, 'default')) { let defaultValue = schema.default; diff --git a/source/pytorch.js b/source/pytorch.js index fbfacfe914..214b7c62f2 100644 --- a/source/pytorch.js +++ b/source/pytorch.js @@ -614,7 +614,6 @@ pytorch.Attribute = class { constructor(metadata, name, value) { this._name = name; this._value = value; - if (this._name === 'training') { this._visible = false; this._type = 'boolean'; @@ -3991,6 +3990,10 @@ pytorch.nnapi.Graph = class { const args = new Map(); const arg = (operand) => { if (!args.has(operand.index)) { + + + + const value = new pytorch.nnapi.Argument(operand); args.set(operand.index, value); } diff --git a/source/server.js b/source/server.js index d0d5b06e9c..ec590e5ff7 100644 --- a/source/server.js +++ b/source/server.js @@ -121,10 +121,6 @@ message.Argument = class { get value() { return this._value; } - - get visible() { - return true; - } }; message.Value = class { @@ -201,10 +197,6 @@ message.Attribute = class { get type() { return this._type; } - - get visible() { - return true; - } }; message.TensorType = class { diff --git a/source/tengine.js b/source/tengine.js index ddfb16bbf7..9512f299ed 100755 --- a/source/tengine.js +++ b/source/tengine.js @@ -206,19 +206,19 @@ tengine.Node = class { tengine.Attribute = class { - constructor(schema, key, value) { + constructor(metadata, key, value) { this._type = ''; this._name = key; this._value = value; - if (schema) { - this._name = schema.name; - if (schema.type) { - this._type = schema.type; + if (metadata) { + this._name = metadata.name; + if (metadata.type) { + this._type = metadata.type; } - if (Object.prototype.hasOwnProperty.call(schema, 'visible') && !schema.visible) { + if (metadata.visible === false) { this._visible = false; - } else if (Object.prototype.hasOwnProperty.call(schema, 'default')) { - if (this._value == schema.default || (this._value && this._value.toString() == schema.default.toString())) { + } else if (Object.prototype.hasOwnProperty.call(metadata, 'default')) { + if (this._value == metadata.default || (this._value && this._value.toString() == metadata.default.toString())) { this._visible = false; } } diff --git a/source/tf.js b/source/tf.js index da1d018ab7..fda7e254d9 100644 --- a/source/tf.js +++ b/source/tf.js @@ -1151,7 +1151,7 @@ tf.Attribute = class { } } if (schema) { - if (Object.prototype.hasOwnProperty.call(schema, 'visible') && !schema.visible) { + if (schema.visible === false) { this._visible = false; } else if (Object.prototype.hasOwnProperty.call(schema, 'default')) { const equals = (value, defaultValue) => { diff --git a/source/tflite.js b/source/tflite.js index 2fac120b1e..0f9df6da53 100644 --- a/source/tflite.js +++ b/source/tflite.js @@ -295,29 +295,30 @@ tflite.Node = class { let inputIndex = 0; while (inputIndex < inputs.length) { let count = 1; - let inputName = null; - let inputVisible = true; - const inputArguments = []; + let name = null; + let visible = true; + const values = []; if (this._type && this._type.inputs && inputIndex < this._type.inputs.length) { const input = this._type.inputs[inputIndex]; - inputName = input.name; + name = input.name; if (input.list) { count = inputs.length - inputIndex; } - if (Object.prototype.hasOwnProperty.call(input, 'visible') && !input.visible) { - inputVisible = false; + if (input.visible === false) { + visible = false; } } const inputArray = inputs.slice(inputIndex, inputIndex + count); for (const index of inputArray) { const value = args(index); if (value) { - inputArguments.push(value); + values.push(value); } } inputIndex += count; - inputName = inputName ? inputName : inputIndex.toString(); - this._inputs.push(new tflite.Argument(inputName, inputVisible, inputArguments)); + name = name ? name : inputIndex.toString(); + const argument = new tflite.Argument(name, visible, values); + this._inputs.push(argument); } for (let k = 0; k < outputs.length; k++) { const index = outputs[k]; @@ -428,7 +429,7 @@ tflite.Attribute = class { this._value = tflite.Utility.enum(this._type, this._value); } if (metadata) { - if (Object.prototype.hasOwnProperty.call(metadata, 'visible') && !metadata.visible) { + if (metadata && metadata.visible == false) { this._visible = false; } else if (Object.prototype.hasOwnProperty.call(metadata, 'default')) { value = this._value; diff --git a/source/tnn.js b/source/tnn.js index c3f7ca99c2..325119115e 100644 --- a/source/tnn.js +++ b/source/tnn.js @@ -378,14 +378,14 @@ tnn.Node = class { tnn.Attribute = class { - constructor(schema, key, value) { + constructor(metadata, key, value) { this._type = ''; this._name = key.toString(); this._value = value; - if (schema) { - this._name = schema.name; - if (schema.type) { - this._type = schema.type; + if (metadata) { + this._name = metadata.name; + if (metadata.type) { + this._type = metadata.type; } switch (this._type) { case '': @@ -405,10 +405,10 @@ tnn.Attribute = class { default: throw new tnn.Error("Unsupported attribute type '" + this._type + "'."); } - if (Object.prototype.hasOwnProperty.call(schema, 'visible') && !schema.visible) { + if (metadata && metadata.visible === false) { this._visible = false; - } else if (Object.prototype.hasOwnProperty.call(schema, 'default')) { - if (this._value == schema.default || (this._value && this._value.toString() == schema.default.toString())) { + } else if (Object.prototype.hasOwnProperty.call(metadata, 'default')) { + if (this._value == metadata.default || (this._value && this._value.toString() == metadata.default.toString())) { this._visible = false; } } diff --git a/source/torch.js b/source/torch.js index 9a4c01b92d..b778ee914b 100644 --- a/source/torch.js +++ b/source/torch.js @@ -453,12 +453,12 @@ torch.Attribute = class { if (name == 'train') { this._visible = false; } - const schema = metadata.attribute(type, name); - if (schema) { - if (Object.prototype.hasOwnProperty.call(schema, 'visible')) { - this._visible = schema.visible; - } else if (Object.prototype.hasOwnProperty.call(schema, 'default')) { - if (JSON.stringify(schema.default) == JSON.stringify(this._value)) { + metadata = metadata.attribute(type, name); + if (metadata) { + if (metadata.visible === false) { + this._visible = false; + } else if (Object.prototype.hasOwnProperty.call(metadata, 'default')) { + if (JSON.stringify(metadata.default) == JSON.stringify(this._value)) { this._visible = false; } } diff --git a/source/uff.js b/source/uff.js index 80df65f26b..2e41d51913 100644 --- a/source/uff.js +++ b/source/uff.js @@ -298,10 +298,6 @@ uff.Attribute = class { get value() { return this._value; } - - get visible() { - return true; - } }; uff.Tensor = class { diff --git a/source/view.js b/source/view.js index ff9f14b1e3..4585c5c1f5 100644 --- a/source/view.js +++ b/source/view.js @@ -1805,7 +1805,7 @@ view.Node = class extends grapher.Node { let sortedAttributes = []; const attributes = node.attributes || []; if (this.context.view.options.attributes) { - sortedAttributes = attributes.filter((attribute) => attribute.visible).slice(); + sortedAttributes = attributes.filter((attribute) => attribute.visible !== false).slice(); } sortedAttributes.sort((a, b) => { const au = a.name.toUpperCase(); @@ -1855,7 +1855,7 @@ view.Node = class extends grapher.Node { } for (const attribute of sortedAttributes) { - if (attribute.visible) { + if (attribute.visible !== false) { let value = new view.Formatter(attribute.value, attribute.type).toString(); if (value && value.length > 25) { value = value.substring(0, 25) + '\u2026';