Instead of the random tensor I used in datasetA and datasetB, you should use valid data like in your ImageDataset.
From your code snippet it looks like you just have one dataset and the RandomIdentitySampler somehow samples the two batches?