will try that but I think the main problem is with dataloader. I ran a dataiter
vis_dataloader = DataLoader(siamese_dataset,
                        shuffle=True,
                        num_workers=8,
                        batch_size=4)
from time import perf_counter
t1=perf_counter()
dataiter = iter(vis_dataloader)
example_batch = next(dataiter)
t2 = perf_counter()

concatenated = torch.cat((example_batch[0],example_batch[1]))
imshow(torchvision.utils.make_grid(concatenated))
print(example_batch[2].numpy())

It’s taking an average of 4s. In each epoch there are around 6000 iterations. I think this is where most of the time for code is elapsing. Anyway I will try out your idea and will let you.