【问题标题】:Restore TensorFlow model on different machine在不同的机器上恢复 TensorFlow 模型
【发布时间】:2018-11-17 23:22:56
【问题描述】:

我在 GPU 集群上训练了 TensorFlow 模型,并使用

保存了模型
saver = tf.train.Saver()
saver.save(sess, config.model_file, global_step=global_step)

现在我正在尝试使用

恢复模型
saver = tf.train.import_meta_graph('model-1000.meta')
saver.restore(sess,tf.train.latest_checkpoint(save_path))

用于评估,在不同的系统上。问题是saver.restore 产生以下错误:

    Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1664, in <module>
    main()
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1658, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1068, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/Users/jonpdeaton/Developer/BraTS18-Project/segmentation/evaluate.py", line 205, in <module>
    main()
  File "/Users/jonpdeaton/Developer/BraTS18-Project/segmentation/evaluate.py", line 162, in main
    restore_and_evaluate(save_path, model_file, output_dir)
  File "/Users/jonpdeaton/Developer/BraTS18-Project/segmentation/evaluate.py", line 127, in restore_and_evaluate
    saver.restore(sess, tf.train.latest_checkpoint(save_path))
  File "/Users/jonpdeaton/anaconda3/envs/BraTS/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1857, in latest_checkpoint
    if file_io.get_matching_files(v2_path) or file_io.get_matching_files(
  File "/Users/jonpdeaton/anaconda3/envs/BraTS/lib/python3.6/site-packages/tensorflow/python/lib/io/file_io.py", line 337, in get_matching_files
    for single_filename in filename
  File "/Users/jonpdeaton/anaconda3/envs/BraTS/lib/python3.6/site-packages/tensorflow/python/framework/errors_impl.py", line 519, in __exit__
    c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.NotFoundError: /afs/cs.stanford.edu/u/jdeaton/dfs/unet; No such file or directory

似乎有一些路径存储在模型或 checkpoint 文件中,形成了训练它的系统,在我正在评估的系统上不再有效。复制 model-X.metamodel-X.indexcheckpoint 文件后,如何在不同的机器上恢复模型(用于评估)?

【问题讨论】:

  • 使用绝对路径到元文件并保存路径,/home/jon/saved/model-1000.meta' 和 save_path=/home/jon/saved
  • @Eliethesaiyan 我是。
  • 可能与您恢复的模型无关,您能否发布完整的错误日志,错误指向完全相同的行吗?

标签: python tensorflow


【解决方案1】:

使用您喜欢的文本编辑器打开检查点文件,只需将其中的绝对路径更改为文件名即可。

【讨论】:

    【解决方案2】:

    默认情况下,Saver 对象会将绝对模型检查点路径写入checkpoint 文件。所以tf.train.latest_checkpoint(save_path)返回的路径就是你旧机器上的绝对路径。

    临时解决方案:

    1. 将实际模型文件路径直接传递给restore 方法,而不是tf.train.latest_checkpoint 的结果。
    2. 手动编辑checkpoint文件,这是一个简单的文本文件。

    长期解决方案:

    saver = tf.train.Saver(save_relative_paths=True)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-06
      • 2016-05-01
      • 1970-01-01
      • 2018-04-05
      • 2017-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多