2017-08-22 147 views
0

當我使用tensorflow來計算auc時,它總是得到0或接近於0.我嘗試了很多次,「準確度」可能達到0.999,但auc reuslt始終爲0或接近0.0。 的代碼如下:爲什麼我的tensorflow auc是0.0

input_tensor = tf.placeholder("float",[None, n_input]) 
output_tensor = tf.placeholder("float",[None, n_classes]) 
prediction = multilayer_perceptron(input_tensor, weights, biases) 
.... 

AUC=tf.contrib.metrics.streaming_auc(prediction, output_tensor) 
sess.run(tf.global_variables_initializer()) 
sess.run(tf.local_variables_initializer()) 
test_auc = sess.run(AUC, feed_dict={input_tensor : batch_x_test, output_tensor : batch_y_test}) 
print "test_auc:",test_auc 

回答

0

tf.contrib.metrics.streaming_auc返回aucupdate_op。將true_positives,true_negatives,false_positivesfalse_negatives變量適當增加並且其值與auc相匹配的操作。在sess.run步驟中,您需要分離輸出以訪問您的test_auc reults,如下所示。

AUC, update_op=tf.contrib.metrics.streaming_auc(prediction, output_tensor) 
... 
test_auc, _ = sess.run([AUC, update_op], feed_dict={input_tensor : batch_x_test, output_tensor : batch_y_test}) 

# Also you need to remove one global_variables_initializer line, as your model is loaded from checkpoint 
sess.run(tf.global_variables_initializer()) 

# place this one one step above sess restore line 
sess.run(tf.local_variables_initializer()) 
saver.restore(sess, some checkpoint file) 
+0

如下:(結果 '精度:',0.99152541) test_auc:[0.0,9.2286828e-05]。 auc是0.0 – jaky

+0

已更新我的回答 –

+0

我認爲不需要恢復會話和模型,因爲模型是經過訓練的,然後用於在同一過程中預測auc。而且,我試圖刪除「一個global_variables_initializer行」,但結果是auc的0.0。 – jaky