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.

猜你喜欢

转载自blog.csdn.net/qq_32806793/article/details/85017215
tf
今日推荐