简体   繁体   English

无法加载 tensorflow 已保存 model 返回

[英]Cannot load tensorflow saved model back

I am following this tutorial: https://www.tensorflow.org/text/tutorials/text_generation#export_the_generator我正在关注本教程: https://www.tensorflow.org/text/tutorials/text_generation#export_the_generator

And i use the following code to save the model and load it back, the saving part works but when i load the model and use "remodel.summary()" i get the following error我使用以下代码保存 model 并将其加载回来,保存部分有效但是当我加载 model 并使用“remodel.summary()”时出现以下错误

tf.saved_model.save(one_step_model, 'one_step')
remodel = tf.saved_model.load('one_step')

Error -> AttributeError: '_UserObject' object has no attribute 'summary'

I believe this means the model wasn't loaded?我相信这意味着 model 没有加载? why is that happeneing?为什么会这样? the model does get saved properly and i followed everything in the tutorial model 确实得到了正确保存,我遵循了教程中的所有内容

Also I have another question, doing this would make it possible for me to re-use the model without needing to train it again right?我还有另一个问题,这样做可以让我重新使用 model 而无需再次训练它,对吗?

Try this way:试试这样:

model = create_model()
model.fit(train_images, train_labels, epochs=5)

model.save('saved_model/my_model')
new_model = tf.keras.models.load_model('saved_model/my_model')


new_model.summary()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM