2017-04-25 51 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)