【问题标题】:regarding using the pre trained im2txt model关于使用预训练的 im2txt 模型
【发布时间】:2017-11-27 21:09:17
【问题描述】:

我已经从这里开始跟踪每一步https://edouardfouche.com/Fun-with-Tensorflow-im2txt/ 但我收到以下错误

NotFoundError(有关回溯,请参见上文):在检查点文件 /home/asadmahmood72/Image_to_text/models/im2txt/model.ckpt-3000000 中找不到张量名称“lstm/basic_lstm_cell/bias” [[节点: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/恢复V2_380/shape_and_slices)]]

我的操作系统是 UBUNTU 16.04 我的张量流版本是 1.2.0

【问题讨论】:

    标签: image machine-learning tensorflow


    【解决方案1】:

    这有点晚了,但希望这个答案能帮助未来遇到这个问题的人。

    就像 Edouard 提到的,这个错误是由于 Tensorflow API 的变化引起的。如果你想使用更新版本的 Tensorflow,我知道有几种方法可以“更新”你的检查点:

    1. 使用 Tensorflow 中包含的官方 checkpoint_convert.py 实用程序,或
    2. 使用 GitHub 上 0xDFDFDF 编写的this solution 重命名有问题的变量:

      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)
      

    我使用了选项 #2,之后加载我的检查点就完美了。

    【讨论】:

      【解决方案2】:

      看起来 tensorflow API 又变了,这使得它与检查点模型不兼容。我在文章中使用的是 tensorflow 0.12.1。如果可以,您可以尝试使用 tensorflow 0.12.1 吗?否则你将不得不自己训练模型(昂贵)或找到使用更新版本的 tensorflow 生成的检查点文件......

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-08-19
        • 1970-01-01
        • 1970-01-01
        • 2021-10-12
        • 2017-08-15
        • 1970-01-01
        • 1970-01-01
        • 2019-04-10
        相关资源
        最近更新 更多