the computational graph needed to compute the outputs报错解决
theano是老古董了,但是鑒于既然碰到了、解決了,那就記錄下來吧,方便后來者.
環境:
ubuntu18.10
jupyter3.6(終端運行下面的代碼的話,會無法顯示圖形的)
#---------------------------------------------------
完整的故障代碼如下:
import theano import numpy as np import theano.tensor as T from IPython.display import Image from IPython.display import displayW = T.dmatrix('W') V = T.dmatrix('V') x = T.dvector('x') #------------------------------------------------------- f = T.dot(x,W) VJ = T.Lop(f,W,V) result= theano.function([V,W,x], VJ) display(Image(theano.printing.pydotprint(result,return_image=True, var_with_name_simple=True)))報錯如下:
UnusedInputError: theano.function was asked to create a function computing outputs given certain inputs, but the provided input variable at index 1 is not part of the computational graph needed to compute the outputs: W.----------------------------------------------------解決方案1------------------------------------------------------------------
直接修改目標函數,讓f對W求導后仍然有W的存在
運行結果如下(這個圖就是上面報錯信息中提到的graph):
----------------------------------------------------解決方案2------------------------------------------------------------------
不要輸入W,因為f=x?wf=x·wf=x?w對w求導后,w就沒用了,所以去掉theano.function后面的括號中的W
運行結果如下:
#########################################################################
好了,說下這個報錯怎么回事,大意是:
f=x?wf=x·wf=x?w,
f′=xf'=xf′=x
也就是說求導后w不再被需要了,在上面的graph中沒有了,所以再輸入就報錯了.
有的人會反駁,上面的例子是Lop,如果改成Rop的話,theano.function中填入W為什么不報錯呢?
這個只能理解為theano的優化問題了 ,可以參考:
https://stackoverflow.com/questions/35422047/matrix-value-not-needed-for-lop
theano已經停止更新了,沒必要再深究,解決問題就好.
總結
以上是生活随笔為你收集整理的the computational graph needed to compute the outputs报错解决的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Jacobian vector prod
- 下一篇: theano中的Rop和Lop的详细解释