(tree: ProtoTree, folder_name: str, args: argparse.Namespace, classes:tuple)
| 14 | |
| 15 | |
| 16 | def 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 | |
| 38 | def _node_vis(node: Node, upsample_dir: str): |
| 39 | if isinstance(node, Leaf): |
no test coverage detected