April 2020
Intermediate to advanced
552 pages
6h 13m
Japanese
前ステップでは、DOT言語の記述方法を学びました。ここでは、その知識を基に、DeZeroの計算グラフをDOT言語に変換します。具体的には、DeZeroで行った計算をDOT言語へと変換する関数を実装していきます。
私たちは、計算グラフを可視化する関数をget_dot_graphという名前で、dezero/utils.pyに実装することにします。まずは、その関数の使用例を先に示します。
importnumpyasnpfromdezeroimportVariablefromdezero.utilsimportget_dot_graphx0=Variable(np.array(1.0))x1=Variable(np.array(1.0))y=x0+x1# 何らかの計算# 変数に名前を付けるx0.name='x0'x1.name='x1'y.name='y'txt=get_dot_graph(y,verbose=False)(txt)# dotファイルとして保存withopen('sample.dot','w')aso:o.write(txt)
実行結果
digraph g { 4423761088 [label="y", color=orange, style=filled] 4423742632 [label="Add", color=lightblue, style=filled, shape=box] 4403357456 -> 4423742632 4403358016 -> 4423742632 4423742632 ...Read now
Unlock full access