teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

4

試したこと2の追記

2018/11/11 06:13

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -23,7 +23,7 @@
23
23
  --input_files="~/test/M/models/research/im2txt/im2txt/cat.jpg"
24
24
  ```
25
25
 
26
- ### 試したこと
26
+ ### 試したこと1
27
27
 
28
28
  参考記事の「トレーニング済みモデルの準備」で処理しなければならない`model.ckpt-2000000`というファイルの変更日が2016年になっていたので、再度[参考記事](https://qiita.com/48saaan/items/1661a912c740308d3fd5#%E3%83%88%E3%83%AC%E3%83%BC%E3%83%8B%E3%83%B3%E3%82%B0%E6%B8%88%E3%81%BF%E3%83%A2%E3%83%87%E3%83%AB%E3%81%AE%E6%BA%96%E5%82%99)に明記されていた以下のコードを実行して処理したところ、エラーが表示されました。
29
29
 
@@ -85,6 +85,22 @@
85
85
  ```
86
86
  の3つのファイルが生成されました。
87
87
 
88
+ ### 試したこと2
89
+ [参考記事の実行コマンド](https://qiita.com/48saaan/items/1661a912c740308d3fd5)では、Mフォルダがないというエラーが出ていたので、Mフォルダのないコマンドで試したところ。さらに別のエラーが出て、解決できませんでした。
90
+ ```bash
91
+ $ 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"
92
+
93
+ ```
94
+
95
+ エラー文
96
+ ```
97
+ 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:
98
+
99
+ Key lstm/basic_lstm_cell/bias not found in checkpoint
100
+ [[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)]]
101
+
102
+ ```
103
+
88
104
  ### 補足情報(FW/ツールのバージョンなど)
89
105
  MacOS mojave
90
106
  tensorflow 1.12.0

3

試したことの追記修正

2018/11/11 06:13

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -72,8 +72,19 @@
72
72
  raise exc
73
73
  ValueError: Parent directory of model.ckpt-2000000 doesn't exist, can't save.
74
74
  ```
75
+ しかし、階層を変えて
76
+ ```
77
+ OLD_CHECKPOINT_FILE = "test/models/research/im2txt/model.ckpt-2000000"
78
+ NEW_CHECKPOINT_FILE = "test/models/research/im2txt/model.ckpt-2000000"
79
+ ```
80
+ にしたところ、エラーは起きず、
81
+ ```
82
+ model.ckpt-2000000.data-00000-of-00001
83
+ model.ckpt-2000000.index
84
+ model.ckpt-2000000.meta
85
+ ```
86
+ の3つのファイルが生成されました。
75
87
 
76
-
77
88
  ### 補足情報(FW/ツールのバージョンなど)
78
89
  MacOS mojave
79
90
  tensorflow 1.12.0

2

試したことの追記

2018/11/11 06:00

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -23,7 +23,57 @@
23
23
  --input_files="~/test/M/models/research/im2txt/im2txt/cat.jpg"
24
24
  ```
25
25
 
26
+ ### 試したこと
26
27
 
28
+ 参考記事の「トレーニング済みモデルの準備」で処理しなければならない`model.ckpt-2000000`というファイルの変更日が2016年になっていたので、再度[参考記事](https://qiita.com/48saaan/items/1661a912c740308d3fd5#%E3%83%88%E3%83%AC%E3%83%BC%E3%83%8B%E3%83%B3%E3%82%B0%E6%B8%88%E3%81%BF%E3%83%A2%E3%83%87%E3%83%AB%E3%81%AE%E6%BA%96%E5%82%99)に明記されていた以下のコードを実行して処理したところ、エラーが表示されました。
29
+
30
+ 参考記事とは異なるファイル階層で、プログラムを実行したので最初の2行は、参考記事から変更しました。
31
+ ```python
32
+ OLD_CHECKPOINT_FILE = "model.ckpt-2000000"
33
+ NEW_CHECKPOINT_FILE = "model.ckpt-2000000"
34
+
35
+ import tensorflow as tf
36
+ vars_to_rename = {
37
+ "lstm/BasicLSTMCell/Linear/Matrix": "lstm/basic_lstm_cell/weights",
38
+ "lstm/BasicLSTMCell/Linear/Bias": "lstm/basic_lstm_cell/biases",
39
+ }
40
+ new_checkpoint_vars = {}
41
+ reader = tf.train.NewCheckpointReader(OLD_CHECKPOINT_FILE)
42
+ for old_name in reader.get_variable_to_shape_map():
43
+ if old_name in vars_to_rename:
44
+ new_name = vars_to_rename[old_name]
45
+ else:
46
+ new_name = old_name
47
+ new_checkpoint_vars[new_name] = tf.Variable(reader.get_tensor(old_name))
48
+
49
+ init = tf.global_variables_initializer()
50
+ saver = tf.train.Saver(new_checkpoint_vars)
51
+
52
+ with tf.Session() as sess:
53
+ sess.run(init)
54
+ saver.save(sess, NEW_CHECKPOINT_FILE)
55
+
56
+ ```
57
+
58
+ エラー文
59
+ ```
60
+ $ python checkpoint_change.py
61
+ 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
62
+ 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
63
+
64
+ (略)
65
+
66
+ During handling of the above exception, another exception occurred:
67
+
68
+ Traceback (most recent call last):
69
+ File "checkpoint_change.py", line 23, in <module>
70
+ saver.save(sess, NEW_CHECKPOINT_FILE)
71
+ File "/Users/username/anaconda/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1458, in save
72
+ raise exc
73
+ ValueError: Parent directory of model.ckpt-2000000 doesn't exist, can't save.
74
+ ```
75
+
76
+
27
77
  ### 補足情報(FW/ツールのバージョンなど)
28
78
  MacOS mojave
29
79
  tensorflow 1.12.0

1

タグの追記

2018/11/11 05:55

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
File without changes