提交 404b0b41 编写于 作者: Q qiaolongfei

can work properly

上级 20f391d3
...@@ -68,7 +68,7 @@ def rename_model(model_json): ...@@ -68,7 +68,7 @@ def rename_model(model_json):
all_nodes[idx]['name'] = new_name all_nodes[idx]['name'] = new_name
def add_links(model_json): def get_links(model_json):
links = [] links = []
for input in model_json['input']: for input in model_json['input']:
...@@ -76,18 +76,22 @@ def add_links(model_json): ...@@ -76,18 +76,22 @@ def add_links(model_json):
for node in model_json['node']: for node in model_json['node']:
if name in node['input']: if name in node['input']:
links.append({'source': name, links.append({'source': name,
"target": node['name'], "target": node['name']})
"label": name}) # links.append({'source': name,
# "target": node['name'],
# "label": name})
for source_node in model_json['node']: for source_node in model_json['node']:
for output in source_node['output']: for output in source_node['output']:
for target_node in model_json['node']: for target_node in model_json['node']:
if output in target_node['input']: if output in target_node['input']:
links.append({'source': source_node['name'], links.append({'source': source_node['name'],
'target': target_node['name'], 'target': target_node['name']})
'label': output}) # links.append({'source': source_node['name'],
# 'target': target_node['name'],
# 'label': output})
model_json['links'] = links return links
def get_node_links(model_json): def get_node_links(model_json):
...@@ -174,6 +178,18 @@ def add_level_to_node_links(node_links): ...@@ -174,6 +178,18 @@ def add_level_to_node_links(node_links):
def get_level_to_all(node_links, model_json): def get_level_to_all(node_links, model_json):
""" """
level_to_nodes {level -> [node_1, node_2]} level_to_nodes {level -> [node_1, node_2]}
output:
{
"35": {
"inputs": [
38,
39
],
"nodes": [
46
],
"outputs": []
}, {}
""" """
level_to_nodes = dict() level_to_nodes = dict()
for idx in node_links: for idx in node_links:
...@@ -249,11 +265,48 @@ def get_level_to_all(node_links, model_json): ...@@ -249,11 +265,48 @@ def get_level_to_all(node_links, model_json):
init_level(level) init_level(level)
level_to_all[level]['outputs'] = level_to_outputs[level] level_to_all[level]['outputs'] = level_to_outputs[level]
debug_print(level_to_all) # debug_print(level_to_all)
return level_to_all return level_to_all
def level_to_coordinate(level_to_all):
default_x = 100
x_step = 100
default_y = 10
y_step = 100
node_to_coordinate = dict()
input_to_coordinate = dict()
output_to_coordinate = dict()
def get_coordinate(x_idx, y_idx):
x = default_x + x_idx * x_step
y = default_y + y_idx * y_step
return {"x": int(x), "y": int(y)}
for level in level_to_all:
nodes = level_to_all[level]['nodes']
inputs = level_to_all[level]['inputs']
outputs = level_to_all[level]['outputs']
x_idx = 0
for node_idx in nodes:
node_to_coordinate[node_idx] = get_coordinate(x_idx, level)
x_idx += 1
for in_idx in inputs:
input_to_coordinate[in_idx] = get_coordinate(x_idx, level)
x_idx += 1
for out_idx in outputs:
output_to_coordinate[out_idx] = get_coordinate(x_idx, level)
x_idx += 1
# debug_print(node_to_coordinate)
# debug_print(input_to_coordinate)
# debug_print(output_to_coordinate)
return node_to_coordinate, input_to_coordinate, output_to_coordinate
def add_edges(json_obj): def add_edges(json_obj):
# TODO(daming-lu): should try to de-duplicate node's out-edge # TODO(daming-lu): should try to de-duplicate node's out-edge
# Currently it is counted twice: 1 as out-edge, 1 as in-edge # Currently it is counted twice: 1 as out-edge, 1 as in-edge
...@@ -295,9 +348,9 @@ def transform_for_echars(model_json): ...@@ -295,9 +348,9 @@ def transform_for_echars(model_json):
} }
}; };
paraSymbolSize = [95, 45]; paraSymbolSize = [95, 45]
paraSymbol = 'rect'; paraSymbol = 'rect'
opSymbolSize = [50, 50]; opSymbolSize = [50, 50]
option = { option = {
"title": { "title": {
...@@ -312,7 +365,7 @@ def transform_for_echars(model_json): ...@@ -312,7 +365,7 @@ def transform_for_echars(model_json):
{ {
"type": "graph", "type": "graph",
"layout": "none", "layout": "none",
"symbolSize": 50, "symbolSize": 8,
"roam": True, "roam": True,
"label": { "label": {
"normal": { "normal": {
...@@ -343,8 +396,42 @@ def transform_for_echars(model_json): ...@@ -343,8 +396,42 @@ def transform_for_echars(model_json):
} }
option['title']['text'] = model_json['name'] option['title']['text'] = model_json['name']
node_links = get_node_links(model_json)
add_level_to_node_links(node_links)
level_to_all = get_level_to_all(node_links, model_json)
node_to_coordinate, input_to_coordinate, output_to_coordinate = level_to_coordinate(level_to_all)
inputs = model_json['input']
nodes = model_json['node'] nodes = model_json['node']
outputs = model_json['output']
echars_data = list()
for in_idx in range(len(inputs)):
input = inputs[in_idx]
data = dict()
data['name'] = input['name']
data['x'] = input_to_coordinate[in_idx]['x']
data['y'] = input_to_coordinate[in_idx]['y']
echars_data.append(data)
for node_idx in range(len(nodes)):
node = nodes[node_idx]
data = dict()
data['name'] = node['name']
data['x'] = node_to_coordinate[node_idx]['x']
data['y'] = node_to_coordinate[node_idx]['y']
echars_data.append(data)
for out_idx in range(len(outputs)):
output = outputs[out_idx]
data = dict()
data['name'] = output['name']
data['x'] = output_to_coordinate[out_idx]['x']
data['y'] = output_to_coordinate[out_idx]['y']
echars_data.append(data)
option['series'][0]['data'] = echars_data
option['series'][0]['links'] = get_links(model_json)
return option return option
...@@ -360,12 +447,10 @@ def load_model(model_pb_path): ...@@ -360,12 +447,10 @@ def load_model(model_pb_path):
reorganize_inout(model_json, 'input') reorganize_inout(model_json, 'input')
reorganize_inout(model_json, 'output') reorganize_inout(model_json, 'output')
rename_model(model_json) rename_model(model_json)
add_links(model_json) # debug_print(model_json)
debug_print(model_json) options = transform_for_echars(model_json)
node_links = get_node_links(model_json) # debug_print(options)
add_level_to_node_links(node_links) return json.dumps(options, sort_keys=True, indent=4, separators=(',', ': '))
get_level_to_all(node_links, model_json)
return json.dumps(model_json, sort_keys=True, indent=4, separators=(',', ': '))
if __name__ == '__main__': if __name__ == '__main__':
...@@ -374,4 +459,4 @@ if __name__ == '__main__': ...@@ -374,4 +459,4 @@ if __name__ == '__main__':
current_path = os.path.abspath(os.path.dirname(sys.argv[0])) current_path = os.path.abspath(os.path.dirname(sys.argv[0]))
# json_str = load_model(current_path + "/mock/inception_v1_model.pb") # json_str = load_model(current_path + "/mock/inception_v1_model.pb")
json_str = load_model(current_path + "/mock/squeezenet_model.pb") json_str = load_model(current_path + "/mock/squeezenet_model.pb")
# print(json_str) print(json_str)
...@@ -7,7 +7,7 @@ from optparse import OptionParser ...@@ -7,7 +7,7 @@ from optparse import OptionParser
from flask import (Flask, Response, redirect, request, send_file, from flask import (Flask, Response, redirect, request, send_file,
send_from_directory) send_from_directory)
import graph import graph as vdl_graph
import lib import lib
import storage import storage
import visualdl.mock.data as mock_data import visualdl.mock.data as mock_data
...@@ -169,9 +169,9 @@ def histogram(): ...@@ -169,9 +169,9 @@ def histogram():
@app.route('/data/plugin/graphs/graphs') @app.route('/data/plugin/graphs/graphs')
def graph(): def graph():
# run = request.args.get('run') # run = request.args.get('run')
# model_json = graph.load_model("") # model_json_str = mock_data.graph_data()
model_json_str = mock_data.graph_data() # model_json = json.loads(model_json_str)
model_json = json.loads(model_json_str) model_json = vdl_graph.load_model(server_path + "/mock/squeezenet_model.pb")
result = gen_result(0, "", model_json) result = gen_result(0, "", model_json)
return Response(json.dumps(result), mimetype='application/json') return Response(json.dumps(result), mimetype='application/json')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册