Tensorflow 属性错误:模块';keras.utils.generic#u utils';没有属性';用模块对象填充dict;带着keras\u self\u的注意力
我正在创建一个带有注意层的LSTM网络,但是当我添加注意层时,我得到了一个错误:AttributeError:module'keras.utils.generic_utils'没有属性'populate_dict_with_module_objects' 这句话的意思是:从keras_self_attention导入SeqSelfAttention 这是我的代码:Tensorflow 属性错误:模块';keras.utils.generic#u utils';没有属性';用模块对象填充dict;带着keras\u self\u的注意力,tensorflow,keras,lstm,attention-model,Tensorflow,Keras,Lstm,Attention Model,我正在创建一个带有注意层的LSTM网络,但是当我添加注意层时,我得到了一个错误:AttributeError:module'keras.utils.generic_utils'没有属性'populate_dict_with_module_objects' 这句话的意思是:从keras_self_attention导入SeqSelfAttention 这是我的代码: def LSTMAttention(): inputs = Input(shape=(sequence_length, 1)
def LSTMAttention():
inputs = Input(shape=(sequence_length, 1))
x = LSTM(units=128, activation='tanh', recurrent_activation='sigmoid',
input_shape=(sequence_length, 1),
dropout=0.1, recurrent_dropout=0.1, return_sequences=True)(inputs)
attention_layer = SeqSelfAttention()(x)
x1 = LSTM(units=32, activation='tanh', recurrent_activation='sigmoid',
input_shape=(sequence_length, 1),
dropout=0.1, recurrent_dropout=0.1, return_sequences=False)(attention_layer)
dense_layer = Dense(32, activation='softmax')(x1)
outputs = Dense(2, activation='softmax')(dense_layer)
model = Model(inputs=inputs, outputs=outputs)
model.compile(loss='categorical_crossentropy', optimizer=optimizers.RMSprop(),
metrics=['accuracy'])
model.summary()
return model
我希望有人能帮我解决这个错误 您的Keras和TensorFlow版本是什么?我使用TensorFlow 2.5.0和Keras 2.3.0该版本的Keras不支持TensorFlow 2.5您建议使用TensorFlow和Keras哪些版本?因为如果我安装TensorFlow==2.4.0和Keras==2.2.0,我会得到以下错误:AttributeError:module'TensorFlow.compat.v2.\uu internal\uuuuuuuu没有属性“tf2”