Search code examples
pythonbashpiptheano

Theano AttributeError: 'module' object has no attribute 'relu'


I want to use theano.tensor.nnet.relu, but I keep getting this error:

AttributeError: 'module' object has no attribute 'relu' 

I have already updated theano via sudo pip install --upgrade theano command as described in theano's documentation, also i've tried sudo pip install --upgrade --no-deps theano. Neither worked, I still get the same error.

I was trying to do theano -v to confirm that I have installed the latest version but then I get the following error: -bash: theano: command not found

So my two questions here are:

  • How can I see theano's version?
  • Am I doing something wrong when updating theano? How can I solve the error first mentioned?

Solution

  • relu is available for theano >= 0.7.1. My guess is that pip linked to theano==0.7.

    You can check theano version with pip freeze:

    pip freeze | grep Theano
    

    So you have to install latest theano with pointing pip to theano git repo :

    pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git
    

    Also note that relu is function and not module, so to access it you have to use one of imports below:

    from theano.tensor.nnet import relu # access `relu` as is ..
    import theano.tensor.nnet as theano_nnet #access `relu` as `theano_nnet.relu`