Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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

and it gives me this error, with 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.

Anyone could help? Thanks!

Luca

like image 411
Luca Avatar asked Feb 25 '16 09:02

Luca


1 Answers

In was officially deprecated and there was a planed replacement. During a few days, it was removed from Theano development version. 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.

This was fixed. So now, update to Theano 0.8 or use the current development version of Theano and it should work correctly.

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.

like image 174
nouiz Avatar answered Nov 02 '22 00:11

nouiz