How to load images in the same folder in Pytorch?
I want to load all of the images from the folder /img and /mask respectively. The data structure can be shown as follows:

data
    img
        0.png
        1.png
        2.png
        3.png
        ...
   mask
       label_0.png
       label_1.png
       label_2.png
       ...


Hopefully for help.

If you want to load all the images from the two folders then you can try cv2

import cv2

img = []
for i in range(n): # n = number of images in img folder
    img_path = f'~data\img\{i}.png' # replace ~ with full path 
    img.append(cv2.imread(img_path))

for i in range(n): # n = number of images in mask folder
    img_path = f'~data\mask\lable_{i}.png' # replace ~ with full path
    img.append(cv2.imread(img_path))

