-
-
Save szagoruyko/46c64163f65d94da7ecf53214e2128e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from graphviz import Digraph | |
dot = Digraph(comment='LRP', node_attr={'style': 'filled', 'shape': 'box'})#, 'fillcolor': 'lightblue'}) | |
seen = set() | |
def add_nodes(var): | |
if var not in seen: | |
if isinstance(var, Variable): | |
dot.node(str(id(var)), str(var.size()), fillcolor='lightblue') | |
else: | |
dot.node(str(id(var)), str(type(var))) | |
seen.add(var) | |
if hasattr(var, 'previous_functions'): | |
for u in var.previous_functions: | |
dot.edge(str(id(u[0])), str(id(var))) | |
add_nodes(u[0]) | |
add_nodes(R.creator) | |
dot.save('/tmp/lrp.dot') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment