Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python im2text&;TensorFlow 1.4.1_Python_Tensorflow - Fatal编程技术网

Python im2text&;TensorFlow 1.4.1

Python im2text&;TensorFlow 1.4.1,python,tensorflow,Python,Tensorflow,这里有人成功使用TensorFlow 1.4.1运行IM2Text吗 我正在使用这个模型() 然后我尝试了以下脚本来转换模型。脚本生成了检查点、.meta、.data和.index OLD_CHECKPOINT_FILE = "/tmp/my_checkpoint/model.ckpt-3000000" NEW_CHECKPOINT_FILE = "/tmp/my_converted_checkpoint/model.ckpt-3000000" import tensorflow as tf

这里有人成功使用TensorFlow 1.4.1运行IM2Text吗

我正在使用这个模型()

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

OLD_CHECKPOINT_FILE = "/tmp/my_checkpoint/model.ckpt-3000000"
NEW_CHECKPOINT_FILE = "/tmp/my_converted_checkpoint/model.ckpt-3000000"

import tensorflow as tf
vars_to_rename = {
    "lstm/BasicLSTMCell/Linear/Matrix": "lstm/basic_lstm_cell/weights",
    "lstm/BasicLSTMCell/Linear/Bias": "lstm/basic_lstm_cell/biases",
}
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)
  print("save checkpoint")
  saver.save(sess, NEW_CHECKPOINT_FILE)
谁能告诉我如何使用这些文件在TensorFlow 1.4.1中运行IM2Text。(实际上,我可以使用tensorflow 0.12.1运行IM2Text)

环境 python 3.5.2
Mac OS X版本10.12.6
TensorFlow 1.4.1


感谢您的帮助。

在MacOS 10.13上,tf 1.4.1和python3.5的检查点文件也会出现同样的错误

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

来自

变化: 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)
  • python3文件读取问题,在im2text/run_reference.py中

    将tf.gfile.gfile(文件名,“rb”)作为f:

  • 从该链接下载的word_count.txt需要替换为此链接


  • 在MacOS 10.13上,tf 1.4.1和python3.5的检查点文件也会出现同样的错误

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

    来自

    变化: 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)
    
  • python3文件读取问题,在im2text/run_reference.py中

    将tf.gfile.gfile(文件名,“rb”)作为f:

  • 从该链接下载的word_count.txt需要替换为此链接


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

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

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

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

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

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