Thanks for your feedback! I did write the sampler and it works as expected, but it needs optimization now since I’m using loops of lists to get the indexes and it’s very slow, but I’ll take care of that later  .
WeightedRandomSampler would work if I wanted to do oversampling and have mixed images in the same batch, but I want to keep the classes separate in this case. Sadly I didn’t find a way to make it do what I needed.