MCPcopy Create free account
hub / github.com/M-Nauta/ProtoTree / gen_vis

Function gen_vis

util/visualize.py:16–36  ·  view source on GitHub ↗
(tree: ProtoTree, folder_name: str, args: argparse.Namespace, classes:tuple)

Source from the content-addressed store, hash-verified

14
15
16def gen_vis(tree: ProtoTree, folder_name: str, args: argparse.Namespace, classes:tuple):
17 destination_folder=os.path.join(args.log_dir,folder_name)
18 upsample_dir = os.path.join(os.path.join(args.log_dir, args.dir_for_saving_images), folder_name)
19 if not os.path.isdir(destination_folder):
20 os.mkdir(destination_folder)
21 if not os.path.isdir(destination_folder + '/node_vis'):
22 os.mkdir(destination_folder + '/node_vis')
23
24 with torch.no_grad():
25 s = 'digraph T {margin=0;ranksep=".03";nodesep="0.05";splines="false";\n'
26 s += 'node [shape=rect, label=""];\n'
27 s += _gen_dot_nodes(tree._root, destination_folder, upsample_dir, classes)
28 s += _gen_dot_edges(tree._root, classes)[0]
29 s += '}\n'
30
31 with open(os.path.join(destination_folder,'treevis.dot'), 'w') as f:
32 f.write(s)
33
34 from_p = os.path.join(destination_folder,'treevis.dot')
35 to_pdf = os.path.join(destination_folder,'treevis.pdf')
36 check_call('dot -Tpdf -Gmargin=0 %s -o %s'%(from_p, to_pdf), shell=True)
37
38def _node_vis(node: Node, upsample_dir: str):
39 if isinstance(node, Leaf):

Callers 1

run_treeFunction · 0.90

Calls 2

_gen_dot_nodesFunction · 0.85
_gen_dot_edgesFunction · 0.85

Tested by

no test coverage detected