【问题标题】:Theano's function() reports that my `givens` value is not needed for the graphTheano 的 function() 报告图表不需要我的 `givens` 值
【发布时间】:2017-03-01 12:32:33
【问题描述】:

很抱歉没有发布整个 sn-ps - 代码非常大而且分散,所以希望这可以说明我的问题。我有这些:

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。我是不是走错了路?我基本上只是想训练一个带有 dropout 的神经网络,但在评估时不使用 dropout。

【问题讨论】:

    标签: python neural-network deep-learning theano conv-neural-network


    【解决方案1】:

    为什么要使用“=”符号?我认为,它使 train_mode 不可读,我的代码通过以下方式运行良好: givens = {train_mode:1}

    【讨论】:

    • 抱歉,=: 打错了。我进行强制转换以保持类型一致,但是当我回到计算机时我会尝试不使用它。
    猜你喜欢
    • 1970-01-01
    • 2013-11-07
    • 2011-01-05
    • 1970-01-01
    • 1970-01-01
    • 2010-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多