This solution also worked for me. My problem was not a custom dataset, but a custom-defined image augmentation transform. When I used typical torchvision.transform transformations, the data loader was iterable even with num_workers=2. However, when I added my custom-made transform, the iter(trainloader) was just freezing without any errors.
Thanks for the solution. Did not understand why this issue exists though. I also did not understand the point about using load and save rather than the default piclkle.