HumanSignal / label-studio-converter

Tools for converting Label Studio annotations into common dataset formats
https://labelstud.io/
262 stars 130 forks source link

Error converting to COCO using any of the `config.xml` configuration #56

Closed ansonnn07 closed 3 years ago

ansonnn07 commented 3 years ago

FYI, I'm using this for a specific project, and I need to convert to COCO JSON format.

I'm using this config.xml configuration obtained from here: https://github.com/heartexlabs/label-studio/blob/fe31f6d300564db4fe8afb3cfeb01d0f4994b698/label_studio/annotation_templates/computer-vision/object-detection-with-bounding-boxes/config.yml#L8-L14

To reproduce:

json_path = "label_studio_segmentation.json"  # with the JSON format exported from Label Studio
converter = Converter(config="config.xml", project_dir=None)
converter.convert_to_coco(
    json_path,
    output_dir="tmp",
    is_dir=False
)

Error:

Traceback (most recent call last):
  File "c:/Users/user/Desktop/ANSON/Python Scripts/test_labelstudio_converter.py", line 37, in <module>
    converter.convert_to_coco(
  File "c:\Users\user\Desktop\ANSON\Python Scripts\label_studio_converter_ORI\label_studio_converter\converter.py", line 514, in convert_to_coco
    categories, category_name_to_id = self._get_labels()
  File "c:\Users\user\Desktop\ANSON\Python Scripts\label_studio_converter_ORI\label_studio_converter\converter.py", line 917, in _get_labels
    labels |= set(info["labels"])
KeyError: 'labels'

Feedback: The issues seem to arise from the config passed into the Converter class, and also the parse_config function shown below? https://github.com/heartexlabs/label-studio-converter/blob/69141b057776546b39625129dda2fa42cd156575/label_studio_converter/converter.py#L136-L144 I'm not sure... I'm wondering if I should just change them entirely to make it work... Please let me know if there is any solution.

KonstantinKorotaev commented 3 years ago

Hi @ansonnn07 I have fixed the issue in PR, could you please check if it helps you?

ansonnn07 commented 3 years ago

Hi @ansonnn07 I have fixed the issue in PR, could you please check if it helps you?

Yes, that's exactly the parse_config function that I'm using for my project right now, and it works perfectly. My colleague seems to got it from the official Label Studio repo or somewhere, I don't really remember.

I should have mentioned about this and made a PR also, anyway thank you 👍