【发布时间】: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 用作其中一个嵌套函数的参数,我用它来区分train 和test,因为我想处理它们的方式略有不同。
但是,当我尝试运行它时,我得到了这个错误:
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