[英]How to save&restore DNNClassifier trained in TensorFlow python; iris example
[英]how to store/save and restore tensorflow DNNClassifier(No variables to save)
我在tensorflow上训练了一个深度神经网络并用来预测一些例子但是,当我尝试使用train.Saver()
保存它时,我得到错误:“没有要保存的变量”
已经尝试过train.Saver
这样:
tf.train.Saver(classi.get_variable_names())
但仍然没有运气,有什么建议吗?
所以我遇到了同样的问题(Estimators还没有保存/恢复功能)。 我试过保存和CheckpointSaver
试图保存检查点,但事实证明它更简单; 只需在实例化Estimator时指定model_dir
。 这将通过创建具有相同model_dir
的Estimator自动保存可以恢复的检查点。 这里有Estimators的文档。
由于@ilblackdragon该解决方案在这里 。
以下是来自tf.variable文档的代码示例,可能会澄清:
# Create some variables.
v1 = tf.Variable(..., name="v1")
v2 = tf.Variable(..., name="v2")
...
# Add an op to initialize the variables.
init_op = tf.initialize_all_variables()
# Add ops to save and restore all the variables.
saver = tf.train.Saver()
# Later, launch the model, initialize the variables, do some work, save the
# variables to disk.
with tf.Session() as sess:
sess.run(init_op)
# Do some work with the model.
..
# Save the variables to disk.
save_path = saver.save(sess, "/tmp/model.ckpt")
print("Model saved in file: %s" % save_path)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.