gpt4 book ai didi

python - 如何在 v1.13.1 中恢复 tensorflow v1.1.0 保存的模型

转载 作者:行者123 更新时间:2023-11-28 18:56:27 25 4
gpt4 key购买 nike

我正在尝试恢复提供的预训练模型 here并继续在不同的数据集上进行训练。那里可用的预训练模型是在 tensorflow_gpu-1.1.0 上训练的.但是我有 tensorflow_gpu-1.13.1。当我尝试恢复模型时,出现以下错误。

NotFoundError (see above for traceback): Restoring from checkpoint failed. This is most likely due to a Variable name or other graph key that is missing from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint.

是否可以将模型转换为当前的 tensorflow 版本?我尝试了提供的脚本 here , 但没有运气!

如果无法转换,我也可以使用旧的 tensorflow 版本。但是我也无法正确安装旧版本。github page 中提供的命令在下面

pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.1.0-cp27-none-linux_x86_64.whl

但是当我使用上述命令安装tensorflow时,出现以下错误

Python 2.7.16 |Anaconda, Inc.| (default, Aug 22 2019, 16:00:36) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/media/nagabhushan/Data02/SoftwareFiles/Anaconda/anaconda3/envs/MCnet3/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/media/nagabhushan/Data02/SoftwareFiles/Anaconda/anaconda3/envs/MCnet3/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 51, in <module>
from tensorflow.python import pywrap_tensorflow
File "/media/nagabhushan/Data02/SoftwareFiles/Anaconda/anaconda3/envs/MCnet3/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/media/nagabhushan/Data02/SoftwareFiles/Anaconda/anaconda3/envs/MCnet3/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/media/nagabhushan/Data02/SoftwareFiles/Anaconda/anaconda3/envs/MCnet3/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/media/nagabhushan/Data02/SoftwareFiles/Anaconda/anaconda3/envs/MCnet3/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
ImportError: libcublas.so.8.0: cannot open shared object file: No such file or directory


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.

如果我使用 conda 安装 tensorflow-1.1.0,导入工作正常,但恢复模型再次失败并出现相同的错误

NotFoundError (see above for traceback): Restoring from checkpoint failed. This is most likely due to a Variable name or other graph key that is missing from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint.

请帮忙!

最佳答案

我真的不确定是否可以移植模型,但我会尝试分享我是如何解决这个问题的。

首先,您应该能够独立于 TensorFlow 版本创建整个图。如果那里发生任何错误,那应该是最小的错误。然后,您可以简单地将所有变量从旧模型复制到新模型:

RESTORE_VARS_BLACKLIST = ['dont', 'load', 'this']
ckpt_vars = tf.train.list_variables(RESTORE_VARS_CKPT)
ass_ops = []
for dst_var in tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES):
for (ckpt_var, ckpt_shape) in ckpt_vars:
if dst_var.name.split(":")[0] == ckpt_var and dst_var.shape == ckpt_shape and ckpt_var not in RESTORE_VARS_BLACKLIST:
value = tf.train.load_variable(RESTORE_VARS_CKPT, ckpt_var)
ass_ops.append(tf.assign(dst_var, value))
# Run assign in a session
sess.run(ass_ops)

最后,只需保存您的新模型即可。

关于python - 如何在 v1.13.1 中恢复 tensorflow v1.1.0 保存的模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57816305/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com