labelImg icon indicating copy to clipboard operation
labelImg copied to clipboard

BUG: Editing label of image annotation erases old labels in classes.txt

Open sohang3112 opened this issue 2 years ago • 7 comments

I have a folder of images and annotations, that has this classes.txt:

injectable
pills
smoking

I opened this folder in labelImg and in an image, edited the label of its existing annotation from injectable to pills, and saved changes. When I reloaded classes.txt, all items except pills had been erased by labelImg:

pills
  • OS: Windows 11
  • PyQt version: 5.15.9
  • Python version: 3.11

sohang3112 avatar Feb 22 '23 12:02 sohang3112

The reason why this happens is that the image doesn't load the "classes.txt" file and creates a new one instead. If you want to preserve your old file, you need to rename it to "predefined_classes.txt".

Although the project itself is fine, the fact that 30% of users are encountering the same issue is problematic. This highlights the importance of clear documentation.

YA2JA avatar Mar 27 '23 22:03 YA2JA

If you want to preserve your old file, you need to rename it to "predefined_classes.txt".

@YA2JA I tried this, but when I opened the folder again in labelImg, there was a FileNotFoundError as classes.txt file was not present. So I'm not sure how this is useful.

I found another solution - explicitly providing the path to classes.txt works: labelImg /path/to/images_and_labels_folder /path/to/classes.txt.

This works but it shouldn't be required in the first place - ideally labelImg should not overwrite existing classes.txt Also, I'm not sure if there is any way to explicitly specify classes.txt from the GUI.

sohang3112 avatar Mar 31 '23 07:03 sohang3112

I'm having this problem too, it's simply a serious functionality defect

kiitio avatar Apr 20 '23 14:04 kiitio

@sohang3112 Thanks to your method, but I feel that it is really necessary for the official to add a setting to the GUI to solve this problem

kiitio avatar Apr 21 '23 04:04 kiitio

@kiitio I agree, we should be able to do this from the GUI

sohang3112 avatar Apr 21 '23 14:04 sohang3112

FWIW (it's not pretty, but it works for me) I'm exporting to YOLO format.

I've made these edits; In labelimg/libs/yolo_io.py on line 57, 62 and 91 change path to the root dir of your images folder to prevent labelimg from creating multiple 'classes.txt' files when you're labeling in subfolders. = "C:/path_to_project_folder/images/classes.txt"

In labelimg/labelimg.py on line 1699 change path to your now static classes.txt file to prevent labelimg from overwriting your labels. default= "C:/path_to_project_folder/images/classes.txt",

Make sure you delete the original file in labelimg/data

And if you run into this error: TypeError: expected str, bytes or os.PathLike object, not NoneType Delete the settings file in your Users folder. (User folder of your OS) .labelImgSettings.pkl

*You can also increase the zoom-in factor with mouse wheel scrolling in labelimg.py on lines 1048-1051

IMO, this is one of the fastest methods to annotate images with a bounding box. *Fast scroll, A - D (prev-next), W (bounding box), single class mode, auto save, etc...

I get through images way faster than in label studio because they put binds all the way on the right of the keyboard.

Hopefully that helps someone.

BerserkeR-Git avatar Jul 25 '23 11:07 BerserkeR-Git

FWIW (it's not pretty, but it works for me) I'm exporting to YOLO format.

I've made these edits; In labelimg/libs/yolo_io.py on line 57, 62 and 91 change path to the root dir of your images folder to prevent labelimg from creating multiple 'classes.txt' files when you're labeling in subfolders. = "C:/path_to_project_folder/images/classes.txt"

In labelimg/labelimg.py on line 1699 change path to your now static classes.txt file to prevent labelimg from overwriting your labels. default= "C:/path_to_project_folder/images/classes.txt",

Make sure you delete the original file in labelimg/data

And if you run into this error: TypeError: expected str, bytes or os.PathLike object, not NoneType Delete the settings file in your Users folder. (User folder of your OS) .labelImgSettings.pkl

*You can also increase the zoom-in factor with mouse wheel scrolling in labelimg.py on lines 1048-1051

IMO, this is one of the fastest methods to annotate images with a bounding box. *Fast scroll, A - D (prev-next), W (bounding box), single class mode, auto save, etc...

I get through images way faster than in label studio because they put binds all the way on the right of the keyboard.

Hopefully that helps someone.

Thanks for your help. I did everything you said but, when I close and reopen LabelImg, the contents of classes.txt are still being overwritten with new labels. For example, I label my class as 'apple.' I close the program and reopen it. When I label 'orange,' it assigns '0' label for both classes. How can i fix it ?

cestcode avatar Nov 22 '23 20:11 cestcode