Solved by ptrblck in post #10 
              
              
                You would have to map these indices to [0, nb_classes-1] as described in the previous post. 
EDIT: here is a code snippet in case you get stuck: 
target = torch.randint(3, 6, (10,))
print(target)
> tensor([3, 4, 3, 3, 3, 5, 5, 4, 3, 4])

unique = torch.unique(target)
for i, u in enumerate(unique):
 …