This helped me a lot, I have a question regarding one of the lines in your code. Why do this
for img_path in img_files:
             self.mask_files.append(os.path.join(folder_path,'mask',os.path.basename(img_path)) 

and not use the glob.glob method for img_files? Wouldn’t the label files be in the same order as the img_files if they both have the same name?