学习了MNIST的基本知识之后,我(菜鸟)想使用该方法来训练另一个DataSet,我认为它类似于MNIST,但是失败了。
尽管我尝试了很多次,但似乎完全无法训练模型。它总是得到相同的结果,看起来像原始的准确性。
96类手写数字符号识别,数据尺寸45 * 45
form:npz
train_x.shape[0] = 64122,
train_x.shape[1] = 2025,
train_x[0] = [1. 1. 1. ... 1. 1. 1.]
非常感谢。
import tensorflow as tf
import numpy as np
data = np.load('E:\Python test\HNR\HNRdata.npz')
train_y = data['train_y']
train_x = data['train_x']
test_x = data['test_x']
test_y = data['test_y']
x = tf.placeholder("float", [None, 2025])
W = tf.Variable(tf.zeros([2025,96]))
b = tf.Variable(tf.zeros([96]))
y = tf.nn.softmax(tf.matmul(x,W) + b)
y_ = tf.placeholder("float", [None,96])
cross_entropy = -tf.reduce_sum(y_*tf.log(y))
train_step =
tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy)
init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)
sess.run(train_step, feed_dict = {x: train_x, y_: train_y})
correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
print(sess.run(accuracy, feed_dict={x: test_x, y_: test_y}))
print(sess.run(accuracy, feed_dict={x: train_x, y_: train_y}))
0.016273392
0.031190543
总是得到这些。非常感谢。