HumanSignal / labelImg

LabelImg is now part of the Label Studio community. The popular image annotation tool created by Tzutalin is no longer actively being developed, but you can check out Label Studio, the open source data labeling tool for images, text, hypertext, audio, video and time-series data.
https://youtu.be/p0nR2YsCY_U
MIT License
22.73k stars 6.3k forks source link

[Feature Request] Save the XML file in the same directory as the image file is found. #663

Open jS5t3r opened 4 years ago

jS5t3r commented 4 years ago

I would like to have the feature, that annotation is saved automatically in the same path as the image file.

My problem:

I have image folders:

When I click "change_save_dir" I selsect "dataset_1". The xml files in the subdirectories are not found...

chrisrapson commented 3 years ago

I have an issue which has slightly different symptoms, but I think has the same underlying cause and solution.

If there are images within a subdirectory, labelImg finds them and loads them for me to annotate. That is convenient. However, the problem occurs if they have been labelled before, and there is an XML or TXT file in the same subdirectory with the image. In that case, the label file is not found. I think the reason is because labelImg looks in defaultSaveDir for label files, e.g. these lines in loadFile():

if self.defaultSaveDir is not None:
                basename = os.path.basename(
                    os.path.splitext(self.filePath)[0])
                xmlPath = os.path.join(self.defaultSaveDir, basename + XML_EXT)
                txtPath = os.path.join(self.defaultSaveDir, basename + TXT_EXT)

I tried calling labelImg with defaultSaveDir = None, but it still loaded a defaultSaveDir from the last time I ran it (.labelImgSettings.pkl). It never reached the lines below, which presumably would have loaded the label files I wanted:

else:
                xmlPath = os.path.splitext(filePath)[0] + XML_EXT
                txtPath = os.path.splitext(filePath)[0] + TXT_EXT

Like @jS5t3r, "I would like to have the feature, that annotation is saved automatically in the same path as the image file." The default location to load a label file should also be in the same path as the image file.

Unfortunately, I think this feature requires changes in many parts of labelImg. It will not be possible to set a defaultSaveDir at the beginning and keep it fixed. The saveDir should be updated when each image is loaded. @tzutalin Please let me know if you agree and want help implementing the change. I might have time over the Christmas break to work on a PR.

There may also be a use case where label files should be stored in a common directory, separate from their image files. To support those users, it may also be necessary to add an option to use a specified directory.

UryWu commented 3 years ago

Have you solved this problem? @chrisrapson ,I can't wait!! It's so annoying.😫

chrisrapson commented 3 years ago

@UryWu no I haven't done any work on this. I was waiting to get some feedback from @tzutalin. It would be a pretty big change, so I wouldn't want to start it without discussing it with them first.

qkum commented 3 years ago

I have an issue which has slightly different symptoms, but I think has the same underlying cause and solution.

If there are images within a subdirectory, labelImg finds them and loads them for me to annotate. That is convenient. However, the problem occurs if they have been labelled before, and there is an XML or TXT file in the same subdirectory with the image. In that case, the label file is not found. I think the reason is because labelImg looks in defaultSaveDir for label files, e.g. these lines in loadFile():

if self.defaultSaveDir is not None:
                basename = os.path.basename(
                    os.path.splitext(self.filePath)[0])
                xmlPath = os.path.join(self.defaultSaveDir, basename + XML_EXT)
                txtPath = os.path.join(self.defaultSaveDir, basename + TXT_EXT)

I tried calling labelImg with defaultSaveDir = None, but it still loaded a defaultSaveDir from the last time I ran it (.labelImgSettings.pkl). It never reached the lines below, which presumably would have loaded the label files I wanted:

else:
                xmlPath = os.path.splitext(filePath)[0] + XML_EXT
                txtPath = os.path.splitext(filePath)[0] + TXT_EXT

Like @jS5t3r, "I would like to have the feature, that annotation is saved automatically in the same path as the image file." The default location to load a label file should also be in the same path as the image file.

Unfortunately, I think this feature requires changes in many parts of labelImg. It will not be possible to set a defaultSaveDir at the beginning and keep it fixed. The saveDir should be updated when each image is loaded. @tzutalin Please let me know if you agree and want help implementing the change. I might have time over the Christmas break to work on a PR.

There may also be a use case where label files should be stored in a common directory, separate from their image files. To support those users, it may also be necessary to add an option to use a specified directory.

I just had the same problem.

Thanks a lot for sharing 💯 👍 🥇

Found this solution to my problem through google.

nathan-stewart commented 10 months ago

This is not just a feature request. The current behavior is actually broken, as it saves EVERYTHING in savedir and can't handle duplicate filenames even if they came from different paths in the tree.