HumanSignal / label-studio-converter

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

Label Studio Polygons Unsupported #12

Closed loomcode closed 1 year ago

loomcode commented 4 years ago

I'd like to convert a list of JSONs I generated with the polygon tool in label studio to COCO format but it doesn't look like the code handles this use case.

loomcode commented 4 years ago

Taking an example from Detectron2, I added a polygon friendly version of your "convert_to_coco" function by making some minor changes to the bounding box loop:

            for bbox in bboxes:

                category_name = bbox['polygonlabels'][0]

                if category_name not in category_name_to_id:
                    category_id = len(categories)
                    category_name_to_id[category_name] = category_id
                    categories.append({
                        'id': category_id,
                        'name': category_name
                    })
                category_id = category_name_to_id[category_name]
                annotation_id = len(annotations)

                **poly = [(x + 0.5, y + 0.5) for x, y in bbox['points']]
                pxpy = np.array(poly)
                poly = [p for x in poly for p in x]

                annotations.append({
                    'id': annotation_id,
                    'image_id': image_id,
                    'category_id': category_id,
                    'segmentation': [poly],
                    'bbox': [np.min(pxpy[:,0]), np.min(pxpy[:,1]), np.max(pxpy[:,0]), np.max(pxpy[:,1])],
                    'ignore': 0,
                    'iscrowd': 0
                })**

Note, that I changed the bbox boundaries to absolute coords and imported numpy. It runs but I still need to check if the output works with a model.

makseq commented 4 years ago

https://github.com/heartexlabs/label-studio/issues/410

niklub commented 3 years ago

@loomcode , This functionality has been added since label-studio>=0.7.5. Can you try it out and close an issue if everything is OK ?