如何存储/保存和恢复tensorflow dnnclassier(没有要保存的变量)

2024-09-25 00:30:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我训练了一个关于tensorflow的深层神经网络,并用来预测一些例子,但是,当我试图用^{}保存它时,我得到了一个错误: “没有要保存的变量”

已经尝试过train.Saver如下:

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

但还是不走运,有什么建议吗?在


Tags: getnamestftensorflow错误train神经网络variable
2条回答

下面是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)

所以我遇到了同样的问题(估计器还没有保存/恢复功能)。我尝试了savers和^{}来尝试保存检查点,但结果发现这要简单得多;在实例化估计器时只需指定model_dir。这将自动保存检查点,这些检查点可以通过创建具有相同model_dir的估计器来恢复。估计器文档here。在

感谢@ilblackdragon提供的解决方案here。在

相关问题 更多 >