微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

AttributeError: 模块“keras.utils.generic_utils”没有带有 keras_self_attention 的属性“populate_dict_with_module_objects”

如何解决AttributeError: 模块“keras.utils.generic_utils”没有带有 keras_self_attention 的属性“populate_dict_with_module_objects”

我正在制作一个带有注意力层的 LSTM 网络,但是当我添加注意力层时出现错误:AttributeError: module 'keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects'

它给出了一行中的错误:from keras_self_attention import SeqSelfAttention

这是我的代码

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,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

希望有人能帮我解决这个错误

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。