Hello @tom,  thanks for your response. 
To compute the weights, I need the count for each class. But whereas in my case the sampler is used to create the datasets too. So, only after creating the datasets i can get access to the  sample count.
( I used sampler to get the indices of images and stack up images sequentially to create samples, then create datasets and load it using the DataLoader)
Do you have any suggestion for this? I can attach the code if required.
Thanks again