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.15k stars 6.23k forks source link

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

Open sohang3112 opened 1 year ago

sohang3112 commented 1 year ago

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
YA2JA commented 1 year ago

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.

sohang3112 commented 1 year ago

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.

kiitio commented 1 year ago

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

kiitio commented 1 year ago

@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

sohang3112 commented 1 year ago

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

BerserkeR-Git commented 11 months ago

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.

cestcode commented 7 months ago

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 ?