There may be a mistake that the elements of first dist.size()[0] at dim 1 are always set to -1, since the features are from a minibatch. The right way is:
dist = torch.mm(features, trainFeatures) # instead of features here
dist[torch.arange(dist.size()[0]), index] = -1 ##Self-contrast set to -1
as mentioned in https://github.com/DiegoOrtego/LabelNoiseMOIT/issues/5 , there also exits an error in your code: