我寫過我的第一個Tensorflow程序(使用我自己的數據)。它運作良好,至少它不會崩潰!但是我得到的有線精度值是0還是1?Tensorflow精度問題
.................................
the previous part of the code, is only about handeling csv file an getting Data in correct format/shapes
......................................................
# Tensoflow
x = tf.placeholder(tf.float32,[None,len(Training_Data[0])],name='Train_data')# each input has a 457 lenght
y_ = tf.placeholder(tf.float32,[None, numberOFClasses],name='Labels')#
#w = tf.Variable(tf.zeros([len(Training_Data[0]),numberOFClasses]),name='Weights')
w = tf.Variable(tf.truncated_normal([len(Training_Data[0]),numberOFClasses],stddev=1./10),name='Weights')
b = tf.Variable(tf.zeros([numberOFClasses]),name='Biases')
model = tf.add(tf.matmul(x,w),b)
y = tf.nn.softmax(model)
cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y_, logits=y))
#cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy)
sess = tf.Session()
sess.run(tf.global_variables_initializer())
for j in range(len(train_data)):
if(np.shape(train_data) == (batchSize,numberOFClasses)):
sess.run(train_step,feed_dict={x:train_data[j],y_:np.reshape(train_labels[j],(batchSize,numberOFClasses)) })
correct_prediction = tf.equal(tf.arg_max(y,1),tf.arg_max(y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction,"float"))
accuracy_vector= []
current_class =[]
for i in range(len(Testing_Data)):
if(np.shape(Testing_Labels[i]) == (numberOFClasses,)):
accuracy_vector.append(sess.run(accuracy,feed_dict={x:np.reshape(Testing_Data[i],(1,457)),y_:np.reshape(Testing_Labels[i],(1,19))}))#,i)#,Test_Labels[i])
current_class.append(int(Test_Raw[i][-1]))
ploting的accuracy_vector
提供以下:
[]
任何想法是什麼,我在這裏失蹤?
非常感謝任何提示!
確定培訓實際發生的?測試'if(np.shape(train_data)==(batchSize,numberOFClasses)):'不應該爲true,因爲train_data更可能是形狀(n_samples,num_features),其中n_samples是樣本總數或批次大小和num_features似乎是457你的情況... – gdelab
@gdelab我無法感謝你足夠的,if語句只是爲了結束,因爲該程序崩潰作爲結束。但是如何檢查訓練是否發生,我的意思是if語句只有一次無效。但如何檢查培訓是否真的發生? – Engine
您只需在'sess.run(training_step,...)'之前或之後的'print(「我們應該訓練」)'在相同的'if'語句中添加。如果它打印一些東西,那麼你訓練! – gdelab