added node attributes keep successfully while refreshing

1123
ZhangGe6 4 years ago
parent a6834ed3b5
commit d92ecd285c

@ -214,7 +214,7 @@ host.BrowserHost = class {
const downloadButton = this.document.getElementById('download-graph');
downloadButton.addEventListener('click', () => {
console.log(this)
// console.log(this)
// https://healeycodes.com/talking-between-languages
fetch('/download', {
// Declare what type of data we're sending

@ -524,7 +524,7 @@ onnx.Graph = class {
make_custom_add_node(node_info) {
// type of node_info == LightNodeInfo
const schema = this._context.metadata.type(node_info.properties.get('op_type'), node_info.properties.get('domain'));
console.log(schema)
// console.log(schema)
// console.log(node_info.attributes)
// console.log(node_info.inputs)
@ -532,7 +532,7 @@ onnx.Graph = class {
// 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 inputs
var max_custom_add_output_num = Math.min(schema.max_output, 5) // set at most 5 custom_add outputs
var inputs = []
for (let i = 0; i < schema.inputs.length; ++i) {
@ -570,14 +570,19 @@ onnx.Graph = class {
// console.log(inputs)
// console.log(outputs)
// console.log(node_info)
var attributes = []
if (schema.attributes) {
for (const attr of schema.attributes) {
// console.log(attr)
var value = node_info.attributes.get(attr.name) // modified value or null
// console.log(value)
attributes.push(
new onnx.LightAttributeInfo(
attr.name,
attr.description,
attr.type
attr.type,
value
)
)
}
@ -594,8 +599,8 @@ onnx.Graph = class {
inputs,
outputs
);
// console.log(custom_add_node)
this._custom_added_node.push(custom_add_node)
return custom_add_node;
@ -687,6 +692,7 @@ onnx.Node = class {
this._description = description || '';
this._inputs = inputs;
this._outputs = outputs;
// console.log(attributes)
this._attributes = attributes.map((attribute) => new onnx.Attribute(context, op_type, domain, attribute));
// console.log(this._attributes)
this._chain = [];
@ -806,7 +812,7 @@ onnx.Attribute = class {
break;
default:
// console.log(attribute)
this._value = null;
this._value = attribute.value;
this._type = attribute.type;
// TODO: I comment the Error message for the compatibility of onnx.Graph.make_custom_add_node. This is unsafe
// throw new onnx.Error("Unknown attribute type '" + attribute.type + "'.");

@ -457,7 +457,13 @@ view.View = class {
}
get activeGraph() {
return Array.isArray(this._graphs) && this._graphs.length > 0 ? this._graphs[0] : null;
// return Array.isArray(this._graphs) && this._graphs.length > 0 ? this._graphs[0] : null;
var active_graph = Array.isArray(this._graphs) && this._graphs.length > 0 ? this._graphs[0] : null;
if (active_graph && this.lastViewGraph) {
this.refreshAddedNode()
}
return active_graph
}
_updateGraph(model, graphs) {
@ -471,10 +477,13 @@ view.View = class {
this.UpdateAddNodeDropDown();
}
this.lastViewGraph = this._graph;
// if (this.lastViewGraph) {
// // console.log(this.lastViewGraph._addedNode)
// }
const graph = this.activeGraph;
// console.log(graph.nodes)
// console.log("_updateGraph is called");
return this._timeout(100).then(() => {
if (graph && graph != lastGraphs[0]) {
@ -857,6 +866,26 @@ view.View = class {
}
}
refreshAddedNode() {
this._graphs[0].reset_custom_added_node()
// for (const node_info of this._addedNode.values()) {
for (const [modelNodeName, node_info] of this.lastViewGraph._addedNode) {
// console.log(node_info)
var node = this._graphs[0].make_custom_add_node(node_info)
// console.log(node)
// padding empty array for LightNodeInfo.inputs/outputs
for (var input of node.inputs) {
var arg_len = input._arguments.length
this.lastViewGraph._addedNode.get(modelNodeName).inputs.set(input.name, new Array(arg_len))
}
}
// console.log(this.view._graphs[0].nodes)
// console.log(this.lastViewGraph._addedNode)
}
};
view.Graph = class extends grapher.Graph {
@ -1114,25 +1143,29 @@ view.Graph = class extends grapher.Graph {
console.log(this._addedNode)
// refresh
this.view._graphs[0].reset_custom_added_node()
// for (const node_info of this._addedNode.values()) {
for (const [modelNodeName, node_info] of this._addedNode) {
// console.log(node)
var node = this.view._graphs[0].make_custom_add_node(node_info)
// padding empty array for LightNodeInfo.inputs/outputs
for (var input of node.inputs) {
var arg_len = input._arguments.length
this._addedNode.get(modelNodeName).inputs.set(input.name, new Array(arg_len))
}
}
// console.log(this.view._graphs[0].nodes)
console.log(this._addedNode)
// this.refresh_added_node()
}
// refresh_added_node() {
// this.view._graphs[0].reset_custom_added_node()
// // for (const node_info of this._addedNode.values()) {
// for (const [modelNodeName, node_info] of this._addedNode) {
// // console.log(node)
// var node = this.view._graphs[0].make_custom_add_node(node_info)
// // padding empty array for LightNodeInfo.inputs/outputs
// for (var input of node.inputs) {
// var arg_len = input._arguments.length
// this._addedNode.get(modelNodeName).inputs.set(input.name, new Array(arg_len))
// }
// }
// // console.log(this.view._graphs[0].nodes)
// console.log(this._addedNode)
// }
changeNodeAttribute(modelNodeName, attributeName, targetValue) {
if (this._addedNode.has(modelNodeName)) {
this._addedNode.get(modelNodeName).attributes.set(attributeName, targetValue)
@ -1145,7 +1178,7 @@ view.Graph = class extends grapher.Graph {
this._addedNode.get(modelNodeName).inputs.get(parameterName)[arg_index] = targetValue
}
console.log(this._addedNode)
// console.log(this._addedNode)
}

Loading…
Cancel
Save