Skip to content

Commit

Permalink
dev(Accuracy): fix integer division error in torch1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-tong committed Sep 2, 2022
1 parent 696b03d commit fdb2de2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mmeval/classification/accuracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def _compute_metric(self,
# calculated directly without considering `topk` and `thrs`.
if predictions.ndim == 1:
correct = (predictions.int() == labels).sum(0, keepdim=True)
acc = correct / total_length
acc = correct.float() / total_length
return {'top1': acc.item()}

# compute the max topk
Expand All @@ -195,7 +195,7 @@ def _compute_metric(self,
thr_correct = correct
topk_thr_correct = thr_correct[:k].reshape(-1).sum(
0, keepdim=True)
acc = topk_thr_correct / total_length
acc = topk_thr_correct.float() / total_length
results_per_thr.append(acc.item())
results_per_topk.append(results_per_thr)

Expand Down

0 comments on commit fdb2de2

Please sign in to comment.