advaitsave / Multiclass-Semantic-Segmentation-CamVid

Tensorflow 2 implementation of complete pipeline for multiclass image semantic segmentation using UNet, SegNet and FCN32 architectures on Cambridge-driving Labeled Video Database (CamVid) dataset.
82 stars 41 forks source link

mask and image not necessarily synchronized #3

Open johngrabner opened 4 years ago

johngrabner commented 4 years ago
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)
pesekon2 commented 4 years ago

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))])