Lesson 1 - ImportError with Theano

When a script in the 1st jupiter note book runs it gives me “ImportError: cannot import name opt” even though it is literally in the same folder.

C:\Users\student\Anaconda2\lib\site-packages\theano\tensor\__init__.py in <module>()
 13     TensorConstantSignature, TensorConstant)
 14 

—> 15 from theano.tensor import opt
16 from theano.tensor import opt_uncanonicalize
17 from theano.tensor import blas

I can’t figure this one out.

I also have this problem.

Have you guys added the configuration file for theano and keras?

On Ubuntu you create
~/ .theanorc

[global]
    device = cuda
    floatX = float32
    [cuda]
    root = /usr/local/cuda-\<version\>

~/.keras/keras.json

{
“image_dim_ordering”: “th”,
“epsilon”: 1e-07,
“floatx”: “float32”,
“backend”: “theano”
}

If you are using windows then I don’t know the answer

How do I setup the theano arc? I don’t have any usr or local or cuda folders. I’m dual booting and am trying this on ubuntu. My own computer has cpu only and I haven’t set-up aws yet. Would that be need to be set to something else for cpu only right now until it connects to aws?

Also the error mysteriously changed from that to:

/home/daniel/anaconda2/lib/python2.7/site-packages/keras/backend/theano_backend.pyc in in_train_phase(x, alt)
   1172     elif _LEARNING_PHASE is 0:
   1173         return alt
-> 1174     x = theano.ifelse.ifelse(_LEARNING_PHASE, x, alt)
   1175     x._uses_learning_phase = True
   1176     return x

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

Just like someone else commented, a reboot fixed this problem…got a different one though - “To use MKL 2018 with Theano you MUST set “MKL_THREADING_LAYER=GNU” in your environement.”…off I go searching again :confused:

@digdeeper add the following line to ~/.bashrc file
export MKL_THREADING_LAYER=GNU

1 Like

@dcash

Have you installed the cuda and anaconda ?

You can follow this tutorial

Thank you, the env variable fixed it!

I’ve installed anaconda but not explicitly installed cuda. My own computer doesn’t have nvidia driver so I wanted to run on my own computer with cpu only before moving onto aws to save money.

I am using Ananaconda 2.7 on Ubuntu 16.04 LTS

I also got the same error after conda install from requirements.txt
For some of the guys the system reboot does solved the problem. For me the following steps solved the issue.

Uninstall theano. Then install theano requirement packages
$ conda install mkl nose sphinx pydot-ng
Then
$ conda install theano

Please refer http://deeplearning.net/software/theano_versions/dev/install_ubuntu.html for more details about theano installation.

I am having this problem also.

I’ve tried uninstalling theano to install the dependencies and reinstalling thano; I do have an environment variable set so that $MKL_THREADING_LAYER = GNU .

I’m just ramping up into the fast.ai course so my problem could be something obvious - I appreciate any suggestion of what to check!

Please read the thread below for details

I am pretty sure you’re right - the truth is that I don’t know where to find the course part 1 v2 notebooks. I am hoping to do the course on the AWS EC2 instance I have rather than paperspace.

i got the same problem and the better solution to me was to uninstall the existing version of mkl and install the 2017 version of mkl using conda conda install mkl=2017

1 Like

@kro

I would recommend switching to that course.