I am trying to apply WeightedRandomSample on single DataLoader which has two datasets with the same data size but different class distribution. I am using the following code to merge two datasets.
class TwoDatasets(Dataset):
	def __init__(self, dataset1_, dataset2_):
		self.dataset1 = dataset1_
		self.dataset2 = dataset2_

	def __getitem__(self, index):
		data1, target1 = self.dataset1[index]
		data2, target2 = self.dataset2[index]

		return (data1, target1), (data2, target2)

	def __len__(self):
		return min(len(self.dataset1), len(self.dataset2))
	

root = './path/to/dataset'	

transform = transforms.Compose([
				transforms.Resize([224, 224]), 
				transforms.ToTensor(), 
				transforms.Normalize([0.485, 0.456, 0.406], 
						 [0.229, 0.224, 0.225]), 
					])

dataset1 = datasets.ImageFolder(os.path.join(root, 'dataset1'), transform)
dataset2 = datasets.ImageFolder(os.path.join(root, 'dataset2'), transform)

two_dataset = TwoDatasets(dataset1, dataset2)
dataloader = DataLoader(two_dataset, batch_size=batch_size, sampler=?)

How I can apply Sampler to the DataLoader so that I will manage to balance both the datasets?
Thanks!