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
和
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'))
但是我得到的错误是:
TypeError: The added layer must be an instance of class Layer. Found: <tensorflow.python.keras.layers.cudnn_recurrent.CuDNNLSTM object at 0x140869be0>
我有:从keras.layers导入keras。从keras.layers导入Input,LSTM,Dense,TimeDistributed,Activation,BatchNormalization,Dropout,Bidirectional。 [您正在
keras
和tf.keras
库之间混合导入,它们不是同一库,因此不支持这样做。