質問編集履歴

2

誤字

2017/07/19 06:15

投稿

zakio49
zakio49

スコア29

test CHANGED
File without changes
test CHANGED
@@ -4,6 +4,10 @@
4
4
 
5
5
 
6
6
 
7
+
8
+
9
+
10
+
7
11
  エラーコード
8
12
 
9
13
  ```
@@ -28,6 +32,8 @@
28
32
 
29
33
  ※model.ckpt.metaファイルを見ても変数名は書かれているものの、重み・バイアスの値は書かれておらず、diskに保存されている→ckpt.metaファイルをもとに後ろで動いているC++で復元しているのか(脱線)
30
34
 
35
+ →それで納得する。
36
+
31
37
  [tf.train.Saver](https://www.tensorflow.org/api_docs/python/tf/train/Saver)
32
38
 
33
39
  2,session2の中で新しく、output2 = inference(score_placeholder)を定義する。
@@ -42,6 +48,8 @@
42
48
 
43
49
  ※ここの値はまだrestoreしていないので、形式?だけは入っている状態(これがいけないってこと?)
44
50
 
51
+ →ここの理解が不足している、run and designの形式とう学ぶ必要あり。
52
+
45
53
  ```
46
54
 
47
55
  def inference(score_placeholder):

1

誤字

2017/07/19 06:15

投稿

zakio49
zakio49

スコア29

test CHANGED
File without changes
test CHANGED
@@ -1,10 +1,164 @@
1
+ #savar.save()で保存した値を異なるセッションでrestore()する際に初期化しているにも関わらず初期化されていない(uninitialize)とエラーが表示される。
2
+
3
+ 45個のデータを学習して、restoreを行って新しいsessionの中で1個分の実践データを吐き出すプログラムを作っています。
4
+
5
+
6
+
7
+ エラーコード
8
+
9
+ ```
10
+
11
+ FailedPreconditionError (see above for traceback): Attempting to use uninitialized value hidden1_1/hidden1_bias
12
+
13
+ [[Node: hidden1_1/hidden1_bias/read = Identity[T=DT_FLOAT, _class=["loc:@hidden1_1/hidden1_bias"], _device="/job:localhost/replica:0/task:0/cpu:0"](hidden1_1/hidden1_bias)]]
14
+
15
+ ```
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+ #プログラムのフロー
26
+
27
+ 1,session1の中で学習時の重み・バイアスをsavar.save()を使ってckptファイルを作りdiskに保存する。
28
+
29
+ ※model.ckpt.metaファイルを見ても変数名は書かれているものの、重み・バイアスの値は書かれておらず、diskに保存されている→ckpt.metaファイルをもとに後ろで動いているC++で復元しているのか(脱線)
30
+
31
+ [tf.train.Saver](https://www.tensorflow.org/api_docs/python/tf/train/Saver)
32
+
33
+ 2,session2の中で新しく、output2 = inference(score_placeholder)を定義する。
34
+
35
+ ※1新たに定義するのはsession2の入力データが1セットのみのデータなので、正規化する式をif~elseで避けているためです。
36
+
37
+ ※2inference()はデータを入力層―隠れ層―出力層を通して予想値を計算する関数
38
+
39
+ ※3print()関数はpythonで実行されるも、th.l2_nomalize,malmulなどはsession(run)でC++に渡されて実行される。
40
+
41
+ 3,output2に含まれる(output_bias,output_weight,hidden_bias,hidden_weight)の値がuninitializeの状態?
42
+
43
+ ※ここの値はまだrestoreしていないので、形式?だけは入っている状態(これがいけないってこと?)
44
+
45
+ ```
46
+
47
+ def inference(score_placeholder):
48
+
49
+ with tf.name_scope('hidden1') as scope:
50
+
51
+ hidden1_weight = tf.Variable(tf.truncated_normal([SCORE_SIZE, HIDDEN_UNIT_SIZE], stddev=0.01), name="hidden1_weight")
52
+
53
+ hidden1_bias = tf.Variable(tf.constant(0.1, shape=[HIDDEN_UNIT_SIZE]), name="hidden1_bias")
54
+
55
+ hidden1_output = tf.nn.relu(tf.matmul(score_placeholder, hidden1_weight) + hidden1_bias)
56
+
57
+ with tf.name_scope('output') as scope:
58
+
59
+ output_weight = tf.Variable(tf.truncated_normal([HIDDEN_UNIT_SIZE, 1], stddev=0.01), name="output_weight")
60
+
61
+ output_bias = tf.Variable(tf.constant(0.1, shape=[1]), name="output_bias")
62
+
63
+ output = tf.matmul(hidden1_output, output_weight) + output_bias
64
+
65
+ if TACK == 1:
66
+
67
+ print("saku1")
68
+
69
+ return output
70
+
71
+ else :
72
+
73
+ print("saku2")
74
+
75
+ return tf.nn.l2_normalize(output, 0)
76
+
77
+
78
+
79
+ ```
80
+
81
+ 4,resotreを用いて重み・バイアスがsession1の状態が復元→variableの値が10000回学習した後の値になる)
82
+
83
+ 5,best_match2 = sess2.run(output3, feed_dict={score_placeholder:[test2]})を実行すれば、復元した重み・バイアスで出力されるはずだとおもうのですが・・・そうならない。
84
+
85
+
86
+
87
+
88
+
89
+ という状態です。
90
+
91
+
92
+
93
+ 思い当たることは
94
+
95
+
96
+
97
+ また別の問題として、
98
+
99
+ ・そもそもinitializeをsessionの最初に書いても、初期化するvariableがないのに何でするのかという疑問があります。
100
+
101
+ ・sessionで関数は実行されているのをみるとsessionの役割はtf.~がつくものの計算が思いから後ろで動いているC++に渡している認識で間違っていないか知りたいです。
102
+
103
+
104
+
105
+
106
+
107
+ 何度もお手間を取らせてしまっていますがよろしくお願い致します。
108
+
109
+ ```
110
+
111
+
112
+
113
+ def inference(score_placeholder):
114
+
115
+ with tf.name_scope('hidden1') as scope:
116
+
117
+ hidden1_weight = tf.Variable(tf.truncated_normal([SCORE_SIZE, HIDDEN_UNIT_SIZE], stddev=0.01), name="hidden1_weight")
118
+
119
+ hidden1_bias = tf.Variable(tf.constant(0.1, shape=[HIDDEN_UNIT_SIZE]), name="hidden1_bias")
120
+
121
+ hidden1_output = tf.nn.relu(tf.matmul(score_placeholder, hidden1_weight) + hidden1_bias)
122
+
123
+ with tf.name_scope('output') as scope:
124
+
125
+ output_weight = tf.Variable(tf.truncated_normal([HIDDEN_UNIT_SIZE, 1], stddev=0.01), name="output_weight")
126
+
127
+ output_bias = tf.Variable(tf.constant(0.1, shape=[1]), name="output_bias")
128
+
129
+ output = tf.matmul(hidden1_output, output_weight) + output_bias
130
+
131
+ if TACK == 1:
132
+
133
+ print("saku1")
134
+
135
+ return output
136
+
137
+ else :
138
+
139
+ print("saku2")
140
+
141
+ return tf.nn.l2_normalize(output, 0)
142
+
143
+
144
+
145
+ ```
146
+
147
+
148
+
1
149
  variable()に保存されている値を異なるセッションで、restoreする際に
2
150
 
3
151
  output_bias,output_weight,hidden_bias,hidden_weightの値が初期化されていない旨のエラーが発生してしましました。
4
152
 
5
153
 
6
154
 
155
+
156
+
7
- 考えられる状況としては
157
+ 1、session
158
+
159
+
160
+
161
+
8
162
 
9
163
 
10
164
 
@@ -78,13 +232,21 @@
78
232
 
79
233
 
80
234
 
235
+
236
+
81
- 多重投稿のご指摘ありがとうございます。言われないと気付けなっかたのでありがたいです。
237
+ one_data.csv
238
+
82
-
239
+ ```
240
+
83
-
241
+ 0.71428573, 0.85714287, 0.71428573, 0.5714286 , 0.5714286 ,0.71428573, 0.5714286 , 0.71428573, 0.71428573, 0.71428573,0.5714286 , 0.71428573
242
+
243
+
244
+
84
-
245
+ ```
246
+
247
+
248
+
85
-
249
+ ソースコード
86
-
87
-
88
250
 
89
251
  ```
90
252
 
@@ -252,8 +414,6 @@
252
414
 
253
415
  summary_writer.add_summary(summary_str, step)
254
416
 
255
-
256
-
257
417
  saver=tf.train.Saver()
258
418
 
259
419
  saver.save(sess,cwd+'/model.ckpt')
@@ -270,22 +430,26 @@
270
430
 
271
431
  with tf.Session() as sess2:
272
432
 
273
- summary_writer = tf.summary.FileWriter('data', graph=sess2.graph)
433
+ #summary_writer = tf.summary.FileWriter('data2', graph=sess2.graph_def)
274
434
 
275
435
  sess2.run(init)
276
436
 
437
+
438
+
439
+ TACK = 1
440
+
277
441
  saver = tf.train.Saver()
278
442
 
443
+ saver.restore(sess2,cwd + "/model.ckpt")
444
+
445
+ output3 = inference(score_placeholder)
446
+
279
447
  test2 = numpy.loadtxt(open("one_data.csv"), delimiter=",").astype(numpy.float32)
280
448
 
281
- TACK = 1
282
-
283
- saver.restore(sess2,cwd + "/model.ckpt")
284
-
285
- output3 = inference(score_placeholder)
286
-
287
449
  best_match2 = sess2.run(output3, feed_dict={score_placeholder:[test2]})
288
450
 
451
+ summary_str = sess2.run(summary_op, feed_dict=feed_dict_test)
452
+
289
453
  print(best_match2)
290
454
 
291
455
  print("fin")
@@ -294,4 +458,6 @@
294
458
 
295
459
 
296
460
 
461
+
462
+
297
- ```
463
+ ```