polish code and make the repo public

1123
ZhangGe6 4 years ago
parent a11ca520c4
commit ee2ba46898

@ -236,7 +236,6 @@ host.BrowserHost = class {
// Should be 'OK' if everything was successful
console.log(text);
if (text == 'OK') {
// alert("Modified model has been saved in ./modified_onnx/modified_" + this.upload_filename);
// alert("Modified model has been successfuly saved in ./modified_onnx/");
swal("Success!", "Modified model has been successfuly saved in ./modified_onnx/", "success");
}
@ -625,9 +624,6 @@ host.BrowserHost = class {
}
return lo
}
};
host.Dropdown = class {

@ -41,13 +41,6 @@ grapher.Graph = class {
}
}
// My code
// var modelNodeName = node.value.name;
// if (modelNodeName == '') { // in case that model node has no name
// modelNodeName = node.value.type.name + node.name
// // console.log(node.value)
// // console.log(modelNodeName)
// }
const modelNodeName = node.modelNodeName
this._modelNodeName2ViewNode.set(modelNodeName, node);
@ -56,9 +49,6 @@ grapher.Graph = class {
if (!this._modelNodeName2State.get(modelNodeName)) {
this._modelNodeName2State.set(modelNodeName, 'Exist');
}
// console.log(modelNodeName)
// console.log(node.modelNodeName)
}
setEdge(edge) {
@ -75,8 +65,6 @@ grapher.Graph = class {
// My code
// _namedEdges: from : to
// var from_node_name = edge.from.value.name
// var to_node_name = edge.to.value.name
var from_node_name = edge.from.modelNodeName
var to_node_name = edge.to.modelNodeName
if (!this._namedEdges.has(from_node_name)) {
@ -180,15 +168,9 @@ grapher.Graph = class {
edgePathGroupDefs.appendChild(marker("arrowhead-vee-select"));
// <==== 显示 边上的箭头
// console.log(this._modelNodeName2State)
// console.log(this.nodes)
for (const nodeId of this.nodes.keys()) {
const node = this.node(nodeId);
if (this.children(nodeId).length == 0) {
// console.log(node.label.modelNodeName)
// console.log(this._modelNodeName2State.get(node.label.modelNodeName))
// node
// type(node.label) == view.Node
if (this._modelNodeName2State.get(node.label.modelNodeName) == 'Exist') {
node.label.build(document, nodeGroup);
}
@ -213,8 +195,6 @@ grapher.Graph = class {
for (const edge of this.edges.values()) {
var node_from = this._nodes.get(edge.v).label;
var node_to = this._nodes.get(edge.w).label;
// console.log(this._modelNodeName2State.get(node_from.modelNodeName))
// console.log(this._modelNodeName2State.get(node_to.modelNodeName))
if (
this._modelNodeName2State.get(node_from.modelNodeName) == 'Exist' &&
this._modelNodeName2State.get(node_to.modelNodeName) == 'Exist'
@ -236,7 +216,6 @@ grapher.Graph = class {
node.label.update(); // 让节点显示出来
}
}
// ===> 这段没有操作
else {
// cluster
const node = this.node(nodeId);
@ -246,13 +225,10 @@ grapher.Graph = class {
node.label.rectangle.setAttribute('width', node.label.width);
node.label.rectangle.setAttribute('height', node.label.height);
}
// <=== 这段没有操作
}
// console.log(this.edges)
for (const edge of this.edges.values()) {
var node_from = this._nodes.get(edge.v).label;
var node_to = this._nodes.get(edge.w).label;
// console.log(edge.label)
if (
this._modelNodeName2State.get(node_from.modelNodeName) == 'Exist' &&
this._modelNodeName2State.get(node_to.modelNodeName) == 'Exist'
@ -311,7 +287,7 @@ grapher.Node = class {
block.build(document, this.element);
}
this.layout(); // 这一行注释后,边和节点全部乱成一团,报错一堆
this.layout();
}
layout() {

@ -167,10 +167,8 @@ sidebar.NodeSidebar = class {
}
const attributes = node.attributes;
// console.log(attributes)
if (attributes && attributes.length > 0) {
const sortedAttributes = node.attributes.slice();
// console.log(sortedAttributes)
sortedAttributes.sort((a, b) => {
const au = a.name.toUpperCase();
const bu = b.name.toUpperCase();
@ -183,7 +181,6 @@ sidebar.NodeSidebar = class {
}
const inputs = node.inputs;
// console.log(inputs)
if (inputs && inputs.length > 0) {
this._addHeader('Inputs');
for (const input of inputs) {
@ -191,7 +188,6 @@ sidebar.NodeSidebar = class {
this.add_rename_aux_element(input.arguments);
}
}
// console.log(this._renameAuxelements)
const outputs = node.outputs;
if (outputs && outputs.length > 0) {
@ -220,7 +216,6 @@ sidebar.NodeSidebar = class {
add_separator(elment, className) {
const separator = this._host.document.createElement('div');
separator.className = className;
// this._elements.push(separator);
elment.push(separator);
}
@ -250,7 +245,6 @@ sidebar.NodeSidebar = class {
console.log(e.target.value);
this._host._view._graph.recordRenameInfo(this._modelNodeName, argument.name, e.target.value);
// console.log(this._host._view._graph._renameMap);
});
this._renameAuxelements.push(origNameElement);
@ -324,7 +318,6 @@ sidebar.NodeSidebar = class {
buttonElement.innerText = title;
this._elements.push(buttonElement);
// console.log(title)
if (title === 'Delete Single Node') {
buttonElement.addEventListener('click', () => {
this._host._view._graph.delete_node(this._modelNodeName)
@ -336,7 +329,6 @@ sidebar.NodeSidebar = class {
});
}
if (title === 'Recover Node') {
// console.log('pressed')
buttonElement.addEventListener('click', () => {
this._host._view._graph.reset_node(this._modelNodeName)
});
@ -473,7 +465,7 @@ sidebar.NameValueView = class {
const nameElement = this._host.document.createElement('div');
nameElement.className = 'sidebar-view-item-name';
// ===> 这一段是input框前的名称如attributte的pad不包含后面的小白块太有误导性了。。。
// ===> 这一段是input框前的名称如attributte的pad不包含后面的小白块
// console.log(name)
const nameInputElement = this._host.document.createElement('input');
nameInputElement.setAttribute('type', 'text');
@ -558,7 +550,7 @@ sidebar.ValueTextView = class {
this._host = host;
this._elements = [];
const element = this._host.document.createElement('div');
element.className = 'sidebar-view-item-value'; // 这个渲染出后面一个长白格
element.className = 'sidebar-view-item-value';
this._elements.push(element);
if (action) {
@ -583,7 +575,6 @@ sidebar.ValueTextView = class {
}
render() {
// console.log(this._elements)
return this._elements;
}
@ -609,11 +600,7 @@ class NodeAttributeView {
});
this._element.appendChild(this._expander);
}
// console.log(this._attribute)
// console.log(this._attribute.value)
const value = this._attribute.value;
// console.log(value)
// console.log(type)
switch (type) {
case 'graph': {
const line = this._host.document.createElement('div');
@ -637,7 +624,6 @@ class NodeAttributeView {
}
default: {
let content = sidebar.NodeSidebar.formatAttributeValue(value, type);
// console.log(content)
if (content && content.length > 1000) {
content = content.substring(0, 1000) + '\u2026';
}
@ -722,10 +708,7 @@ sidebar.ParameterView = class {
this._elements = [];
this._items = [];
// console.log('new ParameterView')
// console.log(list.arguments) // Array(1)
for (const argument of list.arguments) {
// console.log(argument)
const item = new sidebar.ArgumentView(host, argument);
item.on('export-tensor', (sender, tensor) => {
this._raise('export-tensor', tensor);

@ -53,9 +53,7 @@ view.View = class {
this._host.document.addEventListener('keydown', () => {
this.clearSelection();
});
// console.log('before host start');
this._host.start();
// console.log('host started!');
const container = this._getElementById('graph');
container.addEventListener('scroll', (e) => this._scrollHandler(e));
container.addEventListener('wheel', (e) => this._wheelHandler(e), { passive: false });
@ -134,7 +132,6 @@ view.View = class {
}
get model() {
// console.log('model() is called');
return this._model;
}
@ -422,13 +419,10 @@ view.View = class {
}
open(context) {
// console.log("view open()");
// console.log(context);
this._host.event('Model', 'Open', 'Size', context.stream ? context.stream.length : 0);
this._sidebar.close();
return this._timeout(2).then(() => {
return this._modelFactoryService.open(context).then((model) => {
// console.log(model);
const format = [];
if (model.format) {
format.push(model.format);
@ -450,7 +444,6 @@ view.View = class {
_updateActiveGraph(graph) {
this._sidebar.close();
if (this._model) {
// console.log('_updateActiveGraph() is called');
const model = this._model;
this.show('welcome spinner');
this._timeout(200).then(() => {
@ -468,12 +461,8 @@ view.View = class {
}
_updateGraph(model, graphs) {
// console.log('view._updateGraph() is called')
// console.log(model);
// console.log(graphs);
const lastModel = this._model;
const lastGraphs = this._graphs;
// console.log(lastNodeState)
// update graph if and only if `model` and `graphs` are provided
if (model && graphs) {
this._model = model;
@ -481,16 +470,7 @@ view.View = class {
}
const graph = this.activeGraph;
this.lastViewGraph = this._graph;
// console.log("this.lastViewGraph")
// console.log(this.lastViewGraph)
// if (this.lastViewGraph) {
// // console.log(this._graph)
// // this.lastModelNodeName2State = lastViewGraph._modelNodeName2State;
// console.log('lastViewGraph _modelNodeName2State')
// console.log(this.lastViewGraph._modelNodeName2State)
// }
this.lastViewGraph = this._graph;
// console.log("_updateGraph is called");
return this._timeout(100).then(() => {
if (graph && graph != lastGraphs[0]) {
@ -567,7 +547,6 @@ view.View = class {
this._zoom = 1;
const groups = graph.groups;
// console.log(groups) // undefined
const nodes = graph.nodes;
this._host.event('Graph', 'Render', 'Size', nodes.length);
@ -584,19 +563,17 @@ view.View = class {
}
const viewGraph = new view.Graph(this, model, groups, options);
// console.log(viewGraph)
if (this.lastViewGraph) {
// console.log(this.lastViewGraph._modelNodeName2State)
// console.log('node state of lastViewGraph is loaded')
viewGraph._modelNodeName2State = this.lastViewGraph._modelNodeName2State;
viewGraph._renameMap = this.lastViewGraph._renameMap;
// console.log(viewGraph._renameMap);
// console.log(viewGraph._modelNodeName2State)
}
// console.log(viewGraph._modelNodeName2State)
viewGraph.add(graph);
// console.log(viewGraph._arguments)
// Workaround for Safari background drag/zoom issue:
// https://stackoverflow.com/questions/40887193/d3-js-zoom-is-not-working-with-mousewheel-in-safari
const background = this._host.document.createElementNS('http://www.w3.org/2000/svg', 'rect');
@ -617,7 +594,6 @@ view.View = class {
viewGraph.update();
// 让画面可拖动/缩放 =======>
const elements = Array.from(canvas.getElementsByClassName('graph-input') || []);
if (elements.length === 0) {
@ -676,7 +652,6 @@ view.View = class {
// <======= 让画面可拖动/缩放
this._graph = viewGraph;
return;
});
@ -802,8 +777,6 @@ view.View = class {
if (node) {
try {
// console.log(node) // 注意是onnx.Node, 不是grapher.Node所以没有update() 没有element元素
// console.log(node.element) // undefined
// node.update()
const nodeSidebar = new sidebar.NodeSidebar(this._host, node, modelNodeName);
nodeSidebar.on('show-documentation', (/* sender, e */) => {
this.showDocumentation(node.type);
@ -872,8 +845,6 @@ view.View = class {
view.Graph = class extends grapher.Graph {
constructor(view, model, compound, options) {
// console.log('constructing view.Graph')
// console.log(compound) // undefined
super(compound, options);
this.view = view;
this.model = model;
@ -887,7 +858,6 @@ view.Graph = class extends grapher.Graph {
const value = new view.Node(this, node, modelNodeName);
value.name = node_id;
// value.name = node.name;
this.setNode(value);
return value;
}
@ -926,7 +896,6 @@ view.Graph = class extends grapher.Graph {
const clusters = new Set();
const clusterParentMap = new Map();
const groups = graph.groups;
// console.log(groups) // undefined
if (groups) {
for (const node of graph.nodes) {
if (node.group) {
@ -940,7 +909,6 @@ view.Graph = class extends grapher.Graph {
}
}
// console.log(graph)
for (const input of graph.inputs) {
const viewInput = this.createInput(input);
for (const argument of input.arguments) {
@ -962,12 +930,6 @@ view.Graph = class extends grapher.Graph {
!this._renameMap.get(viewNode.modelNodeName).get(argument.name) == '' // in case user clear the input name
)
{
// argument.name = this._renameMap.get(viewNode.modelNodeName).get(argument.name);
// create (deepcopy) a new argument rather than edit in-place
// var renamed_argument = JSON.parse(JSON.stringify(argument));
// renamed_argument.name = this._renameMap.get(viewNode.modelNodeName).get(argument.name);
// this.createArgument(renamed_argument).to(viewNode);
argument._new_name = this._renameMap.get(viewNode.modelNodeName).get(argument.name);
argument._renamed = true;
}
@ -997,13 +959,6 @@ view.Graph = class extends grapher.Graph {
!this._renameMap.get(viewNode.modelNodeName).get(argument.name) == ''
)
{
// console.log(argument.name)
// console.log(this._renameMap.get(viewNode.modelNodeName).get(argument.name))
// argument.name = this._renameMap.get(viewNode.modelNodeName).get(argument.name);
// var renamed_argument = JSON.parse(JSON.stringify(argument));
// renamed_argument.name = this._renameMap.get(viewNode.modelNodeName).get(argument.name);
// this.createArgument(renamed_argument).to(viewNode);
argument._new_name = this._renameMap.get(viewNode.modelNodeName).get(argument.name);
argument._renamed = true;
}
@ -1056,19 +1011,11 @@ view.Graph = class extends grapher.Graph {
}
for (const output of graph.outputs) {
// // My code
// if (this._modelNodeName2State.get(output.name) == 'Deleted') {
// // console.log(this._modelNodeName2State.get(node.name))
// continue;
// }
const viewOutput = this.createOutput(output);
for (const argument of output.arguments) {
this.createArgument(argument).to(viewOutput);
}
}
// console.log()
}
// My code
@ -1083,11 +1030,8 @@ view.Graph = class extends grapher.Graph {
}
delete_node_with_children(node_name) {
this.delete_backtrack(node_name);
// console.log("after deleting")
// console.log(this._modelNodeName2State)
}
delete_backtrack(node_name) {
@ -1104,8 +1048,6 @@ view.Graph = class extends grapher.Graph {
this._modelNodeName2State.set(node_name, 'Deleted');
this._modelNodeName2ViewNode.get(node_name).element.style.opacity = 0.3;
// console.log('deleting')
// console.log(node_name)
if (!this._namedEdges.has(node_name)){ // for leaf node
return;
}
@ -1118,10 +1060,8 @@ view.Graph = class extends grapher.Graph {
resetGraph() {
for (const nodeId of this.nodes.keys()) {
const node = this.node(nodeId);
// console.log(node.label.modelNodeName)
this._modelNodeName2State.set(node.label.modelNodeName, 'Exist')
}
// console.log(this._modelNodeName2State)
this._renameMap = new Map();
}
@ -1137,9 +1077,6 @@ view.Graph = class extends grapher.Graph {
for (const argument of this._arguments.values()) {
argument.build();
}
// console.log("this._pathArgumentNames");
// console.log(this._pathArgumentNames);
// console.log(this._namedEdges)
super.build(document, origin);
}
};
@ -1197,7 +1134,6 @@ view.Node = class extends grapher.Node {
// this._expand.on('click', () => this.toggle());
}
// 节点在图上的显示信息
const initializers = [];
let hiddenInitializers = false;
if (this.context.view.options.initializers) {
@ -1749,17 +1685,14 @@ view.ModelFactoryService = class {
}
open(context) {
// console.log(context)
return this._openSignature(context).then((context) => {
const containers = new Map();
let stream = context.stream;
const entries = context.entries;
// console.log(entries); // undefined
if (!stream && entries && entries.size > 0) {
containers.set('', entries);
}
else {
// console.log('here');
const identifier = context.identifier;
try {
const archive = gzip.Archive.open(stream);
@ -1793,10 +1726,7 @@ view.ModelFactoryService = class {
throw new view.ArchiveError(message.replace(/\.$/, '') + " in '" + identifier + "'.");
}
}
// console.log(containers); // Map(0)
// console.log(context)
const modelContext = new view.ModelContext(context, containers);
// console.log(modelContext);
return this._openContext(modelContext).then((model) => {
if (model) {
return model;
@ -2013,7 +1943,6 @@ view.ModelFactoryService = class {
}
_openContext(context) {
// console.log(context)
const modules = this._filter(context).filter((module) => module && module.length > 0);
// console.log(modules) // ['./onnx', './tensorrt', './rknn', './om']

Loading…
Cancel
Save