From 4a3df7842ab8f305ece134aa223801007d55c4f9 Mon Sep 17 00:00:00 2001 From: Ross Wightman Date: Thu, 29 Oct 2020 14:04:15 -0700 Subject: [PATCH] Fix topn metric view regression on PyTorch 1.7 --- timm/utils/metrics.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/timm/utils/metrics.py b/timm/utils/metrics.py index 08f9a9b3..8e0b1f99 100644 --- a/timm/utils/metrics.py +++ b/timm/utils/metrics.py @@ -28,5 +28,5 @@ def accuracy(output, target, topk=(1,)): batch_size = target.size(0) _, pred = output.topk(maxk, 1, True, True) pred = pred.t() - correct = pred.eq(target.view(1, -1).expand_as(pred)) - return [correct[:k].view(-1).float().sum(0) * 100. / batch_size for k in topk] + correct = pred.eq(target.reshape(1, -1).expand_as(pred)) + return [correct[:k].reshape(-1).float().sum(0) * 100. / batch_size for k in topk]