How to creat MyDataset(data.Dataset)?

I want to load two datasets in an iter with DataLoader to achieve multi-task.

For example, i have two datasets, A, B. I set the batchsize to 30 for DataLoader, and i want get 10 images from A, 20 images from B, how can I do?

You could create a custom Dataset and return a single sample from A and two from B.
Using a batch size of 10, each batch would then contain the desired amount of samples from each dataset.
However, to properly implement it, we would need to know if the lengths of both datasets match, i.e. len(A) * 2 == len(B)?