[Solved] Theano Error In Python – Uncover The Most Common And Quick Solutions

This is fairly standard openCV code where a loop will detect faces with a haar cascade classifier and then there is a deep learning model that will detect the emotion in the face. The model was created from the 2013 Kaggle dataset, and I downloaded this model from this GitHub account if someone wants to try out the code. fer2013_mini_XCEPTION.119-0.65.hdf5 Just place a models folder in your directory and rename it to model.h5

https://github.com/oarriaga/face_classification/tree/master/trained_models

The code works just fine with Tensorflow but when I run the program KERAS_BACKEND=theano python haarMOD.py .

I get an error that is maybe due to the BLAS library not linking properly

The error that pops up for me is line 17 model = load_model(MODELPATH) if on CPU, do you have a BLAS library installed Theano can link against? 

[Solved] I got the code to work on a Windows machine by editing the .json file on my C drive C:\Users\user\.keras to reference "theano" instead of "tenserflow"

{
    "floatx": "float32",
    "epsilon": 1e-07,
    "backend": "theano",
    "image_data_format": "channels_last"
}

And then adding in this bit of additional code

import theano
theano.config.optimizer="None"

Theano with Anaconda on Windows: how to setup BLAS?

I’ve used Anaconda to install Theano (and Keras) on Windows 7 64bit. Here are my steps.

  1. Install the latest Anaconda for Python 3.5
  2. conda install mingw libpython
  3. pip install Theano
  4. conda install pydot-ng
  5. pip install keras
  6. Edit .keras/keras.json to use “theano” instead of “tensorflow”.

Open Jupyter, copy and paste this code: https://github.com/fchollet/keras/blob/master/examples/cifar10_cnn.py It executes fine until the call to model.fit : imports, data download, model compilation all work.

Please note that I set data_augmentation to False.

The call to model.fit fails with the following error message:http://pastebin.com/Rq7HTc4H

This seems to be the problem:

AssertionError: AbstractConv2d Theano optimization failed: there is no implementation available supporting the requested options. Did you exclude both “conv_dnn” and “conv_gemm” from the optimizer? If on GPU, is cuDNN available and does the GPU support it? If on CPU, do you have a BLAS library installed Theano can link against?

I didn’t install BLAS myself, I thought that would be a part of Anaconda. Browsing the internet reveals similar problems. Apparently, you can prevent Theano from looking for a BLAS library by editing a .theanorc.txt file and adding “optimizer = None”: How to configure Theano on Windows?

I executed os.path.expanduser('~/.theanorc.txt'), verified that my .theanorc.txt is in the right place, added the optimier=None line, and tried the code again. No effect.

How can I configure Theano to work without BLAS? Or, even better, how can I install a BLAS library (preferably via Anaconda) ?

Apparently, you can edit the config during runtime:

import theano
theano.config.optimizer="None"

removes the problem.

This means that Theano doesn’t find my config file. I thought I had put it at the correct location, what might prevent Theano from finding it ?

Leave a Reply