Skip to content

Commit

Permalink
Added edges to graph. Also added script to download mock models (#39)
Browse files Browse the repository at this point in the history
* Add edges to graph. Add squeezenet to mock data.

* rm json

* rm pb files and add links to them

* Add edges to graph. Add squeezenet to mock data.

rm json

rm pb files and add links to them

* added download script

* typo
  • Loading branch information
daming-lu authored Dec 28, 2017
1 parent 00ec2f4 commit b079592
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
29 changes: 28 additions & 1 deletion server/visualdl/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,31 @@ def reorganize_inout(json_obj, key):
json_obj[key][index] = var_new


def add_edges(json_obj):
json_obj['edges'] = []
label_incrementer = 0

for node_index in range(0, len(json_obj['node'])):
cur_node = json_obj['node'][node_index]

# input edges
for source in cur_node['input']:
json_obj['edges'].append({
'source': source,
'target': 'node_' + str(node_index),
'label': 'label_' + str(label_incrementer)
})
label_incrementer += 1

# output edge
json_obj['edges'].append({
'source': 'node_' + str(node_index),
'target': cur_node['output'][0],
'label': 'label_' + str(label_incrementer)
})
label_incrementer += 1


def load_model(model_pb_path):
model = onnx.load(model_pb_path)
graph = model.graph
Expand All @@ -38,12 +63,14 @@ def load_model(model_pb_path):
json_obj = json.loads(json_str)
reorganize_inout(json_obj, 'input')
reorganize_inout(json_obj, 'output')
add_edges(json_obj)
return json.dumps(json_obj, sort_keys=True, indent=4, separators=(',', ': '))


if __name__ == '__main__':
import os
import sys
current_path = os.path.abspath(os.path.dirname(sys.argv[0]))
json_str = load_model(current_path + "/mock/inception_v1.pb")
# json_str = load_model(current_path + "/mock/inception_v1_model.pb")
json_str = load_model(current_path + "/mock/squeezenet_model.pb")
print(json_str)
8 changes: 8 additions & 0 deletions server/visualdl/mock/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Note
Test data squeezenet and inception_v1 are from onnx/models.

https://github.com/onnx/models

squeezenet has 53 inputs, 66 nodes and 1 output.

inception_v1 has 117 inputs, 143 nodes and 1 output.
20 changes: 20 additions & 0 deletions server/visualdl/mock/download_mock_models.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

# Download inception_v1 model
curl -LOk https://s3.amazonaws.com/download.onnx/models/inception_v1.tar.gz

tar -xvzf inception_v1.tar.gz
cp inception_v1/model.pb inception_v1_model.pb

rm -rf inception_v1
rm inception_v1.tar.gz


# Download squeezenet model
curl -LOk https://s3.amazonaws.com/download.onnx/models/squeezenet.tar.gz

tar -xvzf squeezenet.tar.gz
cp squeezenet/model.pb squeezenet_model.pb

rm -rf squeezenet
rm squeezenet.tar.gz

Binary file removed server/visualdl/mock/inception_v1.pb
Binary file not shown.

0 comments on commit b079592

Please sign in to comment.