When I calculate the Hit Ratio, I need to calculate the number of elements of predict tensor in the target tensor, I wanna calculate the number of elements in their intersection.
For example: [# of classes: 20, # of samples: 2]
target:
tensor([[14, 13, 8, 11, 18, 12, 5, 1, 0, 10],
[ 8, 10, 2, 10, 7, 17, 6, 12, 13, 14]])
pred_idx: (HR@5):
tensor([[14, 11, 8, 19, 4],
[ 6, 9, 8, 13, 18]])
now when I do >>> (pred_idx & target).sum((1,2))
RuntimeError: The size of tensor a (5) must match the size of tensor b (10) at non-singleton dimension 1.
But the thing is, the prediction and target have different size, how can I calculate the number of elements in the pred@5 that are also in the target?