我已经按照这个链接中的每一步操作 https://edouardfouche.com/Fun-with-Tensorflow-im2txt/,但我遇到了以下错误
NotFoundError(参见上面的跟踪信息):在检查点文件 /home/asadmahmood72/Image_to_text/models/im2txt/model.ckpt-3000000 中找不到名为 “lstm/basic_lstm_cell/bias” 的张量[[Node: save/RestoreV2_380 = RestoreV2[dtypes=[DT_FLOAT], _device=”/job:localhost/replica:0/task:0/cpu:0″](_arg_save/Const_0_0, save/RestoreV2_380/tensor_names, save/RestoreV2_380/shape_and_slices)]]
我的操作系统是Ubuntu 16.04,我的TensorFlow版本是1.2.0
回答:
虽然回答得有点晚,但希望这个答案能帮助将来遇到这个问题的人。
正如Edouard提到的,这个错误是由于TensorFlow API的更改引起的。如果你想使用更新版本的TensorFlow,有几种方法可以“更新”你的检查点:
- 使用TensorFlow中包含的官方
checkpoint_convert.py
工具,或者 -
使用GitHub上由0xDFDFDF编写的 这个解决方案 来重命名有问题的变量:
OLD_CHECKPOINT_FILE = "model.ckpt-1000000"NEW_CHECKPOINT_FILE = "model2.ckpt-1000000"import tensorflow as tfvars_to_rename = { "lstm/basic_lstm_cell/weights": "lstm/basic_lstm_cell/kernel", "lstm/basic_lstm_cell/biases": "lstm/basic_lstm_cell/bias",}new_checkpoint_vars = {}reader = tf.train.NewCheckpointReader(OLD_CHECKPOINT_FILE)for old_name in reader.get_variable_to_shape_map(): if old_name in vars_to_rename: new_name = vars_to_rename[old_name] else: new_name = old_name new_checkpoint_vars[new_name] = tf.Variable(reader.get_tensor(old_name))init = tf.global_variables_initializer()saver = tf.train.Saver(new_checkpoint_vars)with tf.Session() as sess: sess.run(init) saver.save(sess, NEW_CHECKPOINT_FILE)
我使用了选项#2,之后加载我的检查点工作得非常完美。