accuracy

paddle.metric. accuracy ( input, label, k=1, correct=None, total=None, name=None ) [source]

accuracy layer. Refer to the https://en.wikipedia.org/wiki/Precision_and_recall

This function computes the accuracy using the input and label. If the correct label occurs in top k predictions, then correct will increment by one. Note: the dtype of accuracy is determined by input. the input and label dtype can be different.

Parameters
  • input (Tensor) – The input of accuracy layer, which is the predictions of network. A Tensor with type float32,float64. The shape is [sample_number, class_dim] .

  • label (Tensor) – The label of dataset. Tensor with type int64 or int32. The shape is [sample_number, 1] .

  • k (int, optional) – The top k predictions for each class will be checked. Data type is int64 or int32.

  • correct (Tensor, optional) – The correct predictions count. A Tensor with type int64 or int32.

  • total (Tensor, optional) – The total entries count. A tensor with type int64 or int32.

  • name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name

Returns

Tensor, the correct rate. A Tensor with type float32.

Examples

>>> import paddle

>>> predictions = paddle.to_tensor([[0.2, 0.1, 0.4, 0.1, 0.1], [0.2, 0.3, 0.1, 0.15, 0.25]], dtype='float32')
>>> label = paddle.to_tensor([[2], [0]], dtype="int64")
>>> result = paddle.metric.accuracy(input=predictions, label=label, k=1)
>>> print(result)
Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
0.50000000)

Used in the guide/tutorials