如何获得 keras 保存模型的权重

问题描述

我用 Keras 构建了一个模型来对文本进行分类,它可以按我的意愿工作。最后我保存了 Keras 模型及其权重。 在下一步中,我加载模型并对新文本进行分类。现在我想知道每个单词在新文本中的权重是多少。有人有经验吗?

vocab = util.data_reader.load_dict('./dict/','vocab')
text = "a sample text."
numbers = util.word_index.generate_index_vector(text,vocab,50)

new_model = tf.keras.models.load_model('./training')
weights = new_model.load_weights('./training/')

ints = list()
ints.append(numbers)
print(new_model.predict(ints))

loss,acc = new_model.evaluate(ints,[[1,0]],verbose=2)
print('Restored model,accuracy: {:5.2f}%'.format(100 * acc))

print(new_model.predict(ints).shape)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)