前提・実現したいこと
画像から説明文を生成する手法の「Show and Tell」をCPUで実行しようとしています。
以下の参考サイト通りに進めています。
参考記事
発生している問題・エラーメッセージ
キャプション生成の最後の実行で、以下のエラーが出ました。
run_inference スクリプトをビルドをするところまでは、できています。
tensorflow.python.framework.errors_impl.NotFoundError: ~/test/M/models/research/im2txt/word_counts.txt; No such file or directory
該当のソースコード
以下が、参考記事のコードです。
このtest/M/research
というのが、gitからクローンしたもともとのフォルダには存在せず、記事中ではここで初めて出てきたので、それが問題になっているのではないかと推測されます。
しかし、解決方法がわからないので、質問させていただきました。
~/test/models/research/im2txt/bazel-bin/im2txt/run_inference \ --checkpoint_path="~/test/M/models/research/im2txt/model.ckpt-2000000" \ --vocab_file="~/test/M/models/research/im2txt/word_counts.txt" \ --input_files="~/test/M/models/research/im2txt/im2txt/cat.jpg"
試したこと1
参考記事の「トレーニング済みモデルの準備」で処理しなければならないmodel.ckpt-2000000
というファイルの変更日が2016年になっていたので、再度参考記事に明記されていた以下のコードを実行して処理したところ、エラーが表示されました。
参考記事とは異なるファイル階層で、プログラムを実行したので最初の2行は、参考記事から変更しました。
python
1OLD_CHECKPOINT_FILE = "model.ckpt-2000000" 2NEW_CHECKPOINT_FILE = "model.ckpt-2000000" 3 4import tensorflow as tf 5vars_to_rename = { 6 "lstm/BasicLSTMCell/Linear/Matrix": "lstm/basic_lstm_cell/weights", 7 "lstm/BasicLSTMCell/Linear/Bias": "lstm/basic_lstm_cell/biases", 8} 9new_checkpoint_vars = {} 10reader = tf.train.NewCheckpointReader(OLD_CHECKPOINT_FILE) 11for old_name in reader.get_variable_to_shape_map(): 12 if old_name in vars_to_rename: 13 new_name = vars_to_rename[old_name] 14 else: 15 new_name = old_name 16 new_checkpoint_vars[new_name] = tf.Variable(reader.get_tensor(old_name)) 17 18init = tf.global_variables_initializer() 19saver = tf.train.Saver(new_checkpoint_vars) 20 21with tf.Session() as sess: 22 sess.run(init) 23 saver.save(sess, NEW_CHECKPOINT_FILE) 24
エラー文
$ python checkpoint_change.py 2018-11-11 14:45:58.509219: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA 2018-11-11 14:46:17.630002: W tensorflow/core/framework/op_kernel.cc:1273] OP_REQUIRES failed at save_restore_v2_ops.cc:109 : Not found: ; No such file or directory (略) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "checkpoint_change.py", line 23, in <module> saver.save(sess, NEW_CHECKPOINT_FILE) File "/Users/username/anaconda/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1458, in save raise exc ValueError: Parent directory of model.ckpt-2000000 doesn't exist, can't save.
しかし、階層を変えて
OLD_CHECKPOINT_FILE = "test/models/research/im2txt/model.ckpt-2000000" NEW_CHECKPOINT_FILE = "test/models/research/im2txt/model.ckpt-2000000"
にしたところ、エラーは起きず、
model.ckpt-2000000.data-00000-of-00001 model.ckpt-2000000.index model.ckpt-2000000.meta
の3つのファイルが生成されました。
試したこと2
参考記事の実行コマンドでは、Mフォルダがないというエラーが出ていたので、Mフォルダのないコマンドで試したところ。さらに別のエラーが出て、解決できませんでした。
bash
1$ test/models/research/im2txt/bazel-bin/im2txt/run_inference --checkpoint_path="test/models/research/im2txt/model.ckpt-2000000" --vocab_file="test/models/research/im2txt/word_counts.txt" --input_files="test/models/research/im2txt/im2txt/cat.jpg" 2
エラー文
NotFoundError (see above for traceback): Restoring from checkpoint failed. This is most likely due to a Variable name or other graph key that is missing from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint. Original error: Key lstm/basic_lstm_cell/bias not found in checkpoint [[node save/RestoreV2 (defined at /Users/username/Desktop/show_and_tell/test/models/research/im2txt/bazel-bin/im2txt/run_inference.runfiles/im2txt/im2txt/inference_utils/inference_wrapper_base.py:116) = RestoreV2[dtypes=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, ..., DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT], _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_save/Const_0_0, save/RestoreV2/tensor_names, save/RestoreV2/shape_and_slices)]]
補足情報(FW/ツールのバージョンなど)
MacOS mojave
tensorflow 1.12.0
numpy 1.15.4
Babel 2.3.4
Python 3.6.0 :: Anaconda 4.3.0 (x86_64)
回答1件
あなたの回答
tips
プレビュー