我一直在試圖找出爲什麼這不工作幾個小時,但我無處可去。真的很感謝一些幫助。MNIST tensorflow - 不能找出最新錯誤
它基本上是在tensorflow網站上找到的教程的一個副本,它使用本地數據集進行了一些調整。但我只有10%的準確度,這與猜測一樣!
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
import tensorflow as tf
df = pd.read_csv('train.csv')
yi = df['label']
df = df.drop('label',1)
labels=[]
for i in range(len(yi)):
#convert to one hot
label = [0,0,0,0,0,0,0,0,0,0]
label[yi[i]]= 1
labels.append(label)
labels = np.array(labels)
df = df.as_matrix()
df_train, df_test, y_train, y_test = train_test_split(df,labels)
x = tf.placeholder('float', [None, 784])
W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))
y = tf.nn.softmax(tf.matmul(x, W) + b)
y_ = tf.placeholder('float', [None, 10])
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))
train_step = tf.train.GradientDescentOptimizer(0.05).minimize(cross_entropy)
sess = tf.Session()
init = tf.global_variables_initializer()
sess.run(init)
def next_batch(num, data, labels):
#get batches for training
idx = np.arange(0 , len(data))
np.random.shuffle(idx)
idx = idx[:num]
data_shuffle = [data[ i] for i in idx]
labels_shuffle = [labels[ i] for i in idx]
return np.asarray(data_shuffle), np.asarray(labels_shuffle)
for _ in range(1000):
df_train0, y_train0 = next_batch(100, df_train, y_train)
sess.run(train_step, feed_dict={ x: df_train0, y_: y_train0})
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:df_test, y_:y_test}))
您沒有使用任何隱藏層?這只是一個線性模型?你期望什麼準確度? –
我預計至少有90個。我知道還有更多的圖層可以添加,但需要先讓它工作! – ElkanaTheGreat
無法訪問您的培訓數據,無法運行此程序並嘗試進行調試。你可以上傳你正在運行的數據文件嗎? –