machine-learning - 如何从上次保存的状态开始重新训练 Tensorflow seq2seq 模型?

标签 machine-learning nlp tensorflow

我对tensorflow完全陌生,我正在使用他们的seq2seq翻译示例。我查看了translate.py中的代码,训练是在无限循环中完成的,它时不时地将检查点保存在文件translate.ckpt中。

那么,如果我停止训练并想稍后从上次保存的状态重新启动它,我该怎么做?

谢谢

最佳答案

您需要从文件中恢复变量,而不是在 session 中启动变量:

saver = tf.train.Saver()
with tf.Session() as sess:
  # Restore variables from disk.
  saver.restore(sess, "/tmp/model.ckpt")
  print("Model restored.")
  # Do some work with the model

请注意,您的模型只是变量的值。为了恢复它们,您需要一个具有相同变量名称的图表。可能还需要执行一些操作才能计算结果。

在这里阅读更多相关信息:

https://www.tensorflow.org/versions/r0.11/how_tos/variables/index.html#restoring-variables

关于machine-learning - 如何从上次保存的状态开始重新训练 Tensorflow seq2seq 模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40824545/

相关文章:

machine-learning - 在查找 k 簇方面比 Elbow 更有用的另一个函数

machine-learning - 用于理解上下文单词的自然语言处理技术

tensorflow - 在分布式 TensorFlow 中,是否可以在不同的工作线程之间共享相同的队列?

tensorflow - 找不到 tensorflow 的匹配分布

python - Tensorflow2.0 Keras : Is dropout disabled during testing by default?

python - keras model.fit_generator() 比 model.fit() 慢几倍

machine-learning - 使用用户输入测试预测模型

python - 如何通过重复索引拆分数据帧并进行枚举?

machine-learning - 训练SVM模型后如何加载未标记的数据进行情感分类?

python - 训练自定义瑞典 spacy 模型