TensorFlow:是否有度量标准来计算和更新前k个精度? [英] TensorFlow: Is there a metric to calculate and update top k accuracy?

查看:86
本文介绍了TensorFlow:是否有度量标准来计算和更新前k个精度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前的tf.contrib.metrics.streaming_accuracy仅能计算前1个精度,而不是前k个.作为解决方法,这是我一直在使用的:

The current tf.contrib.metrics.streaming_accuracy is only able to calculate the top 1 accuracy, and not the top k. As a workaround, this is what I've been using:

tf.reduce_mean(tf.cast(tf.nn.in_top_k(predictions=predictions, targets=labels, k=5), tf.float32))

但是,这并没有给我一种方法来计算每个批次的平均流精度,这对于获得稳定的评估准确性很有用.我目前正在使用numpy输出手动计算流式前5位的准确性,但这意味着我将无法在张量板上可视化该指标.

However, this does not give me a way to calculate the streaming accuracies averaged across each batch, which would be useful in getting a stable evaluation accuracy. I am currently manually calculating this streaming top 5 accuracy through using its numpy output, but this means I won't be able to visualize this metric on tensorboard.

是否可以通过创建precision_update函数来实现更简单的实现,或者是否已有已经执行此操作的函数?

Is there a way to have a simpler implementation by creating an accuracy_update function, or is there an existing function that already does this?

谢谢.

推荐答案

您可以将tf.contrib.metrics.streaming_accuracy的使用替换为较低级别的

You could replace your use of tf.contrib.metrics.streaming_accuracy by the lower-level tf.metrics.mean, which is by the way ultimately used by streaming_accuracy -- you will find a similarity in their respective documentations.

例如(未经测试)

tf.metrics.mean(tf.nn.in_top_k(predictions=predictions, targets=labels, k=5))

这篇关于TensorFlow:是否有度量标准来计算和更新前k个精度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆