質問編集履歴
2
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
#savar.save()で保存した値を異なるセッションでrestore()する際に初期化しているにも関わらず初期化されていない(uninitialize)とエラーが表示される。
|
2
2
|
45個のデータを学習して、restoreを行って新しいsessionの中で1個分の実践データを吐き出すプログラムを作っています。
|
3
3
|
|
4
|
+
|
5
|
+
|
4
6
|
エラーコード
|
5
7
|
```
|
6
8
|
FailedPreconditionError (see above for traceback): Attempting to use uninitialized value hidden1_1/hidden1_bias
|
@@ -13,6 +15,7 @@
|
|
13
15
|
#プログラムのフロー
|
14
16
|
1,session1の中で学習時の重み・バイアスをsavar.save()を使ってckptファイルを作りdiskに保存する。
|
15
17
|
※model.ckpt.metaファイルを見ても変数名は書かれているものの、重み・バイアスの値は書かれておらず、diskに保存されている→ckpt.metaファイルをもとに後ろで動いているC++で復元しているのか(脱線)
|
18
|
+
→それで納得する。
|
16
19
|
[tf.train.Saver](https://www.tensorflow.org/api_docs/python/tf/train/Saver)
|
17
20
|
2,session2の中で新しく、output2 = inference(score_placeholder)を定義する。
|
18
21
|
※1新たに定義するのはsession2の入力データが1セットのみのデータなので、正規化する式をif~elseで避けているためです。
|
@@ -20,6 +23,7 @@
|
|
20
23
|
※3print()関数はpythonで実行されるも、th.l2_nomalize,malmulなどはsession(run)でC++に渡されて実行される。
|
21
24
|
3,output2に含まれる(output_bias,output_weight,hidden_bias,hidden_weight)の値がuninitializeの状態?
|
22
25
|
※ここの値はまだrestoreしていないので、形式?だけは入っている状態(これがいけないってこと?)
|
26
|
+
→ここの理解が不足している、run and designの形式とう学ぶ必要あり。
|
23
27
|
```
|
24
28
|
def inference(score_placeholder):
|
25
29
|
with tf.name_scope('hidden1') as scope:
|
1
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,8 +1,85 @@
|
|
1
|
+
#savar.save()で保存した値を異なるセッションでrestore()する際に初期化しているにも関わらず初期化されていない(uninitialize)とエラーが表示される。
|
2
|
+
45個のデータを学習して、restoreを行って新しいsessionの中で1個分の実践データを吐き出すプログラムを作っています。
|
3
|
+
|
4
|
+
エラーコード
|
5
|
+
```
|
6
|
+
FailedPreconditionError (see above for traceback): Attempting to use uninitialized value hidden1_1/hidden1_bias
|
7
|
+
[[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)]]
|
8
|
+
```
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
#プログラムのフロー
|
14
|
+
1,session1の中で学習時の重み・バイアスをsavar.save()を使ってckptファイルを作りdiskに保存する。
|
15
|
+
※model.ckpt.metaファイルを見ても変数名は書かれているものの、重み・バイアスの値は書かれておらず、diskに保存されている→ckpt.metaファイルをもとに後ろで動いているC++で復元しているのか(脱線)
|
16
|
+
[tf.train.Saver](https://www.tensorflow.org/api_docs/python/tf/train/Saver)
|
17
|
+
2,session2の中で新しく、output2 = inference(score_placeholder)を定義する。
|
18
|
+
※1新たに定義するのはsession2の入力データが1セットのみのデータなので、正規化する式をif~elseで避けているためです。
|
19
|
+
※2inference()はデータを入力層―隠れ層―出力層を通して予想値を計算する関数
|
20
|
+
※3print()関数はpythonで実行されるも、th.l2_nomalize,malmulなどはsession(run)でC++に渡されて実行される。
|
21
|
+
3,output2に含まれる(output_bias,output_weight,hidden_bias,hidden_weight)の値がuninitializeの状態?
|
22
|
+
※ここの値はまだrestoreしていないので、形式?だけは入っている状態(これがいけないってこと?)
|
23
|
+
```
|
24
|
+
def inference(score_placeholder):
|
25
|
+
with tf.name_scope('hidden1') as scope:
|
26
|
+
hidden1_weight = tf.Variable(tf.truncated_normal([SCORE_SIZE, HIDDEN_UNIT_SIZE], stddev=0.01), name="hidden1_weight")
|
27
|
+
hidden1_bias = tf.Variable(tf.constant(0.1, shape=[HIDDEN_UNIT_SIZE]), name="hidden1_bias")
|
28
|
+
hidden1_output = tf.nn.relu(tf.matmul(score_placeholder, hidden1_weight) + hidden1_bias)
|
29
|
+
with tf.name_scope('output') as scope:
|
30
|
+
output_weight = tf.Variable(tf.truncated_normal([HIDDEN_UNIT_SIZE, 1], stddev=0.01), name="output_weight")
|
31
|
+
output_bias = tf.Variable(tf.constant(0.1, shape=[1]), name="output_bias")
|
32
|
+
output = tf.matmul(hidden1_output, output_weight) + output_bias
|
33
|
+
if TACK == 1:
|
34
|
+
print("saku1")
|
35
|
+
return output
|
36
|
+
else :
|
37
|
+
print("saku2")
|
38
|
+
return tf.nn.l2_normalize(output, 0)
|
39
|
+
|
40
|
+
```
|
41
|
+
4,resotreを用いて重み・バイアスがsession1の状態が復元→variableの値が10000回学習した後の値になる)
|
42
|
+
5,best_match2 = sess2.run(output3, feed_dict={score_placeholder:[test2]})を実行すれば、復元した重み・バイアスで出力されるはずだとおもうのですが・・・そうならない。
|
43
|
+
|
44
|
+
|
45
|
+
という状態です。
|
46
|
+
|
47
|
+
思い当たることは
|
48
|
+
|
49
|
+
また別の問題として、
|
50
|
+
・そもそもinitializeをsessionの最初に書いても、初期化するvariableがないのに何でするのかという疑問があります。
|
51
|
+
・sessionで関数は実行されているのをみるとsessionの役割はtf.~がつくものの計算が思いから後ろで動いているC++に渡している認識で間違っていないか知りたいです。
|
52
|
+
|
53
|
+
|
54
|
+
何度もお手間を取らせてしまっていますがよろしくお願い致します。
|
55
|
+
```
|
56
|
+
|
57
|
+
def inference(score_placeholder):
|
58
|
+
with tf.name_scope('hidden1') as scope:
|
59
|
+
hidden1_weight = tf.Variable(tf.truncated_normal([SCORE_SIZE, HIDDEN_UNIT_SIZE], stddev=0.01), name="hidden1_weight")
|
60
|
+
hidden1_bias = tf.Variable(tf.constant(0.1, shape=[HIDDEN_UNIT_SIZE]), name="hidden1_bias")
|
61
|
+
hidden1_output = tf.nn.relu(tf.matmul(score_placeholder, hidden1_weight) + hidden1_bias)
|
62
|
+
with tf.name_scope('output') as scope:
|
63
|
+
output_weight = tf.Variable(tf.truncated_normal([HIDDEN_UNIT_SIZE, 1], stddev=0.01), name="output_weight")
|
64
|
+
output_bias = tf.Variable(tf.constant(0.1, shape=[1]), name="output_bias")
|
65
|
+
output = tf.matmul(hidden1_output, output_weight) + output_bias
|
66
|
+
if TACK == 1:
|
67
|
+
print("saku1")
|
68
|
+
return output
|
69
|
+
else :
|
70
|
+
print("saku2")
|
71
|
+
return tf.nn.l2_normalize(output, 0)
|
72
|
+
|
73
|
+
```
|
74
|
+
|
1
75
|
variable()に保存されている値を異なるセッションで、restoreする際に
|
2
76
|
output_bias,output_weight,hidden_bias,hidden_weightの値が初期化されていない旨のエラーが発生してしましました。
|
3
77
|
|
4
|
-
考えられる状況としては
|
5
78
|
|
79
|
+
1、session
|
80
|
+
|
81
|
+
|
82
|
+
|
6
83
|
入力層ー隠れ層ー出力層で構成されるNN
|
7
84
|
inference関数の引数になる実践データが予測値を吐き出す認識
|
8
85
|
```
|
@@ -38,10 +115,14 @@
|
|
38
115
|
FailedPreconditionError (see above for traceback): Attempting to use uninitialized value output_1/output_bias
|
39
116
|
```
|
40
117
|
|
41
|
-
多重投稿のご指摘ありがとうございます。言われないと気付けなっかたのでありがたいです。
|
42
118
|
|
119
|
+
one_data.csv
|
120
|
+
```
|
121
|
+
0.71428573, 0.85714287, 0.71428573, 0.5714286 , 0.5714286 ,0.71428573, 0.5714286 , 0.71428573, 0.71428573, 0.71428573,0.5714286 , 0.71428573
|
43
122
|
|
123
|
+
```
|
44
124
|
|
125
|
+
ソースコード
|
45
126
|
```
|
46
127
|
import tensorflow as tf
|
47
128
|
import numpy
|
@@ -125,7 +206,6 @@
|
|
125
206
|
summary_str = sess.run(summary_op, feed_dict=feed_dict_test)
|
126
207
|
summary_str += sess.run(summary_op, feed_dict=feed_dict_train)
|
127
208
|
summary_writer.add_summary(summary_str, step)
|
128
|
-
|
129
209
|
saver=tf.train.Saver()
|
130
210
|
saver.save(sess,cwd+'/model.ckpt')
|
131
211
|
print(cwd)
|
@@ -134,16 +214,19 @@
|
|
134
214
|
sess.close()
|
135
215
|
|
136
216
|
with tf.Session() as sess2:
|
137
|
-
summary_writer = tf.summary.FileWriter('
|
217
|
+
#summary_writer = tf.summary.FileWriter('data2', graph=sess2.graph_def)
|
138
218
|
sess2.run(init)
|
219
|
+
|
220
|
+
TACK = 1
|
139
221
|
saver = tf.train.Saver()
|
140
|
-
test2 = numpy.loadtxt(open("one_data.csv"), delimiter=",").astype(numpy.float32)
|
141
|
-
TACK = 1
|
142
222
|
saver.restore(sess2,cwd + "/model.ckpt")
|
143
223
|
output3 = inference(score_placeholder)
|
224
|
+
test2 = numpy.loadtxt(open("one_data.csv"), delimiter=",").astype(numpy.float32)
|
144
225
|
best_match2 = sess2.run(output3, feed_dict={score_placeholder:[test2]})
|
226
|
+
summary_str = sess2.run(summary_op, feed_dict=feed_dict_test)
|
145
227
|
print(best_match2)
|
146
228
|
print("fin")
|
147
229
|
sess2.close()
|
148
230
|
|
231
|
+
|
149
232
|
```
|