我正在使用安装了 Theano 库(更新版本)的 Python 2.7,我在定义 Theano 函数的输入参数方面遇到了问题。
代码是:
corruption_level = T.scalar('corruption') # % of corruption to use
learning_rate = T.scalar('lr') # learning rate to use
fn = theano.function(
inputs=[
index,
theano.In(corruption_level, value=0.2),
theano.In(learning_rate, value=0.1)
],
outputs=cost,
updates=updates,
givens={
self.x: train_set_x[batch_begin: batch_end]
}
)
取自这里:
http://deeplearning.net/tutorial/code/SdA.py
它给了我这个错误,Eclipse:
NotImplementedError: In() instances and tuple inputs trigger the old
semantics, which disallow using updates and givens
所以,如果我以这种方式更改代码:
fn = theano.function(
inputs=[
index,
#theano.In(corruption_level, value=0.2),
#theano.In(learning_rate, value=0.1)
corruption_level,
learning_rate
],
outputs=cost,
updates=updates,
givens={
self.x: train_set_x[batch_begin: batch_end]
}
)
它有效,但我无法传递 corruption_level 和 learning_rate 的值。
有人可以帮忙吗?谢谢!
卢卡
最佳答案
In 已被正式弃用,并且有计划的替代品。在几天内,它从 Theano 开发版本中删除了。但后来我们意识到最好保留它并更改它并摆脱我们计划的替代品。
在那段时间里,Theano 想要的东西和深度学习教程之间也存在一些不一致。
这是固定的。所以现在,更新到 Theano 0.8 或使用 Theano 的当前开发版本,它应该可以正常工作。
也许有相关问题的其他人可能需要在几天内更新深度学习教程代码,它使用的是我们删除的计划替代品。
theano.In() 现在像您的问题一样工作。
关于python - 将输入参数传递给 Theano 函数的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35622784/