关于使用预训练的im2txt模型

我已经按照这个链接中的每一步操作 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,有几种方法可以“更新”你的检查点:

  1. 使用TensorFlow中包含的官方 checkpoint_convert.py 工具,或者
  2. 使用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,之后加载我的检查点工作得非常完美。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注