How to convert Yolo segment annotations to coco format?

414 views Asked by At

I am trying to convert the yolo segment Dataset to coco format. initially I used JsonToYolo from ultralytics to convert from Coco to Yolo. Now I want to do vice-versa.

I have tried some yolo to coco converter like YOLO2COCO and using fiftyone converter. These will only convert the bbox(bounding box) values into the coco format, not the segmentation values. The segmented values are Empty([]).

Coco Format:

    "annotations": [
        {
            "id": 1,
            "image_id": 1,
            "category_id": 1,
            "segmentation": [
                [
                    5131.4,
                    1099.1,
                    5014.3,
                    1079.0,
                    4918.16,
                    1093.03,
                    4878.82,
                    1161.22,
                    4881.44,
                    1205.81,
                    4898.05,
                    1264.38,
                    4934.77,
                    1283.62,
                    4904.17,
                    1302.85,
                    4982.85,
                    1323.83,
                    4988.97,
                    1338.69,
                    5090.38,
                    1307.22,
                    5135.84,
                    1288.86,
                    5183.05,
                    1283.62,
                    5168.19,
                    1227.67,
                    5179.55,
                    1217.18,
                    5184.8,
                    1199.69,
                    5214.5,
                    1157.7
                ]
            ],
            "area": 62712.0,
            "bbox": [
                4878.82,
                1079.0,
                335.68,
                259.69
            ],
            "iscrowd": 0,
            "attributes": {
                "username": "",
                "occluded": false
            }
        },

Yolo Format:

0 0.21875 0.380208 0.215625 0.390625 0.215625 0.395833 0.214062 0.401042 0.214062 0.40625 0.2125 0.411458 0.2125 0.427083 0.210938 0.432292 0.210938 0.447917 0.209375 0.453125 0.209375 0.458333 0.207813 0.463542 0.207813 0.46875 0.20625 0.473958 0.20625 0.479167 0.204688 0.484375 0.204688 0.489583 0.203125 0.494792 0.203125 0.515625 0.201562 0.520833 0.201562 0.5625 0.2 0.567708 0.2 0.59375 0.201562 0.598958 0.201562 0.651042 0.203125 0.65625 0.204688 0.651042 0.204688 0.645833 0.20625 0.640625 0.20625 0.635417 0.207813 0.630208 0.207813 0.625 0.209375 0.619792 0.209375 0.614583 0.210938 0.609375 0.210938 0.604167 0.2125 0.598958 0.2125 0.59375 0.214062 0.588542 0.214062 0.578125 0.215625 0.572917 0.215625 0.567708 0.217187 0.5625 0.217187 0.552083 0.21875 0.546875 0.21875 0.536458 0.220313 0.53125 0.220313 0.520833 0.221875 0.515625 0.221875 0.505208 0.223438 0.5 0.223438 0.489583 0.225 0.484375 0.225 0.46875 0.226562 0.463542 0.226562 0.432292 0.228125 0.427083 0.228125 0.380208

One of the alternative way is using Roboflow where the data is uploaded in yolo format and exported in coco format. But I need a script which converts the yolo annotations to coco format.

Any leads?

0

There are 0 answers