Keras - ImportError: cannot import name 'CuDNNLSTM'

Marvin Lerousseau picture Marvin Lerousseau · Dec 17, 2017 · Viewed 16.1k times · Source

I am trying to use the CuDNNLSTM Keras cell to improve training speed for a recurrent neural network (doc here).

When I run:

from keras.layers import Bidirectional, CuDNNLSTM

I get this error:

ImportError: cannot import name 'CuDNNLSTM'

My configuration is Keras 2.0.8, python 3.5, tensorflow-gpu 1.4.0 (all managed by Anaconda) and I have both CUDA 8.0 and cudnn 6.0 installed that should be OK with the nvidia dependencies of tensorflow (here). My code setup makes Keras effectively use tensorflow backend, and every layer except the ones starting with CuDNN* work fine.

Anyone has an idea about the source of this import error ?

Answer

Marvin Lerousseau picture Marvin Lerousseau · Dec 17, 2017

It turns out keras 2.0.8 doesn't have the code for these kind of layers that came in more recent versions.

I used pip to upgrade to the lastest version:

pip install --upgrade keras

and it all works now.