tf.metrics.accuracy讲解

tf.metrics.accuracy

tf.metrics.accuracy(
    labels,
    predictions,
    weights=None,
    metrics_collections=None,
    updates_collections=None,
    name=None
)

'''
Args:
	labels: The ground truth values, a Tensor whose shape matches predictions.
	predictions: The predicted values, a Tensor of any shape.
	weights: Optional Tensor whose rank is either 0, or the same rank as labels, and must be broadcastable to labels (i.e., all dimensions must be either 1, or the same as the corresponding labels dimension).
	metrics_collections: An optional list of collections that accuracy should be added to.
	updates_collections: An optional list of collections that update_op should be added to.
	name: An optional variable_scope name.

Returns:
		accuracy: A Tensor representing the accuracy, the value of total divided by count.
		update_op: An operation that increments the total and count variables appropriately and whose value matches accuracy.
'''

说明

根据标签 labels 和 predicts(模型的预测)来计算准确率acc
该函数会创建两个局部变量 total 和 count

The accuracy function creates two local variables, total and count that are used to compute the frequency with which predictions matches labels. This frequency is ultimately returned as accuracy: an idempotent operation that simply divides total by count.
一定要注意下面这段话:

For estimation of the metric over a stream of data, the function creates an update_op operation that updates these variables and returns the accuracy. Internally, an is_correct operation computes a Tensor with elements 1.0 where the corresponding elements of predictions and labels match and 0.0 otherwise. Then update_op increments total with the reduced sum of the product of weights and is_correct, and update_op increments count with the reduced sum of weights.
简单点就是说:如果输入是一个 a stream of data,虽然我们是一个一个batch_size的数据输入,但是我们最后返回的是在整个数据集上的准确率,因为update_op每次都会自动更新 total 和count

注意函数返回的
accuracy: A Tensor representing the accuracy, the value of total divided by count.
update_op: An operation that increments the total and count variables appropriately and whose value matches accuracy.

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值