labelImg icon indicating copy to clipboard operation
labelImg copied to clipboard

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

Open jS5t3r opened this issue 4 years ago • 5 comments

  • OS: Windows
  • PyQt version: 5

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:

  • dataset_1 - folder_1 - img0.jpg - img0.xml

                         ...
     - folder_2
     - folder_3
    

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

jS5t3r avatar Oct 21 '20 13:10 jS5t3r

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.

chrisrapson avatar Dec 16 '20 00:12 chrisrapson

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

UryWu avatar Jan 10 '21 13:01 UryWu

@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.

chrisrapson avatar Jan 10 '21 20:01 chrisrapson

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.

qkum avatar Aug 24 '21 19:08 qkum

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.

nathan-stewart avatar Dec 29 '23 22:12 nathan-stewart