Torch.expand_as() not working for tensors of different shape

Hi everyone
I am trying to calculate the top-n accuracy of a VQA model but every time it throwing an error regarding incompatible shape. I got the top-n code from here https://github.com/pprp/timm/blob/master/timm/utils/metrics.py

def accuracy(output, target, topk=(1,)):
    maxk = min(max(topk), output.size()[1])
    batch_size = target.size(0)
    _, pred = output.topk(maxk, 1, True, True)
    pred = pred.t()
    print(pred.shape)
    correct = pred.eq(target.reshape(1, -1).expand_as(pred))
    return [correct[:min(k, maxk)].reshape(-1).float().sum(0) * 100. / batch_size for k in topk]

Is there any way I can mitigate the issue?

Could you post the full error message as well as the tensor shapes causing it?

Sorry for not giving them in my previous post.

The tensor shapes are for a batch of data

pred = torch.size(64, 830)
target = torch.size(64, 830)

After getting the top-k predictions, I am getting the pred shape as follows torch.size(10, 64). After which I am getting a runtime error

RuntimeError: The expanded size of the tensor (64) must match the existing size (53120) at non-singleton dimension 1.  Target sizes: [10, 64].  Tensor sizes: [1, 53120]