0
https://www.tensorflow.org/get_started/mnist/beginnersで説明したsoftmax回帰方法を使用して文字を認識しようとしています。ソフトマックスによるテンソルフロー文字認識は、[NaN ... NaN]予測のため精度1になります
私のコードは以下の通りです。
train_data = pd.read_csv('CharDataSet/train.csv')
print(train_data.shape)
x = tf.placeholder(tf.float32, [None, 130])
W = tf.Variable(tf.zeros([130, 26]))
b = tf.Variable(tf.zeros([26]))
y = tf.nn.softmax(tf.matmul(x, W) + b)
y_ = tf.placeholder(tf.float32, [None, 26])
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
sess = tf.InteractiveSession()
tf.global_variables_initializer().run()
for _ in range(10):
batch_xs = train_data.iloc[:, 2:]
print(batch_xs)
batch_ys = getencodedbatch(train_data.iloc[:, 1])
print(batch_ys)
sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})
しかし、私は1の精度を得ていますが、そうではありません。私は私のyテンソルは
[nan, ..., nan]
のような配列となりので、それはそうで取得していますなぜ 理由は、誰もが私のコードで間違っているものを私に説明できますか?
私はここで
def getencodedbatch(param):
s = (param.shape[0],26)
y_encode = np.zeros(s)
row=0
# print(y_encode)
for val in param:
col = ord(val)-97
y_encode[row, col] = 1
row += 1
return pd.DataFrame(y_encode)