Skip to content Skip to sidebar Skip to footer

Tensorflow Streaming_dynamic_auc Returns 0 Value And None Op

I am trying to understand how to aggregate metric variables in Tensorflow and I came across tf.contrib.metrics.streaming_dynamic_auc. It aggregates predictions and labels, which se

Solution 1:

No, it's intended behavior. TF metrics output a tuple of value and update op, that update value. So in first run the actual value, the first output of a metric will be 0. If you just print the both values two times, you'll see that on the second run both values will be non zero.

with tf.Session() as sess:
        auc_tf = tf.contrib.metrics.streaming_dynamic_auc(predictions=pds, labels=lbs)
        sess.run(tf.global_variables_initializer())
        sess.run(tf.local_variables_initializer())
        auc_tf_val = sess.run(auc_tf, {pds:y_pred, lbs:y_true})
        print(auc_tf_val)
        auc_tf_val = sess.run(auc_tf, {pds: y_pred, lbs: y_true})
        print(auc_tf_val)

P.S. I don't know your particular application and TF version you're using, but I guess it's better to use tf.metrics.auc. Contrib module will be deprecated in future versions. https://www.tensorflow.org/api_docs/python/tf/metrics/auc

Edit: In regard to particular case, mentioned in the question. update_op's value is always None because it's computed differently, In case contrib module metrics it is <class 'tensorflow.python.framework.ops.Operation'>, while metrics module return plain tensor, that can be evaluated inside session, therefore has value.


Post a Comment for "Tensorflow Streaming_dynamic_auc Returns 0 Value And None Op"