在Python中,有没有办法使用networkx以标准格式显示神经网络?
In Python, is there a way to use networkx to display a neural network in the standard format?
'standard format' 我的意思是输入和输出节点在它们自己的单独的行中,图像中它们之间的所有其他隐藏节点。正如您在下面看到的,我的输入节点是节点 0、1 和 2,我的输出节点是 3,我的隐藏节点是 4 和 5。这是我能得到的最好看的网络图。我尽量避免使用 keras,因为要让它在 anaconda 中工作是一件非常痛苦的事情。
我相信如果我知道用于显示神经网络的 'standard format' 图形类型的名称,会更容易。
如果有我遗漏的用于执行此任务的包,请告诉我。
以下是我现在如何让网络显示:
图表代码:
import networkx as nx
G = nx.MultiDiGraph()
ed = N2.dna.get_conns(weight=True)
G.add_weighted_edges_from(ed)
nx.draw_planar(G,with_labels=True,font_weight='bold')
ed
Out[32]:
[[0, 3, -1],
[1, 3, -1],
[2, 3, -1],
[0, 4, -1],
[4, 5, -1],
[5, 3, 100],
[2, 4, 10]]
希望我没看错。
可能的解决方案:
import networkx as nx
from networkx.drawing.nx_agraph import graphviz_layout
G = nx.DiGraph()
ed = [[0, 4, -1],
[0, 5, -1],
[1, 4, -1],
[1, 5, -1],
[2, 4, -1],
[2, 5, 10],
[4, 3, -1],
[5, 3, 100]]
G.add_weighted_edges_from(ed)
pos = graphviz_layout(G, prog='dot', args="-Grankdir=LR")
nx.draw(G,with_labels=True,pos=pos, font_weight='bold')
'standard format' 我的意思是输入和输出节点在它们自己的单独的行中,图像中它们之间的所有其他隐藏节点。正如您在下面看到的,我的输入节点是节点 0、1 和 2,我的输出节点是 3,我的隐藏节点是 4 和 5。这是我能得到的最好看的网络图。我尽量避免使用 keras,因为要让它在 anaconda 中工作是一件非常痛苦的事情。
我相信如果我知道用于显示神经网络的 'standard format' 图形类型的名称,会更容易。
如果有我遗漏的用于执行此任务的包,请告诉我。
以下是我现在如何让网络显示:
图表代码:
import networkx as nx
G = nx.MultiDiGraph()
ed = N2.dna.get_conns(weight=True)
G.add_weighted_edges_from(ed)
nx.draw_planar(G,with_labels=True,font_weight='bold')
ed
Out[32]:
[[0, 3, -1],
[1, 3, -1],
[2, 3, -1],
[0, 4, -1],
[4, 5, -1],
[5, 3, 100],
[2, 4, 10]]
希望我没看错。
可能的解决方案:
import networkx as nx
from networkx.drawing.nx_agraph import graphviz_layout
G = nx.DiGraph()
ed = [[0, 4, -1],
[0, 5, -1],
[1, 4, -1],
[1, 5, -1],
[2, 4, -1],
[2, 5, 10],
[4, 3, -1],
[5, 3, 100]]
G.add_weighted_edges_from(ed)
pos = graphviz_layout(G, prog='dot', args="-Grankdir=LR")
nx.draw(G,with_labels=True,pos=pos, font_weight='bold')