Thanks for your kind help! I have not solved this problem yet. I just walked around this problem by using ImageFolder, which is super helpful. I prepared my dataset as the requirement of ImageFolder, then every transform function worked smoothly!