facebookresearch/Mask2Former

Support for BitMask

satpalsr opened this issue · 3 comments

Support requested for training coco instance segmentation with annotations in the bitmask format. It's useful in case when the object has some empty space within it or is divided into two parts.

Maybe https://github.com/facebookresearch/Mask2Former/blob/main/mask2former/data/dataset_mappers/mask_former_instance_dataset_mapper.py is what you are looking for?

BTW, COCO polygon is still able to handle objects split into multiple parts.

There is a config parameter for it ('INPUT.MASK_FORMAT', "bitmask",), but it wasnt sufficient for me.
What worked for me, depending on the dataset_mapper you use, is to change the line
instances = utils.annotations_to_instances(sorted_annos, image_shape)
to
instances = utils.annotations_to_instances(sorted_annos, image_shape, mask_format="bitmask")

Hey @VGrondin, This is for converting polygon to bitmask format? I already have bitmask format and want to use that.

I have this format json file (similar to cocostuff):

{
"info": {"description": "Dataset for instance segmentation"},
"categories": [{"id": 0, "name": "object_name"}],
"images": [
{"id": 0, "width": 640, "height": 360, "file_name": "000000.png"},
{"id": 10, "width": 640, "height": 360, "file_name": "000010.png"}
],
"annotations": [
{"id": 0, "image_id": 0, "category_id": 0, "segmentation": {"size": [360, 640], "counts": "iT^25Q;a0_O4M2M5K3M3M3M3M2O2M3M2N3M2N3M2O2M2O2N1O101O001O000000000000O2O0000001N101N1O2N100O2N2N101O0O2O1M2N3M3M2N3M3M3M3M3M3M3M3M3M4L4L4KTek3"}, "area": 4745, "bbox": [222, 69, 287, 142], "iscrowd": 0},
{"id": 10, "image_id": 10, "category_id": 0, "segmentation": {"size": [360, 640], "counts": "jTX4313k:8M3L4M3M6I3N2N1O2M3N2N2N1O2N2N2N1O200O1N101N2O1O1O001O1O1O010O1O1O10O01O00000O10O101N2O1N2O0O2N2N2O1N1O2N2N2O1N1O2N2N2N2N1O2N2O1O1N1O2M3N2N2J5O2M3M3LTTn1"}, "area": 5175, "bbox": [387, 75, 462, 144], "iscrowd": 0}
]
}

@bowenc0221 I should use the below format with your suggested mapper?

{
{"file_name": "000002.png", "image_id": 2, "height": 360, "width": 640, "annotations": [{"bbox": [239, 111, 358, 244], "bbox_mode": 0, "category_id": 0, "segmentation": {"size": [360, 640], "counts": "iT^25Q;a0_O4M2M5K3M3M3M3M2O2M3M2N3M2N3M2O2M2O2N1O101O001O000000000000O2O0000001N101N1O2N100O2N2N101O0O2O1M2N3M3M2N3M3M3M3M3M3M3M3M3M4L4L4KTek3"}}]},
{"file_name": "000003.png", "image_id": 3, "height": 360, "width": 640, "annotations": [{"bbox": [247, 111, 364, 241], "bbox_mode": 0, "category_id": 0, "segmentation": {"size": [360, 640], "counts": "jTX4313k:8M3L4M3M6I3N2N1O2M3N2N2N1O2N2N2N1O200O1N101N2O1O1O001O1O1O010O1O1O10O01O00000O10O101N2O1N2O0O2N2N2O1N1O2N2N2O1N1O2N2N2N2N1O2N2O1O1N1O2M3N2N2J5O2M3M3LTTn1"}}]}
}