2017-04-25 82 views
1

我試圖首次使用contrib度量標準,但沒有設法使它們工作。Tensorflow Contrib度量總是返回0.0

這裏是我試圖用指標和它們是如何實現的:

y_pred_labels = y[:, 1] 
y_true_labels = tf.cast(y_[:, 1], tf.int32) 

with tf.name_scope('auc'):  
    auc_score, update_op_auc = tf.contrib.metrics.streaming_auc(
     predictions=y_pred_labels, 
     labels=y_true_labels 
    ) 
    tf.summary.scalar('auc', auc_score) 

with tf.name_scope('accuracy_contrib'): 
    accuracy_contrib, update_op_acc = tf.contrib.metrics.streaming_accuracy(
     predictions=y_pred_labels, 
     labels=y_true_labels 
    ) 
    tf.summary.scalar('accuracy_contrib', accuracy_contrib) 

with tf.name_scope('error_contrib'): 
    error_contrib, update_op_error = tf.contrib.metrics.streaming_mean_absolute_error(
     predictions=y_pred_labels, 
     labels=y_[:, 1] ## Needs to use float32 and not int32 
    ) 
    tf.summary.scalar('error_contrib', error_contrib) 

此代碼完全執行,並在執行過程中我得到如下:

######################################## 
Accuracy at step 1000: 0.633333 # This is computed by another displayed not displayed above 
Accuracy Contrib at step 1000: (0.0, 0.0) 
AUC Score at step 1000: (0.0, 0.0) 
Error Contrib at step 1000: (0.0, 0.0) 
######################################## 

這裏的格式資料輸入:

y_pred_labels = [0.1, 0.5, 0.6, 0.8, 0.9, 0.1, ...] #represent a binary probability 
y_true_labels = [1, 0, 1, 1, 1, 0, 0, ...] # Represent the true class {0 or 1} 
y_[:, 1]  = [1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, ...] # Same as y_true_labels formated as float32 

我想我已經在official documentation在某些條件下它是正常行爲...但是,我無法獲得我的度量值。


其次,我注意到兩個指標分別稱爲:streaming_accuracystreaming_auc,它是如何行爲不同於在「非流」準確性或AUC指標?如果有必要,有什麼辦法可以使它成爲「非流媒體」?

回答

3

我剛纔遇到同樣的問題。並發現:

您需要運行update_op s,如sess.run(update_op_auc),同時運行度量操作,如sess.run(auc_score)