簡體   English   中英

Theano的function()報告該圖不需要我的'givens'值

[英]Theano's function() reports that my `givens` value is not needed for the graph

很抱歉沒有發布完整的代碼段-代碼很大並且分散了,因此希望可以說明我的問題。 我有這些:

train = theano.function([X], output, updates=update_G,
                        givens={train_mode=:np.cast['int32'](1)})

test = theano.function([X], output, updates=update_G,
                       givens={train_mode=:np.cast['int32'](0)})

我的理解, givens將輸入的值train_mode (即1 / 0 ),無論它來計算輸出真實需要。

output在以下行中計算:

     ...
     network2 = Net2()
     # This is sort of a dummy variable so I don't get a NameError when this
     # is called before `theano.function()` is called. Not sure if this is the
     # right way to do this.
     train_mode = T.iscalar('train_mode')
     output = loss(network1.get_outputs(network2.get_outputs(X, train_mode=train_mode)),something).mean()

 ....
 class Net2(): 
      def get_outputs(self, x, train_mode):
           from theano.ifelse import ifelse
           import theano.tensor as T
           my_flag = ifelse(T.eq(train_mode, 1), 1, 0)
           return something if my_flag else something_else

因此, train_mode用作其中一個嵌套函數的參數,並且我希望使用它來區分traintest因為我想稍微不同地處理它們。

但是,當我嘗試運行此命令時,出現以下錯誤:

theano.compile.function_module.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: <TensorType(int32, scalar)>.To make 
this error into a warning, you can pass the parameter 
on_unused_input='warn' to theano.function. To disable it completely, use 
on_unused_input='ignore'.    

如果我刪除了givens的參數,錯誤消失,所以我的理解Theano認為,我的train_mode是沒有必要的計算function() 我可以按照他們的建議使用on_unusued_input='ignore' ,但是如果他們認為未使用它,那只會忽略我的train_mode 我會以這種錯誤的方式走嗎? 我基本上只是想訓練一個帶有輟學的神經網絡,但在評估時不使用輟學。

為什么使用“ =”符號? 我認為,這使train_mode不可讀,我的代碼通過編寫工作得很好: givens = {train_mode:1}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM