pylabel icon indicating copy to clipboard operation
pylabel copied to clipboard

reindexing category id when exporting to coco json format

Open danacity opened this issue 3 years ago • 3 comments

Instead of changing the category Ids, it might be a nice feature to add a "background" category at category_id = 0, that is how other libraries do it.

danacity avatar Jan 12 '22 09:01 danacity

Hi @Daniel-R-Armstrong thank you for the idea and sorry for the late reply. The re-indexing was provided by another contributor and the reason for it is some frameworks (like detectron) start at 1 and yolo starts at 0, and the ids must be sequential.

Would be open to adding the background class too if you think it would be helpful. How would it work? Do you have example from other libraries?

alexheat avatar Jan 26 '22 04:01 alexheat

@alexheat my thought is that you just use the category ids that are feed into pylable, you add a background class at index 0 if it was not provided. if the output requires you to start at one you could either add 1 to each index or drop the background class. I suppose you would have to run a test to see if they are sequential and reindex if needed. I guess my problem with the current way is that I feed in correct id and it gets reindexed when I try to save in the same format I would expect them to have the same Ids. I am just thinking and typing, but how do you feel about saving a dictionary of the classes and their respective Id, when the data gets passed to pylable if their is values that are not in the dictionary you can just add them to the dictionary as the classes are added to the labeling tool. IceVision has a concept of a class map https://airctic.com/dev/parser/. I will have to look at some of the other data tools to see what they do.

danacity avatar Jan 26 '22 12:01 danacity

I will have to give it more thought but you might be able to apply or use the dictionary as the pandas cat.codes.

danacity avatar Jan 26 '22 13:01 danacity