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

Filename exception although file names and paths are the same or correct - windows issue #2

Closed
robisen1 opened this issue Apr 1, 2020 · 5 comments

Comments

@robisen1
Copy link

robisen1 commented Apr 1, 2020

I am trying to use the image_bbox_slicer in that it fits exactly my use case. My problem is that it keeps through exceptions like below no matter what filenames or paths I used. I looked at your code a little bit thinking that maybe it is my file names which are like "Scenario_10_3_1_standing_by_vehicle_150ft-0058.jpg". I did not see anything in your code that would have a problem with the file name. Do you have any suggestions on what I am doing wrong?

Exception: Each image in E:/sd_data_collection/sd_11_15_19/ripped_frames/tile_test/test_src/images must have its corresponding XML file in E:/sd_data_collection/sd_11_15_19/ripped_frames/tile_test/test_src/annotations with the same file name.

@acl21
Copy link
Owner

acl21 commented Apr 3, 2020

Are the filenames of images and their corresponding annotations similar? I mean, do you have the corresponding "Scenario_10_3_1_standing_by_vehicle_150ft-0058.xml" in the "annotations" directory.

@robisen1
Copy link
Author

robisen1 commented Apr 3, 2020

First, let me say thank you for putting this tool together. As to my issue, I believe it is Windows specific. The issue arises from how this code deals with windows paths. Here is the code:

imgs = sorted(glob.glob(img_src + '/*'))
anns = sorted(glob.glob(ann_src + '/*.xml'))

That is from helpers.py in the validate_file_names function. What happens is that on windows it adds \ instead of / and this causes the exception. Anyways I resolved it by doing:

imgs = [i.replace('\\', '/') for i in imgs]
anns = [a.replace('\\', '/') for a in imgs]

I have also been changing the code to use Pathlib and some other things. I hope to have some time next week to test on Linux/Ubuntu because I am concerned my hacks might cause issues themselves but for right now the code is doing what I need. Again thanks

@robisen1 robisen1 closed this as completed Apr 3, 2020
@acl21 acl21 changed the title Filename exception although file names and paths are the same or correct Filename exception although file names and paths are the same or correct - windows issue Apr 5, 2020
@acl21
Copy link
Owner

acl21 commented Apr 5, 2020

Thank you for pointing this out. I did not test this tool on Windows and I should have mentioned that in the docs. I will add it now. But thanks again for letting me know a potential fix around the problem.

I am glad you found the tool helpful. 😊

@mikeyEcology
Copy link

I'm getting this same error even though I'm running on Linux (Ubuntu). I can check to make sure there is an xml for each image file by running this:

im_list = os.listdir(im_src)
an_list = [x.replace("xml", "JPG") for x in os.listdir(an_src)]
list(set(im_list) - set(an_list))

Which returns []. I think this means that I don't have any images without a corresponding xml file?
But when I run

slicer.config_dirs(img_src=im_src, ann_src=an_src,
                   img_dst=im_dst, ann_dst=an_dst)

I get

in validate_file_names
raise Exception(
Exception: Each image in .../images/ must have its corresponding XML file
in .../labels/ with the same file name.

@mikeyEcology
Copy link

I solved my problem, so please ignore unless you're having a similar problem and want to try what I did. The slicer function is making sure that annotations and images filenames are exactly the same (with the exception of jpg and xml). If you're getting a similar error, you can try running this:

im_list = os.listdir(im_src)
an_list = [x.replace("xml", "JPG") for x in os.listdir(an_src)]
list(set(im_list) - set(an_list))
list(set(an_list) - set(im_list))

I had a couple of annotation files that python doesn't seem to think match up with image files (they do in terminal, but not in python), so I just deleted these two files, and it is working now.

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

3 participants