Hi, I’m dealing with an image classification problem where I have three classes. The first class contains about 98.5% of the images and the other 2 classes 0.9% and 0.6% respectively. I’ve tried using the WeigthedRandomSampler which did give quite good results (meaning that the model doesn’t only classify images to be majority class to achieve high accuracy). However, I’ve noticed that the validation loss is consistently lower than the training loss, which seems strange to me. I think this could be due to the fact that I don’t use the sampler in the validation DataLoader and the minority classes are thus not seen an equal amount of times at validation time…
Now to solve this problem I want to use weighted CrossEntropy loss. However, I don’t fully understand what the weights should be. I have seen it mentioned before that one should give a weight tensor of [1/N1, 1/N2 … 1/Nk] for each class k  as ‘weight’ parameter to the nn.CrossEntropyLoss class. However, to me this seems strange as the loss then becomes multiplied by very small weights. Shouldn’t this weight tensor contain the inverse class frequencies instead?