# Accuracy¶

## 参数：¶

• topk (list[int]|tuple(int)) - 计算准确率的top个数，默认是(1,)。

• name (str, optional) - metric实例的名字，默认是'acc'。

## 代码示例¶

```import numpy as np

[0.1, 0.2, 0.3, 0.4],
[0.1, 0.4, 0.3, 0.2],
[0.1, 0.2, 0.4, 0.3],
[0.1, 0.2, 0.3, 0.4]]))
y = paddle.to_tensor(np.array([[0], [1], [2], [3]]))

correct = m.compute(x, y)
m.update(correct)
res = m.accumulate()
print(res) # 0.75
```

```import paddle

input = InputSpec([None, 1, 28, 28], 'float32', 'image')
label = InputSpec([None, 1], 'int64', 'label')
transform = T.Compose([T.Transpose(), T.Normalize([127.5], [127.5])])
train_dataset = MNIST(mode='train', transform=transform)

learning_rate=0.001, parameters=model.parameters())
model.prepare(
optim,

model.fit(train_dataset, batch_size=64)
```

## compute(pred, label, *args)¶

• pred (Tensor) - 预测结果为是float64或float32类型的Tensor。shape为[batch_size, d0, ..., dN].

• label (Tensor) - 真实的标签值是一个int64类型的Tensor，shape为[batch_size, d0, ..., 1] 或one hot表示的形状[batch_size, d0, ..., num_classes].

## update(pred, label, *args)¶

• correct (numpy.array | Tensor): 一个值为0或1的Tensor，shape是[batch_size, d0, ..., topk]。