17

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 ?

talonmies
  • 70,661
  • 34
  • 192
  • 269
Marvin Lerousseau
  • 451
  • 1
  • 5
  • 10

4 Answers4

16

And for Tensorflow-2: You can just use LSTM with no activation function and it will automatically use the CuDNN version

Archy Will He 何魏奇
  • 9,589
  • 4
  • 34
  • 50
6

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.

Marvin Lerousseau
  • 451
  • 1
  • 5
  • 10
2

These layers have been deprecated in the latest versions.
For a detailed tutorial you can see this Keras guide

1

in conda it will be (as of nov 2019)

conda config --add channels conda-forge
conda install keras==2.3.0
Archy Will He 何魏奇
  • 9,589
  • 4
  • 34
  • 50