how to use tf.metrics.__ with estimator model predict output

余生颓废 提交于 2019-12-06 05:42:58

The function returns 2 operations:

auc, update_op = tf.metrics.auc(...)

If you run sess.run(auc) you will get back the current auc value. This is the value you want to report on, for example, print sess.run([auc, cost], feed_dict={...}).

The AUC metric may need to be computed over many calls to sess.run. For example, when the dataset you're computing the AUC for doesn't fit in memory. That's where the update_op comes in. You need to call it each time to accumulate the values needed to compute auc.

So during a test set evaluation, you might have this:

for i in range(num_batches):
    sess.run([accuracy, cost, update_op], feed_dict={...})

print("Final (accumulated) AUC value):", sess.run(auc))

When you want to reset the accumulated values (before you re-evaluate your test set, for example) you should re-initialize your local variables. The tf.metrics package wisely adds its accumulator variables to the local variables collection, which don't include trainable variables such as weights by default.

sess.run(tf.local_variables_initializer())  # Resets AUC accumulator variables

https://www.tensorflow.org/api_docs/python/tf/metrics/auc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!