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.75k stars 6.3k forks source link

Re-Opening the app resets classes.txt #482

Open bertalanimre opened 5 years ago

bertalanimre commented 5 years ago

I have a folder with (let'a say) 1000 images. About 200 of them was already processed with labelImg to label "tag" and "mini-tag". I close the app, classes.txt have the tag and mini-tag at the end nicely. The next day I open up the folder with "Open Dir", it recognises yesterday's work. When I want to add a new class "like weapon", I add the RectBox, add the class weapon ( At this time, strangely the list doesn't contain tag and mini-tag already ), save my job and what happens? Classes.txt gets erased, and now it looks like the default classes.txt + the class "weapon". tag and mini-tag have disappeared. Every time when I re-open the application I have to add random RectBoxes with the name of the previous classes, save it, then I can only continue my work.

Why does the app resets the classes.txt and does not read it properly when I open the folder containing it?

Mahaaveer commented 5 years ago

Did you find a solution? facing the same issue

bertalanimre commented 5 years ago

Sorry, nothing yet. Waiting for the authors reply

khaitranvan96kt commented 5 years ago

You can edit the data/predefined_classes.txt to load pre-defined classes

dokluch commented 3 years ago

Same issue here, unfortunately

Niranjan2054 commented 3 years ago

same issue

alikaz3mi commented 2 years ago

Same issue

CrucialDrew commented 2 years ago

Seems simple to do:

In labelImg.py, do this:

def change_save_dir_dialog(self, _value=False):

    if self.default_save_dir is not None:
        path = ustr(self.default_save_dir)
    else:
        path = '.'

    dir_path = ustr(QFileDialog.getExistingDirectory(self,
                                                     '%s - Save annotations to the directory' % __appname__, path,  QFileDialog.ShowDirsOnly
                                                     | QFileDialog.DontResolveSymlinks))

    if os.path.exists(dir_path + "/classes.txt"):
        self.label_hist = None
        self.load_predefined_classes(dir_path + "/classes.txt")

    if dir_path is not None and len(dir_path) > 1:
        self.default_save_dir = dir_path

    self.statusBar().showMessage('%s . Annotation will be saved to %s' %
                                 ('Change saved folder', self.default_save_dir))
    self.statusBar().show()
doitauto commented 2 years ago

that gives an error by starting labelimg

@iMac-von-Arif labelImg % python3 labelImg.py File "/usr/local/lib/python3.9/site-packages/labelImg/labelImg.py", line 1283 if os.path.exists(dir_path + "/classes.txt"): IndentationError: unexpected indent arifcalhan@iMac-von-Arif labelImg %

CrucialDrew commented 2 years ago

I'm not sure how to get the indentation to work in a github comment, you'll have to fix the indents.

The only change should be:

if os.path.exists(dir_path + "/classes.txt"):
    self.label_hist = None
    self.load_predefined_classes(dir_path + "/classes.txt")

And then keep in mind you have to do the "change save dir" before it will load the classes, also that the label_hist = None line removes the predefined (or existing classes), so remove that line if you want to keep them

doitauto commented 2 years ago

i get again same error:

iMac-von-Arif labelImg % python3 labelImg.py                       
  File "/usr/local/lib/python3.9/site-packages/labelImg/labelImg.py", line 1286
    if dir_path is not None and len(dir_path) > 1:
IndentationError: unexpected indent
arifcalhan@iMac-von-Arif labelImg % 
Bildschirmfoto 2021-11-27 um 01 28 29
CrucialDrew commented 2 years ago

Yeah, well, your indentation is bad. Slide it all over so:

if os.path.exists(dir_path + "/classes.txt"):

lines up with dir_path (and the two lines below it are to the right of that) Screenshot from 2021-11-26 17-37-43

doitauto commented 2 years ago

thank you now it is working 👍

nqa112 commented 2 years ago

Yeah, well, your indentation is bad. Slide it all over so:

if os.path.exists(dir_path + "/classes.txt"):

lines up with dir_path (and the two lines below it are to the right of that) Screenshot from 2021-11-26 17-37-43

Thank you so much, waste my 2-day work because of this. I wonder why this bug is still not fixed yet, since I move from labelMe (great tool with no bug) to use YOLO.

christianepedersen commented 2 years ago

I had the same issue. Thanks for the solution!

crclz commented 2 years ago

My solution:

  1. create predefined_classes.txt before labeling any images
  2. run command: labelImg $ImageFolder $PredefinedClassesTxtPath.

For example, if you created predefined_classes.txt under the images folder (step 1), you can just cd to the images folder, and run: labelImg . predefined_classes.txt

AbdulAzizHamka commented 2 years ago

@CrucialDrew @doitauto

I copied the code and paste it into "labelimg.py" but I am still facing the same error

image

I added print ("test") just to see if the program reaches that part of the code and it didn't print the word "test" at all

Ching87 commented 2 years ago

This did not solve my issue

amaalanoosucs commented 1 year ago

I'm not sure how to get the indentation to work in a github comment, you'll have to fix the indents.

The only change should be:

if os.path.exists(dir_path + "/classes.txt"):
    self.label_hist = None
    self.load_predefined_classes(dir_path + "/classes.txt")

And then keep in mind you have to do the "change save dir" before it will load the classes, also that the label_hist = None line removes the predefined (or existing classes), so remove that line if you want to keep them

Thank you so much for the clarification. I was plagued with this issue for almost an year and I just found the fix, it's working flawlessly.

Safouane commented 1 year ago

recap locate the file labelImg.py Line 1241: def change_save_dir_dialog add the following two lines after dir_path

        if os.path.exists(dir_path + "/classes.txt"):
            self.load_predefined_classes(dir_path + "/classes.txt")

The whole function will look like this:

def change_save_dir_dialog(self, _value=False):
        if self.default_save_dir is not None:
            path = ustr(self.default_save_dir)
        else:
            path = '.'

        dir_path = ustr(QFileDialog.getExistingDirectory(self,
                                                         '%s - Save annotations to the directory' % __appname__, path,  QFileDialog.ShowDirsOnly
                                                         | QFileDialog.DontResolveSymlinks))
        if os.path.exists(dir_path + "/classes.txt"):
            self.load_predefined_classes(dir_path + "/classes.txt")

        if dir_path is not None and len(dir_path) > 1:
            self.default_save_dir = dir_path

        self.statusBar().showMessage('%s . Annotation will be saved to %s' %
                                     ('Change saved folder', self.default_save_dir))
        self.statusBar().show()
daivuongktx13 commented 10 months ago

I ran labelImg with arguments as in python file and it worked without any code modification. labelImg <image_dir> <class_file> <save_dir>

mrunalinipatil1996 commented 8 months ago

def change_save_dir_dialog(self, _value=False): if self.default_save_dir is not None: path = ustr(self.default_save_dir) else: path = '.'

    dir_path = ustr(QFileDialog.getExistingDirectory(self,
                                                     '%s - Save annotations to the directory' % __appname__, path,  QFileDialog.ShowDirsOnly
                                                     | QFileDialog.DontResolveSymlinks))

    if os.path.exists(dir_path + "/classes.txt"):
        self.load_predefined_classes(dir_path + "/classes.txt")

    if dir_path is not None and len(dir_path) > 1:
        self.default_save_dir = dir_pathw

i wrote this lines in my code ,there is no error showing but labelimg open and after image selected from folder image opened but when i press w to create rect box labelimg dirrectly closed. why this is happening? and what should i do now