jeudi 30 juin 2016

Tensor Flow all predictions are 0

I'm running the following code for TensorFlow and all the probabilities are NaN and all the predictions are 0. The accuracy works, however. I have no idea how to debug this. Any and all help is appreciated.

x = tf.placeholder("float", shape=[None, 22])
W = tf.Variable(tf.zeros([22, 5]))

y = tf.nn.softmax(tf.matmul(x, W))
y_ = tf.placeholder(tf.float32, [None, 5])

cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))
#cross_entropy = -tf.reduce_sum(tf_softmax_correct*tf.log(tf_softmax  + 1e-50))
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
init = tf.initialize_all_variables()

sess = tf.Session()
sess.run(init)

for i in range(100):
    batch_xs, batch_ys = random.sample(allTrainingArray,100), random.sample(allTrainingSkillsArray,100)
    sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})

#test on itself
correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
print "accuracy", sess.run(accuracy, feed_dict={x: batch_xs, y_: batch_ys})

probabilities = y
print "probabilities", probabilities.eval(feed_dict={x: allTrainingArray}, session=sess)

prediction=tf.argmax(y,1)
print "predictions", prediction.eval(feed_dict={x: allTrainingArray}, session = sess)

Aucun commentaire:

Enregistrer un commentaire