如何存储/保存和恢复tensorflow DNNClassifier(无变量保存)

时间:2016-07-14 07:30:04

标签: python machine-learning tensorflow

我在tensorflow上训练了一个深度神经网络并用来预测一些例子但是,当我尝试使用train.Saver()保存它时,我得到错误: “没有要保存的变量”

已经尝试train.Saver这样:

tf.train.Saver(classi.get_variable_names())

但仍然没有运气,有什么建议吗?

2 个答案:

答案 0 :(得分:4)

所以我遇到了同样的问题(Estimators还没有保存/恢复功能)。我尝试过储户和CheckpointSaver试图保存检查点,但事实证明它更简单;只需在实例化Estimator时指定model_dir。这将通过创建具有相同model_dir的Estimator来自动保存可以恢复的检查点。估算工具的文档here

感谢@ilblackdragon提供解决方案here

答案 1 :(得分:-1)

以下是tf.variable docs中可能澄清的代码示例:

# 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)
相关问题