Image Segmentation Load COCO JSON Labels and Images for Training

Hello everyone, we have created labels for training an image panoptic segmentation model (to identify and locate multiple unique instances) using COCO JSON format (attached for reference).
0319_730990070047

0319_730990070047.png___fuse

{
    "info": {
        "description": "This is dataset.",
        "url": "https://superannotate.ai",
        "version": "1.0",
        "year": 2021,
        "contributor": "Superannotate AI",
        "date_created": "22/11/2021"
    },
    "licenses": [
        {
            "url": "https://superannotate.ai",
            "id": 1,
            "name": "Superannotate AI"
        }
    ],
    "images": [
        {
            "id": 1,
            "file_name": "1020_302810060008.png",
            "height": 136,
            "width": 87,
            "license": 1
        },
        {
            "id": 2,
            "file_name": "0319_730990070047.png",
            "height": 150,
            "width": 137,
            "license": 1
        },
        {
            "id": 3,
            "file_name": "grid_029_614.tif",
            "height": 282,
            "width": 252,
            "license": 1
        },
        {
            "id": 4,
            "file_name": "grid_001_84.tif",
            "height": 354,
            "width": 211,
            "license": 1
        }
    ],
    "annotations": [
        {
            "image_id": 1,
            "file_name": "1020_302810060008.png",
            "segments_info": [
                {
                    "id": 1,
                    "category_id": 987398,
                    "area": 2185,
                    "bbox": [
                        0.0,
                        0.0,
                        87.0,
                        131.0
                    ],
                    "iscrowd": 0
                },
                {
                    "id": 2,
                    "category_id": 987396,
                    "area": 3200,
                    "bbox": [
                        0.0,
                        12.0,
                        87.0,
                        124.0
                    ],
                    "iscrowd": 0
                },
                {
                    "id": 3,
                    "category_id": 987394,
                    "area": 6447,
                    "bbox": [
                        0.0,
                        18.0,
                        87.0,
                        106.0
                    ],
                    "iscrowd": 0
                }
            ]
        },
        {
            "image_id": 2,
            "file_name": "0319_730990070047.png",
            "segments_info": [
                {
                    "id": 4,
                    "category_id": 992499,
                    "area": 312,
                    "bbox": [
                        34.0,
                        80.0,
                        55.0,
                        70.0
                    ],
                    "iscrowd": 0
                },
                {
                    "id": 5,
                    "category_id": 987394,
                    "area": 2731,
                    "bbox": [
                        23.0,
                        1.0,
                        114.0,
                        141.0
                    ],
                    "iscrowd": 0
                },
                {
                    "id": 6,
                    "category_id": 987395,
                    "area": 2738,
                    "bbox": [
                        73.0,
                        4.0,
                        63.0,
                        101.0
                    ],
                    "iscrowd": 0
                },
                {
                    "id": 7,
                    "category_id": 987396,
                    "area": 2744,
                    "bbox": [
                        0.0,
                        70.0,
                        83.0,
                        80.0
                    ],
                    "iscrowd": 0
                },
                {
                    "id": 8,
                    "category_id": 987398,
                    "area": 3615,
                    "bbox": [
                        51.0,
                        65.0,
                        86.0,
                        85.0
                    ],
                    "iscrowd": 0
                },
                {
                    "id": 9,
                    "category_id": 987399,
                    "area": 196,
                    "bbox": [
                        45.0,
                        82.0,
                        25.0,
                        15.0
                    ],
                    "iscrowd": 0
                }
            ]
        },
        {
            "image_id": 3,
            "file_name": "grid_029_614.tif",
            "segments_info": [
                {
                    "id": 10,
                    "category_id": 987393,
                    "area": 25121,
                    "bbox": [
                        22.0,
                        125.0,
                        230.0,
                        157.0
                    ],
                    "iscrowd": 0
                },
                {
                    "id": 11,
                    "category_id": 987394,
                    "area": 27136,
                    "bbox": [
                        0.0,
                        1.0,
                        230.0,
                        163.0
                    ],
                    "iscrowd": 0
                }
            ]
        },
        {
            "image_id": 4,
            "file_name": "grid_001_84.tif",
            "segments_info": [
                {
                    "id": 12,
                    "category_id": 987394,
                    "area": 36729,
                    "bbox": [
                        20.0,
                        129.0,
                        176.0,
                        225.0
                    ],
                    "iscrowd": 0
                },
                {
                    "id": 13,
                    "category_id": 987393,
                    "area": 26854,
                    "bbox": [
                        1.0,
                        0.0,
                        210.0,
                        217.0
                    ],
                    "iscrowd": 0
                }
            ]
        }
    ],
    "categories": [
        {
            "id": 987393,
            "name": "Ongoing Construction Activity",
            "supercategory": "Ongoing Construction Activity",
            "isthing": 1,
            "color": [
                1,
                17,
                15
            ]
        },
        {
            "id": 987394,
            "name": "Completed Building",
            "supercategory": "Completed Building",
            "isthing": 1,
            "color": [
                2,
                17,
                15
            ]
        },
        {
            "id": 987395,
            "name": "Grass",
            "supercategory": "Grass",
            "isthing": 1,
            "color": [
                3,
                17,
                15
            ]
        },
        {
            "id": 987396,
            "name": "Clean Land",
            "supercategory": "Clean Land",
            "isthing": 1,
            "color": [
                4,
                17,
                15
            ]
        },
        {
            "id": 987397,
            "name": "Car",
            "supercategory": "Car",
            "isthing": 1,
            "color": [
                5,
                17,
                15
            ]
        },
        {
            "id": 987398,
            "name": "Tree",
            "supercategory": "Tree",
            "isthing": 1,
            "color": [
                6,
                17,
                15
            ]
        },
        {
            "id": 987399,
            "name": "Water Body",
            "supercategory": "Water Body",
            "isthing": 1,
            "color": [
                7,
                17,
                15
            ]
        },
        {
            "id": 987400,
            "name": "Snow",
            "supercategory": "Snow",
            "isthing": 1,
            "color": [
                8,
                17,
                15
            ]
        },
        {
            "id": 992499,
            "name": "Background",
            "supercategory": "Background",
            "isthing": 1,
            "color": [
                243,
                36,
                15
            ]
        }
    ]
}

What is the best method to load these labels inside the JSON file, as well as the corresponding images into a DataBlock for training?

Thanks!

Hi, looks like pycocotools can be used here. Typically one can do:

# see https://github.com/cocodataset/cocoapi/
from pycocotools.coco import COCO
coco = COCO(annotation_file)
coco.anns

Thank you very much. I will check that.

it does not seem to like it…