【问题标题】:Importing tf.train.Saver from another python file从另一个 python 文件导入 tf.train.Saver
【发布时间】:2016-02-25 08:15:31
【问题描述】:

我在 one.py 文件中使用 tf.train.Saver() 和以下代码。

saver = tf.train.Saver(tf.all_variables())
saver.save(sess,"checkpoint.data")

如何在另一个 python 文件中恢复 checkpoint.data

我使用了下面的代码,但是没有用。

from one import saver
import tensorflow as tf

with tf.Session() as sess:
    saver.restore(sess, "checkpoint.data")

【问题讨论】:

    标签: python tensorflow


    【解决方案1】:

    检查点文件(即'checkpoint.data')没有为 TensorFlow 提供足够的信息来重建您的模型结构。在您的第二个程序中,您需要重建与第一个程序中使用的相同的 TensorFlow 图。有几个选项可以做到这一点:

    • 将模型构建代码提取到 Python 函数中,并在每个程序中创建 tf.train.Saver 之前调用它。
    • 在您的第一个程序中使用saver.export_meta_graph() 写出图形结构和检查点,并在您的第二个程序中使用tf.train.import_meta_graph() 导入图形结构(并创建适当配置的tf.train.Saver 实例)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-09
      • 2021-04-17
      • 2017-09-12
      • 2018-11-06
      • 2018-04-22
      • 1970-01-01
      相关资源
      最近更新 更多