Multiclass-Semantic-Segmentation-CamVid icon indicating copy to clipboard operation
Multiclass-Semantic-Segmentation-CamVid copied to clipboard

mask and image not necessarily synchronized

Open johngrabner opened this issue 5 years ago • 1 comments

def read_images(img_dir):
   ...
   file_list = [f for f in os.listdir(img_dir) if os.path.isfile(os.path.join(img_dir, f))]
   frames_list = [file for file in file_list if ('_L' not in file) and ('txt' not in file)]
   masks_list = [file for file in file_list if ('_L' in file) and ('txt' not in file)]

adding

for i in range(10):
        print(f"{frames_list[i]} and {masks_list[i]}")

will demonstrate the items can arrive out of order, as they did on my system.

0016E5_08115.png and 0016E5_08031_L.png
0016E5_08075.png and 0016E5_08007_L.png
0016E5_08001.png and 0016E5_08147_L.png
0016E5_07991.png and 0016E5_08107_L.png
0016E5_08157.png and 0016E5_08013_L.png
0016E5_08023.png and 0016E5_08111_L.png
0016E5_07963.png and 0016E5_07975_L.png
0016E5_08015.png and 0016E5_08067_L.png
0016E5_08139.png and 0016E5_07961_L.png
0016E5_08061.png and 0016E5_08149_L.png

a brute force fix

    masks_list = []
    frames_list = []
    for file in file_list:
        if ('_L' in file) and ('txt' not in file):
            index = file.rfind(".")
            frame_file = file[:index-2]+file[index:]
            if os.path.isfile(os.path.join(img_dir, frame_file)):
                masks_list.append(file)
                frames_list.append(frame_file)

johngrabner avatar Feb 08 '20 21:02 johngrabner

I believe that the right fix is to change this:

file_list = [f for f in os.listdir(img_dir) if os.path.isfile(os.path.join(img_dir, f))]

into that:

file_list = sorted([f for f in os.listdir(img_dir) if os.path.isfile(os.path.join(img_dir, f))])

pesekon2 avatar Apr 03 '20 17:04 pesekon2