Open bertalanimre opened 5 years ago
Did you find a solution? facing the same issue
Sorry, nothing yet. Waiting for the authors reply
You can edit the data/predefined_classes.txt to load pre-defined classes
Same issue here, unfortunately
same issue
Same issue
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()
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 %
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
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 %
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)
thank you now it is working 👍
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)
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.
I had the same issue. Thanks for the solution!
My solution:
predefined_classes.txt
before labeling any imageslabelImg $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
@CrucialDrew @doitauto
I copied the code and paste it into "labelimg.py" but I am still facing the same error
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
This did not solve my issue
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.
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()
I ran labelImg with arguments as in python file and it worked without any code modification.
labelImg <image_dir> <class_file> <save_dir>
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
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?