Use Dataloader、ImageFolder to simultaneously load the test images and ground truth from different paths

I need to test my model using the test set and corresponding groundtruth. There are multiple subsets in the test folder and ground truth folder. Also, I need they have one-to-one relationship. How to samutaneously load the images and groundtruth without mentioning the name of subfolders (color, poke…) but only use the roots (test, ground truth)? Many thanks for your help.

The structures of folders are as follows:

test
—color
------000.png
------001.png
------002.png
—poke
------000.png
------001.png
------002.png

groundtruth
—color
------000.png
------001.png
------002.png
—poke
------000.png
------001.png
------002.png

ImageFolder will build classes based on names of the folders you have under the root, so if the underlying folders and files are exactly the same you can expect a one-to-one match between datasets made with test and groundtruth root folders. You can also check .imgs attribute of each dataset which will contain full path and label for each file and see if the one-to-one match is preserved. So if you iterate over each dateset separately with shuffle=False, you should get what you need.
However, I’m not sure how these two datasets need to be iterated in your testing pipeline.

Thanks for your reply. One root contains the original images and the other contains the corresponding ground truth, which are also images (not a classification label like “dog”). So, there is some difficulty to combine these two folders together in one dataloader.