From 75a92c8263ac4e220b7547a9b1513f75128f6dd6 Mon Sep 17 00:00:00 2001 From: ZhangGe6 Date: Sun, 12 Jun 2022 11:09:02 +0800 Subject: [PATCH] fix the un-filled item in inputs/outputs list (like `concat`) issue --- onnx_modifier.py | 2 ++ readme.md | 14 +++++++++----- static/onnx.js | 8 ++++---- static/view-sidebar.js | 11 +++++------ utils/make_nodes.py | 14 ++++++++++---- 5 files changed, 30 insertions(+), 19 deletions(-) diff --git a/onnx_modifier.py b/onnx_modifier.py index c362cf2..c480fba 100644 --- a/onnx_modifier.py +++ b/onnx_modifier.py @@ -98,6 +98,8 @@ class onnxModifier: if len(const_node_left_output) == 0: self.graph.node.remove(self.node_name2module[left_node.name]) # self.initializer.remove(self.initializer_name2module[init_name]) + else: + left_node.output = const_node_left_output def modify_node_io_name(self, node_renamed_io): diff --git a/readme.md b/readme.md index 8b6c308..0a4821a 100644 --- a/readme.md +++ b/readme.md @@ -108,15 +108,19 @@ Note there is an `Add node` button, following with a selector elements on the to The following are some notes for this feature: -1. Click the selector and type the first letter for the new node type (`f` for `Flatten` node for example), we can be quickly navigated to the node type. +1. :warning: Currently, adding nodes with initializer (such as weight parameters) are not supported (such as `Conv`, `BatchNormalization`). Adding nodes without initializer are tested and work as expected in my tested case (such as `Flatten`, `ArgMax`, `Concat`). -2. By clicking the `?` in the `NODE PROPERTIES -> type` element, or the `+` in each `Attribute` element, we can get some reference to help us fill the node information. +2. Click the selector and type the first letter for the new node type (`f` for `Flatten` node for example), we can be quickly navigated to the node type. -3. It is suggested to fill all of the `Attribute`, without leaving them as `undefined`. The default value may not be supported well in the current version. +3. By clicking the `?` in the `NODE PROPERTIES -> type` element, or the `+` in each `Attribute` element, we can get some reference to help us fill the node information. -4. For the `Attribute` with type `list`, items are split with '`,`' (comma) +4. It is suggested to fill all of the `Attribute`, without leaving them as `undefined`. The default value may not be supported well in the current version. -5. This feature is experimentally supported now and may be not very rebust. So any issues are warmly welcomed if some unexpected result is encountered. +5. For the `Attribute` with type `list`, items are split with '`,`' (comma) + +6. For the `Inputs/Outputs` with type `list`, it is forced to be at most 8 elements in the current version. If the actual inputs/outputs number is less than 8, we can leave the unused items with the name starting with `list_custom`, and they will be automatically omitted. + +7. This feature is experimentally supported now and may be not very rebust. So any issues are warmly welcomed if some unexpected result is encountered. # Sample models diff --git a/static/onnx.js b/static/onnx.js index 85f6ffe..2de8d14 100644 --- a/static/onnx.js +++ b/static/onnx.js @@ -531,8 +531,8 @@ onnx.Graph = class { // console.log(node_info.outputs) // var max_input = schema.max_input // var min_input = schema.max_input - var max_custom_add_input_num = Math.min(schema.max_input, 5) // set at most 5 custom_add inputs - var max_custom_add_output_num = Math.min(schema.max_output, 5) // set at most 5 custom_add outputs + var max_custom_add_input_num = Math.min(schema.max_input, 8) // set at most 8 custom_add inputs + var max_custom_add_output_num = Math.min(schema.max_output, 8) // set at most 8 custom_add outputs // console.log(node_info) var inputs = [] @@ -549,7 +549,7 @@ onnx.Graph = class { var arg_name = node_info_input[j] } else { - var arg_name = 'custom_input_' + (this._custom_add_node_io_idx++).toString() + var arg_name = 'list_custom_input_' + (this._custom_add_node_io_idx++).toString() } arg_list.push(this._context.argument(arg_name)) } @@ -600,7 +600,7 @@ onnx.Graph = class { var arg_name = node_info_output[j] } else { - var arg_name = 'custom_output_' + (this._custom_add_node_io_idx++).toString() + var arg_name = 'list_custom_output_' + (this._custom_add_node_io_idx++).toString() } arg_list.push(this._context.argument(arg_name)) } diff --git a/static/view-sidebar.js b/static/view-sidebar.js index d8d07d6..46703b9 100644 --- a/static/view-sidebar.js +++ b/static/view-sidebar.js @@ -698,7 +698,7 @@ class NodeAttributeView { attr_input.setAttribute("size", "42"); attr_input.setAttribute("value", content ? content : 'undefined'); attr_input.addEventListener('input', (e) => { - console.log(e.target.value); + // console.log(e.target.value); this._host._view._graph.changeNodeAttribute(this._modelNodeName, this._attributeName, this.parse_value(e.target.value, type)); // console.log(this._host._view._graph._renameMap); }); @@ -771,11 +771,6 @@ class NodeAttributeView { } parse_value(value, type) { - if (value == 'undefined') { - // alert(""); - return value - } - switch (type) { case "int64": return parseInt(value) @@ -795,6 +790,10 @@ class NodeAttributeView { val.push(parseFloat(v)) } return val + + default: + return value + } } } diff --git a/utils/make_nodes.py b/utils/make_nodes.py index bc69836..e0b0a4f 100644 --- a/utils/make_nodes.py +++ b/utils/make_nodes.py @@ -3,16 +3,22 @@ import onnx def make_node(node_info): name = node_info['properties']['name'] op_type = node_info['properties']['op_type'] - attributes = node_info['attributes'] - # attributes = {k: v for k, v in node_info['attributes'].items() if not v == 'undefined'} + # attributes = node_info['attributes'] + attributes = {k: v for k, v in node_info['attributes'].items() if not v == 'undefined'} # print(attributes) inputs = [] for key in node_info['inputs'].keys(): - inputs += node_info['inputs'][key] + for inp in node_info['inputs'][key]: + # filter out the un-filled io in list + if not inp.startswith('list_custom'): + inputs.append(inp) outputs = [] for key in node_info['outputs'].keys(): - outputs += node_info['outputs'][key] + for out in node_info['outputs'][key]: + # filter out the un-filled io in list + if not out.startswith('list_custom'): + outputs.append(out) # https://github.com/onnx/onnx/blob/main/onnx/helper.py#L82 node = onnx.helper.make_node(