How to get number of images per class from ConcatDataset

I have a ConcatDataset and i want to know how many number of images per class so that i can apply WeightedRandomSampler

I don’t think there is a better generic solution than iterating over the dataset and recording the images per class. That said, you’ll be decoding all images once just for nothing, to a solution tailored to your dataset will be much more efficient.

Best regards

Thomas

i tried this way

counts=[]
for d in data_list:
     print(len(np.unique(d.targets, return_counts=True)[1]))
     counts.append(np.unique(d.targets, return_counts=True)[1])