Skip to content

Commit acd6c68

Browse files
committed
git push origin masterMerge branch 'yohann84L-fix_accuracy'
2 parents a16a753 + d667351 commit acd6c68

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

timm/utils/metrics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ def update(self, val, n=1):
2424

2525
def accuracy(output, target, topk=(1,)):
2626
"""Computes the accuracy over the k top predictions for the specified values of k"""
27-
maxk = max(topk)
27+
maxk = min(max(topk), output.size()[1])
2828
batch_size = target.size(0)
2929
_, pred = output.topk(maxk, 1, True, True)
3030
pred = pred.t()
3131
correct = pred.eq(target.reshape(1, -1).expand_as(pred))
32-
return [correct[:k].reshape(-1).float().sum(0) * 100. / batch_size for k in topk]
32+
return [correct[:min(k, maxk)].reshape(-1).float().sum(0) * 100. / batch_size for k in topk]

0 commit comments

Comments
 (0)