Tensorflow Real Example
Solution 1:
It can't be the source of your problem or errors, but I think all occurrences of row[:-2] should be replaced by row[:-1], if you want to take all indices but one (Python excludes the index end
given in a range like row[begin:end]
)
You should have:
y_ = tf.placeholder(tf.float32,[None,numberOFClasses])
...
sess.run(train_step,feed_dict={x:batch_xs[i],y_:np.reshape(batch_ys[i],(batchSize, numberOFClasses ))})
...
print(sess.run(accuracy,feed_dict={x:batch_txs[i],y_:np.reshape(batch_tys[i],(batchSize, numberOFClasses ))}))
Anyway, you should definetly use batch_size != numberOFClasses
, because it throws an error that you can use to understand what is wrong in your code. If you don't, you lose the exception message but the error is still there, hidden (you network still does not learn what you want). When you get the error look which reshapecauses a problem, and try to understand why (look what the shapes are and should be)
Solution 2:
From your code sample it's impossible to tell exactly (at least batch() and batchSize are missing to be sure), but my guess is that you have batches of size one (whether intended or not), and so you get either an accuracy of one (if the sample was predicted correctly) or zero (if the sample was misclassified). For meaningful accuracies, you want to evaluate over larger batches.
Post a Comment for "Tensorflow Real Example"