Load data with match based on the file names in two directories

I have a problem for loading my dataset as I consider to function.
I have two directories, one is considered for feeding to the ConvNet and the other one is considered for target images to be used in loss function. In this regard, I declare two data loaders to read images from directories. But when I read images that are loaded from train loader and target loader (train_loader and target_loader), they don’t load the images from both directories with the same name. Actually, I considered that the images in the train and target directories have the same name in order to match images with their target.
It seems that data_loader in pytorch load images randomly in each iteration. How can I do this purpose? please guide me.
is there another method for loading the target images in a way that they can be considered instead of labels for using in loss function? The default method is that images are loaded and the directory name is considered as their labels. How about replacing labels with images from target directory?

Thank you in advance

Implement your custom Dataset http://pytorch.org/docs/0.2.0/data.html#torch.utils.data.Dataset

Thank you very much for your help.