<p>对于macos10.13上的tf1.4.1和python3.5,检查点文件也会出现相同的错误</p>
<p>原因:下载的检查点文件是使用旧版本的tensorflow(python2)生成的。字_计数.txt文件格式</p>
<p>来自<a href="https://github.com/KranthiGV/Pretrained-Show-and-Tell-model" rel="nofollow noreferrer">https://github.com/KranthiGV/Pretrained-Show-and-Tell-model</a>的答案</p>
<p>更改:
1生成可由tf1.4.1加载的ckp文件</p>
<pre><code>OLD_CHECKPOINT_FILE = "model.ckpt-1000000"
NEW_CHECKPOINT_FILE = "model2.ckpt-1000000"
import tensorflow as tf
vars_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)
</code></pre>
<ol start=“2”>
<li><p>python3文件读取问题,在im2text/run中_参考.py在</p>
<p><code>with tf.gfile.GFile(filename, "rb") as f:</code></p></li>
<li><p>字_计数.txt从那个链接下载的需要被这个替换
<a href="https://github.com/siavash9000/im2txt_demo/tree/master/im2txt_pretrained" rel="nofollow noreferrer">https://github.com/siavash9000/im2txt_demo/tree/master/im2txt_pretrained</a></p></li>
</ol>