IM2Text和TensorFlow 1.4.1

2024-05-17 00:21:11 发布

您现在位置:Python中文网/ 问答频道 /正文

这里有人成功地用TensorFlow 1.4.1运行im2xt吗?在

我使用这个模型(https://drive.google.com/file/d/0B_qCJ40uBfjEWVItOTdyNUFOMzg/view

2018-01-04 00:46:59.268582: W tensorflow/core/framework/op_kernel.cc:1192] Not found: Key lstm/basic_lstm_cell/kernel not found in checkpoint

然后我尝试使用下面的脚本来转换模型。脚本生成了检查点、.meta、.data和.index。在

^{pr2}$

有谁能告诉我如何使用这些文件来运行带有TensorFlow 1.4.1的im2xt。(实际上,我可以用tensorflow 0.12.1运行im2text)

环境 python 3.5.2
Mac OS X 10.12.6版
TensorFlow 1.4.1

谢谢你的帮助。在


Tags: https模型脚本comtensorflowgoogledrivekernel
2条回答

对于macos10.13上的tf1.4.1和python3.5,检查点文件也会出现相同的错误

原因:下载的检查点文件是使用旧版本的tensorflow(python2)生成的。字_计数.txt文件格式

来自https://github.com/KranthiGV/Pretrained-Show-and-Tell-model的答案

更改: 1生成可由tf1.4.1加载的ckp文件

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)
  1. python3文件读取问题,在im2text/run中_参考.py在

    with tf.gfile.GFile(filename, "rb") as f:

  2. 字_计数.txt从那个链接下载的需要被这个替换 https://github.com/siavash9000/im2txt_demo/tree/master/im2txt_pretrained

春芳的解决方案对我有效,但我想分享另一种方法。在

在TensorFlow的最新版本中,Google提供了一个“官方”^{}实用程序来转换旧的RNN检查点:

python checkpoint_convert.py [ write_v1_checkpoint] \
  '/path/to/old_checkpoint' '/path/to/new_checkpoint'

相关问题 更多 >