Co-DETR
Co-DETR copied to clipboard
How to obtain instance segmentation results from Co-DETR?
Dear @TempleX98 , @Sense-X ,
I am trying to obtain instance segmentation results, but I have not been successful yet. I follow this instance-segmentation-using-mmdetection-on-colab-part-1
def segm(self, img_brg:np.ndarray):
result = inference_detector(self.model, img_brg)
bboxes, labels, ret_mask = self._postprocess(result)
exit()
return bboxes, labels, ret_mask
def _postprocess(self, preds):
bbox_result, segm_result = preds
segm_result = segm_result[1]
bboxes = np.vstack(bbox_result)
labels = [
np.full(bbox.shape[0], i, dtype=np.int32)
for i, bbox in enumerate(bbox_result)
]
labels = np.concatenate(labels)
#Get polygon points of all labels
segms = segm_result
if segm_result is not None and len(labels) > 0:# non empty
segms = mmcv.concat_list(segm_result)
if isinstance(segms[0], torch.Tensor):
segms = torch.stack(segms, dim=0).detach().cpu().numpy()
else:
segms = np.stack(segms, axis=0)
assert segms is None or segms.shape[0] == labels.shape[0], \
'segms.shape[0] and labels.shape[0] should have the same length.'
assert segms is not None or bboxes is not None, \
'segms and bboxes should not be None at the same time.'
#Polygon points
ret_mask = []
for i, mask in enumerate(segms):
print(mask)
contours, _ = bitmap_to_polygon(mask)
ret_mask.append(contours)
return bboxes, labels, ret_mask