Skip to content

Commit 32ccedb

Browse files
committed
fix graph_test, clean code
1 parent 5194061 commit 32ccedb

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

visualdl/server/graph.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def rename_variables(model, variables):
5454
+ '\nshape=' + str(new_shape)
5555
variable['name'] = new_name
5656
rename_edge(model, old_name, new_name)
57+
5758
rename_variables(model_json, model_json['input'])
5859
rename_variables(model_json, model_json['output'])
5960

@@ -79,19 +80,13 @@ def get_links(model_json):
7980
if name in node['input']:
8081
links.append({'source': name,
8182
"target": node['name']})
82-
# links.append({'source': name,
83-
# "target": node['name'],
84-
# "label": name})
8583

8684
for source_node in model_json['node']:
8785
for output in source_node['output']:
8886
for target_node in model_json['node']:
8987
if output in target_node['input']:
9088
links.append({'source': source_node['name'],
9189
'target': target_node['name']})
92-
# links.append({'source': source_node['name'],
93-
# 'target': target_node['name'],
94-
# 'label': output})
9590

9691
return links
9792

@@ -174,7 +169,6 @@ def add_level_to_node_links(node_links):
174169
assert in_level is not None
175170
if cur_level is None or in_level >= cur_level:
176171
node_links[idx]['level'] = in_level + 1
177-
# debug_print(node_links)
178172

179173

180174
def get_level_to_all(node_links, model_json):
@@ -249,7 +243,6 @@ def get_level_to_all(node_links, model_json):
249243
if level not in level_to_outputs:
250244
level_to_outputs[level] = list()
251245
level_to_outputs[level].append(out_idx)
252-
# debug_print(level_to_outputs)
253246

254247
level_to_all = dict()
255248

@@ -302,13 +295,9 @@ def get_coordinate(x_idx, y_idx):
302295
output_to_coordinate[out_idx] = get_coordinate(x_idx, level)
303296
x_idx += 1
304297

305-
# debug_print(node_to_coordinate)
306-
# debug_print(input_to_coordinate)
307-
# debug_print(output_to_coordinate)
308298
return node_to_coordinate, input_to_coordinate, output_to_coordinate
309299

310300

311-
312301
def add_edges(json_obj):
313302
# TODO(daming-lu): should try to de-duplicate node's out-edge
314303
# Currently it is counted twice: 1 as out-edge, 1 as in-edge

visualdl/server/graph_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def setUp(self):
99

1010
def test_graph_edges_squeezenet(self):
1111
json_obj = graph.to_IR_json(self.mock_dir + '/squeezenet_model.pb')
12+
json_obj = graph.add_edges(json_obj)
1213

1314
# 126 edges + 66 nodes (out-edge of each node is counted twice)
1415
self.assertEqual(len(json_obj['edges']), 126 + 66)
@@ -39,6 +40,7 @@ def test_graph_edges_squeezenet(self):
3940

4041
def test_graph_edges_inception_v1(self):
4142
json_obj = graph.to_IR_json(self.mock_dir + '/inception_v1_model.pb')
43+
json_obj = graph.add_edges(json_obj)
4244

4345
# 286 edges + 143 nodes (out-edge of each node is counted twice)
4446
self.assertEqual(len(json_obj['edges']), 286 + 143)

0 commit comments

Comments
 (0)