annotationssemantic-segmentationcocolabelme

Convert coco to labelme format


I want to convert my existing coco format into the labelme format:

Coco:

{"info":{"description":"my-project-name"},"images":[{"id":1,"width":3296,"height":2472,"file_name":"test.png"}],"annotations":[{"id":0,"iscrowd":0,"image_id":1,"category_id":1,"segmentation":[[1281.1870967741934,626.5437788018434,1235.6202764976958,726.7907834101383,1383.7124423963132,745.0175115207373,1547.752995391705,726.7907834101383,1595.5981566820276,624.2654377880185]],"bbox":[1235.6202764976958,624.2654377880185,359.97788018433175,120.75207373271883],"area":34552.81165112869},{"id":1,"iscrowd":0,"image_id":1,"category_id":1,"segmentation":[[474.6543778801842,776.9142857142858,460.98433179723486,895.3880184331798,823.2405529953916,870.3262672811061,807.2921658986174,758.6875576036867]],"bbox":[460.98433179723486,758.6875576036867,362.2562211981567,136.70046082949307],"area":40000.595896281506}],"categories":[{"id":1,"name":"leaf"}]}

Labelme:

{
  "version": "4.5.7",
  "flags": {},
  "shapes": [
    {
      "label": "frame",
      "points": [
        [
          1055.4444444444446,
          266.11111111111114
        ],
        [
          1038.7777777777778,
          2171.666666666667
        ],
        [
          1124.888888888889,
          2166.1111111111113
        ],
        [
          1144.3333333333335,
          343.8888888888889
        ],
        [
          1644.3333333333335,
          349.44444444444446
        ],
        [
          1644.3333333333335,
          2168.888888888889
        ],
        [
          1736.0,
          2171.666666666667
        ],
        [
          1727.6666666666667,
          260.55555555555554
        ]
      ],
      "group_id": 1,
      "shape_type": "polygon",
      "flags": {}
    },

It's not clear to my why labelme stores a polygon as points. How to convert my polygon list of coco into a point-polygon list for labelme?


Solution

  • My classmates and I have created a python package called PyLabel to help others with this kind of task and other labelling tasks. You can see an example in this notebook: https://github.com/pylabel-project/samples/blob/main/coco2voc.ipynb

    While this may not directly go to the labelme format, you should be able to use the package's importer tool to import your data to a dataframe that you can then use to convert it to your desired format.

    If you're interested in converting between other formats, you can find the code for the package here: https://github.com/pylabel-project/