简体   繁体   English

将输入参数传递给Theano函数的正确方法是什么?

[英]What is the right way to pass inputs parameters to a Theano function?

I'm using Python 2.7 with Theano library installed (updated version) and I've got a problem with the inputs parameters, defining a Theano function. 我正在使用安装了Theano库的Python 2.7(更新版本),我对输入参数有问题,定义了Theano函数。

The code is: 代码是:

    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]
        }
    )

It's taken from here: 它取自这里:

http://deeplearning.net/tutorial/code/SdA.py http://deeplearning.net/tutorial/code/SdA.py

and it gives me this error, with Eclipse: 它给了我这个错误,使用Eclipse:

NotImplementedError: In() instances and tuple inputs trigger the old
semantics, which disallow using updates and givens

So, if I change the code in this way: 所以,如果我以这种方式更改代码:

        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]
            }
        )

it works but I can't pass the value of corruption_level and learning_rate. 它有效,但我无法传递corruption_level和learning_rate的值。

Anyone could help? 有人可以帮忙吗? Thanks! 谢谢!

Luca 卢卡

In was officially deprecated and there was a planed replacement. 在正式弃用,并有一个计划更换。 During a few days, it was removed from Theano development version. 几天之内,它已从Theano开发版中删除。 But then we realized that it was better to keep it and change it and get rid our planned replacement. 但后来我们意识到最好保留它并改变它并摆脱我们计划的更换。

During that time, there was also some inconsistency between the what Theano wanted and the Deep Learning tutorial. 在那段时间里,Theano想要的内容与深度学习教程之间也存在一些不一致。

This was fixed. 这是固定的。 So now, update to Theano 0.8 or use the current development version of Theano and it should work correctly. 现在,更新到Theano 0.8或使用Theano的当前开发版本,它应该正常工作。

Maybe other people having related problems could need to update there Deep Learning tutorial code as for a few days, it was using the planned replacement that we removed. 也许其他有相关问题的人可能需要更新深度学习教程代码几天,它使用我们删除的计划替换。

theano.In() now work as in your question. theano.In()现在像你的问题一样工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM