Python 在张量流中保存模型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38939081/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 21:38:49  来源:igfitidea点击:

Saving model in tensorflow

pythonpython-2.7tensorflow

提问by user3425082

Tensorflow allows us to save/load model's structure, using method tf.train.write_graph, so that we can restore it in the future to continue our training session. However, I'm wondering that if this is necessary because I can create a module, e.g GraphDefinition.py, and use this module to re-create the model. So, which is the better way to save the model structure or are there any rule of thumb that suggest which way should I use when saving a model?

Tensorflow 允许我们使用 tf.train.write_graph 方法保存/加载模型的结构,以便我们可以在将来恢复它以继续我们的训练课程。但是,我想知道这是否有必要,因为我可以创建一个模块,例如 GraphDefinition.py,并使用该模块重新创建模型。那么,哪个是保存模型结构的更好方法,或者是否有任何经验法则建议我在保存模型时应该使用哪种方式?

回答by Alex Joz

First of all you have to understand, that tensorflow graph does not have current weights in it (until you save them manually there) and if you load model structure from graph.pb, you will start you train from the very beginning. But if you want to continue train or use your trained model, you have to save checkpoint (using tf Saver) with the values of the variables in it, not only the structure. Check out this tread: Tensorflow: How to restore a previously saved model (python)

首先你必须明白,张量流图中没有当前的权重(直到你手动将它们保存在那里),如果你从 graph.pb 加载模型结构,你将从一开始就开始训练。但是如果你想继续训练或使用你训练过的模型,你必须保存检查点(使用 tf Saver),其中包含变量的值,而不仅仅是结构。看看这个步骤:Tensorflow:如何恢复以前保存的模型(python)