Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mask and image not necessarily synchronized #3

Open
johngrabner opened this issue Feb 8, 2020 · 1 comment
Open

mask and image not necessarily synchronized #3

johngrabner opened this issue Feb 8, 2020 · 1 comment

Comments

@johngrabner
Copy link

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
Copy link

pesekon2 commented Apr 3, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants