- paddle.metric. accuracy ( input, label, k=1, correct=None, total=None, name=None )
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.
input (Tensor) – The input of accuracy layer, which is the predictions of network. A Tensor with type float32,float64. The shape is
label (Tensor) – The label of dataset. Tensor with type int64. The shape is
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
Tensor, the correct rate. A Tensor with type float32.
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([, ], dtype="int64") result = paddle.metric.accuracy(input=predictions, label=label, k=1) # [0.5]