facebookresearch / Generic-Grouping

Open-source code for Generic Grouping Network (GGN, CVPR 2022)
Other
109 stars 12 forks source link

How to acquire ADE20K data in class-agnostic setting #15

Open wangchust opened 1 year ago

wangchust commented 1 year ago

Hi, thanks for your great work. Could you pls provide scripts transferring ADE20K to class-agnostic COCO format?

weiyaowang commented 1 year ago

Please check the following. Let me know if you have any questions:

def ade_inst2rle(img_instance_folder, orig_img):
    img_paths = os.listdir(img_instance_folder)
    masks = []
    for img_path in img_paths:
        ade_img = cv2.imread(img_instance_folder + "/" + img_path)
        # un-occluded is 255; occluded is 128
        mask = ade_img[..., 0] == 255
        masks.append(mask)
    masks = np.stack(masks)
    masks = np.transpose(masks[:, :, :], (1, 2, 0))
    rles = maskUtils.encode(np.asfortranarray(masks))
    areas = areas = maskUtils.area(rles)
    bboxes = maskUtils.toBbox(rles)
    anns = []
    for i, rle in enumerate(rles):
        new_rle = rle
        if type(new_rle["counts"]) == bytes:
            new_rle["counts"] = new_rle["counts"].decode("ascii")
        ann = {
            "segmentation": new_rle,
            "area": int(areas[i]),
            "bbox": [int(coord) for coord in bboxes[i]],
            "instance_img": img_paths[i],
            "orig_img_file": orig_img,
            "category_id": 1,
            "rank": i,
        }
        anns.append(ann)
    return anns
wangchust commented 1 year ago

Thanks for your kind response. It helps me a lot!

wangchust commented 1 year ago

By the way, I see there are two versions of ADE20K, which are v16 and v21. I wonder which one is used in your work?

weiyaowang commented 1 year ago

Do you have a reference for the difference of the version? I think the version I used is downloaded in 2021, but would like to know the difference here.