很抱歉没有发布完整的代码片段——代码非常大而且分散,所以希望这可以说明我的问题。我有这些:
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
没有使用,那就忽略了它。我走错路了吗?我基本上只想用dropout训练一个神经网络,但在评估时不使用dropout。你知道吗
为什么用“=”号?我认为,它使train\u模式不可读,我的代码可以很好地通过编写:
givens = {train_mode:1}
相关问题 更多 >
编程相关推荐