Hi.
Top-K Metrics are widely used in assessing the quality of Multi-Label classification.
I didn’t find metrics on pytorch that can be used for monitoring multi-label classification training out of the box. I tried using this 2 (Edited following @Eta_C comment ).
But got some error
output = torch.randn(64, 134)
target = torch.randn(64, 134)

def accuracy(output, target, topk=(1,)):
    maxk = max(topk)
    batch_size = target.size(0)

    _, pred = output.topk(maxk, dim=1, largest=True, sorted=True)
    pred = pred.t()
    correct = pred.eq(target.view(1, -1).expand_as(pred))

    ret = []
    for k in topk:
        correct_k = correct[:k].contiguous().view(-1).float().sum(dim=0, keepdim=True)
        ret.append(correct_k.mul_(1. / batch_size))
    return ret
## using
acc = accuracy(output, target, topk=(1,2,5))

An error
Traceback (most recent call last):
  File "main.py", line 77, in <module>
    trainer.train(epoch)
  File "/home/xx/xxx/trainer.py", line 152, in train
    prec = accuracy(pred_attrs.data, attrs.data, topk=(1, 2, 5))
  File "/home/xx/xxx/evaluation/classification.py", line 23, in accuracy
    correct = pred.eq(target.view(1, -1).expand_as(pred))
RuntimeError: The expanded size of the tensor (64) must match the existing size (8576) at non-singleton dimension 1.  Target sizes: [5, 64].  Tensor sizes: [1, 8576]

Any suggestions how to go about this implementation?
Thank you