更新时间:2023-11-23 07:54:28
使用model.save()保存所需的内容,清除tf会话,然后再次加载以解决此问题(如@NatthaphonHongcharoen所建议(在注释中):
Saving the desired with model.save() , clearing tf session and then loading it again fixed the issue(as suggested @NatthaphonHongcharoen (in the comments):
model.save(model_file)
del model
keras.backend.clear_session()
model = keras.models.load_model(model_file)
现在在tensorflow中导出的图仅显示所需的图层,冻结的图将生成较小的.pb文件.
Now the exported graph in tensorflow shows only the desired layers and the frozen graph generates a smaller .pb file.
然而,即使使用基础模型的单层并添加编译器仍然说的Dense层,仍然存在另一个问题
However another issue persists, even using a single layer of the base model and adding a Dense layer the compiler still says
设备上的内存不足,无法运行模型.
Not enough on-device memory to run model.
但这是一个没有直接在这个问题中问到的问题.
But that is a different issue not directly asked in this question.