wkentaro / labelme

Image Polygonal Annotation with Python (polygon, rectangle, circle, line, point and image-level flag annotation).
https://labelme.io
Other
13.54k stars 3.41k forks source link

Is there a way to convert coco annotation file to labelme annotation files? #490

Closed XiaohangZhan closed 4 years ago

XiaohangZhan commented 5 years ago

I want to load LVIS annotation file (in the same format as coco) to labelme and modify the instance segmentations. It should be the inverse process of examples/instance_segmentation/labelme2coco.py.

Is there such a script?

wkentaro commented 5 years ago

No, but sounds useful if we had.

cm107 commented 4 years ago

I made a converter for Labelme to COCO. https://github.com/cm107/annotation_utils/blob/master/build/lib/annotation_utils/converter/labelme_coco_converter.py

You could do something similar for converting COCO to Labelme as well. You would have to make assumptions though. For example, all Labelme point annotations are keypoints, all rectangles are bounding boxes, and all polygons are segmentation. You would also have to assume that all point labels are contained in either a rectangle or polygon.

Labelme Parser: https://github.com/cm107/annotation_utils/blob/master/build/lib/annotation_utils/labelme/annotation/labelme_annotation.py COCO Parser: https://github.com/cm107/annotation_utils/blob/master/build/lib/annotation_utils/coco/annotation/coco_annotation.py

Edit 2020/12/9:

pip install https://github.com/cm107/annotation_utils/archive/development.zip

Here is an example:

from annotation_utils.coco.structs import COCO_Dataset

dataset = COCO_Dataset.load_from_path('annotations/instances_val2017.json', img_dir='val2017', strict=False)
labelme_handler = dataset.to_labelme()
labelme_handler.save_to_dir(json_save_dir='labelme_json', src_img_dir='val2017', overwrite=True)

travishsu commented 3 years ago

https://gist.github.com/travishsu/6efa5c9fb92ece37b4748036026342f6