Proper way of using WeightedRandomSampler()

The weight tensor should contain a weight value for each sample, while yours seem to contain the class weights.
Have a look at this example.

With replacement=True, each sample can be picked in each draw again. The number of drawn samples is defined by the num_samples argument.
On the other hand, replacement=False will still use the sample weights to draw the samples, however already picked samples will be removed from the set.

1 Like