Theano2.1.5-基础知识之打印出theano的图
生活随笔
收集整理的這篇文章主要介紹了
Theano2.1.5-基础知识之打印出theano的图
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
來自:http://deeplearning.net/software/theano/tutorial/printing_drawing.html
Printing/Drawing Theano graphs
? ? Theano提供的函數theano.printing.pprint()?和?theano.printing.debugprint()?可以用來在編譯前和后打印一個graph到終端上。?pprint()?該函數更緊湊而且更偏向于數學形式,?debugprint()?更為的詳細。 Theano同樣提供pydotprint()?來生成一張有關該函數的圖片。更詳細的可以看看?printing – Graph Printing and Symbolic Print Statement.
note:當打印theano函數的時候,有時候會比較難讀懂。為了簡化過程,可以禁止一些theano優化,只要使用theano的flag:?optimizer_excluding=fusion:inplace. 不要在工作執行的時候使用這個flag,這會使得graph更慢而且使用更多的內存。
? ? 考慮邏輯回歸的例子:
友好的打印結果:
>>> theano.printing.pprint(prediction) 'gt((TensorConstant{1} / (TensorConstant{1} + exp(((-(x \\dot w)) - b)))), TensorConstant{0.5})'調試打印
預編譯圖:
>>> theano.printing.debugprint(prediction) Elemwise{gt,no_inplace} [@A] ''|Elemwise{true_div,no_inplace} [@B] ''| |DimShuffle{x} [@C] ''| | |TensorConstant{1} [@D]| |Elemwise{add,no_inplace} [@E] ''| |DimShuffle{x} [@F] ''| | |TensorConstant{1} [@D]| |Elemwise{exp,no_inplace} [@G] ''| |Elemwise{sub,no_inplace} [@H] ''| |Elemwise{neg,no_inplace} [@I] ''| | |dot [@J] ''| | |x [@K]| | |w [@L]| |DimShuffle{x} [@M] ''| |b [@N]|DimShuffle{x} [@O] ''|TensorConstant{0.5} [@P]編譯后的圖:
>>> theano.printing.debugprint(predict) Elemwise{Composite{GT(scalar_sigmoid((-((-i0) - i1))), i2)}} [@A] '' 4|CGemv{inplace} [@B] '' 3| |Alloc [@C] '' 2| | |TensorConstant{0.0} [@D]| | |Shape_i{0} [@E] '' 1| | |x [@F]| |TensorConstant{1.0} [@G]| |x [@F]| |w [@H]| |TensorConstant{0.0} [@D]|InplaceDimShuffle{x} [@I] '' 0| |b [@J]|TensorConstant{(1,) of 0.5} [@K]
graph的圖片打印
預編譯圖
>>> theano.printing.pydotprint(prediction, outfile="pics/logreg_pydotprint_prediction.png", var_with_name_simple=True) The output file is available at pics/logreg_pydotprint_prediction.png
編譯后的圖
>>> theano.printing.pydotprint(predict, outfile="pics/logreg_pydotprint_predict.png", var_with_name_simple=True)
The output file is available at pics/logreg_pydotprint_predict.png優化后的訓練圖: >>> theano.printing.pydotprint(train, outfile="pics/logreg_pydotprint_train.png", var_with_name_simple=True) The output file is available at pics/logreg_pydotprint_train.png
參考資料:
[1] 官網:http://deeplearning.net/software/theano/tutorial/printing_drawing.html
總結
以上是生活随笔為你收集整理的Theano2.1.5-基础知识之打印出theano的图的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Deadline来了,如何按时结题?
- 下一篇: innodb行锁理解