RuntimeError with WeightedRandomSampler

The weights argument should contain weights for each sample, not just the class weights.
Have a look at this example.

  1. Usually you would pass num_samples = len(dataset), but you could also vary the number of samples from your DataLoader, if that’s your use case.

  2. With replacement = True each drawn sample can be drawn again. On the other hand, replacement = False still uses the weights associated with each sample, but removes a drawn sample from the set.