Shamoon
Shamoon

Reputation: 43559

Error loading CuDNNLSTM with Tensorflow 2.1.0

I have:

from keras.layers import Input, LSTM, Dense, TimeDistributed, Activation, BatchNormalization, Dropout, Bidirectional
from keras.models import Sequential
from keras.utils import Sequence
from tensorflow.compat.v1.keras.layers import CuDNNLSTM

and

        self.model.add(CuDNNLSTM(lstm1_size, input_shape=(
            seq_length, feature_dim), return_sequences=True))
        # self.model.add(BatchNormalization())
        self.model.add(Dropout(0.2))
        self.model.add(CuDNNLSTM(lstm2_size, return_sequences=True))
        self.model.add(Dropout(0.2))
        self.model.add(CuDNNLSTM(lstm3_size, return_sequences=True))
        self.model.add(Dropout(0.2))
        self.model.add(CuDNNLSTM(lstm4_size, return_sequences=True))
        self.model.add(Dropout(0.2))
        self.model.add(Dense(feature_dim, activation='linear'))

But the error I get is:

TypeError: The added layer must be an instance of class Layer. Found: <tensorflow.python.keras.layers.cudnn_recurrent.CuDNNLSTM object at 0x140869be0>

Upvotes: 0

Views: 5003

Answers (2)

user2554528
user2554528

Reputation:

If you are using tensorflow 2 you will need to include using the compat layer:

from tensorflow.compat.v1.keras.layers import CuDNNLSTM

as CuDNNLSTM doesn't exist on keras.layer (v2)

Upvotes: 4

Dr. Snoopy
Dr. Snoopy

Reputation: 56377

You are mixing imports between the keras and tf.keras libraries, these are not the same library, and doing this is not supported.

You need to make all imports from one of the libraries:

from keras.layers import Input, LSTM, Dense, TimeDistributed, Activation, BatchNormalization, Dropout, Bidirectional
from keras.models import Sequential
from keras.utils import Sequence
from keras.layers import CuDNNLSTM

Upvotes: 2

Related Questions