Mask_RCNN
                                
                                
                                
                                    Mask_RCNN copied to clipboard
                            
                            
                            
                        Extracting the coordinates of the predicted polygons after model.detect
Run object detection
results = model.detect([image], verbose=1)
Display results
ax = get_ax(1) r = results[0] visualize.display_instances(image, r['rois'], r['masks'], r['class_ids'], dataset.class_names, r['scores'], ax=ax, title="Predictions") log("gt_class_id", gt_class_id) log("gt_bbox", gt_bbox) log("gt_mask", gt_mask) How to extract the x,y coordinates of the predicted polygons?
I think this should work for you, I think under segmentation each pair is x,y! I think this was asked before but I couldn't find the question I used this on.
 temp_mask = r['masks'].astype(int)
 # Here we just take the first mask to see if it works
 ground_truth_binary_mask = np.array(temp_mask[:,:,1], dtype=np.uint8)
 fortran_ground_truth_binary_mask = np.asfortranarray(ground_truth_binary_mask)
 encoded_ground_truth = mask.encode(fortran_ground_truth_binary_mask)
 ground_truth_area = mask.area(encoded_ground_truth)
 ground_truth_bounding_box = mask.toBbox(encoded_ground_truth)
 contours = measure.find_contours(ground_truth_binary_mask, 0.5)
 annotation = {
         "segmentation": [],
         "area": ground_truth_area.tolist(),
         "iscrowd": 0,
         "image_id": 123,
         "bbox": ground_truth_bounding_box.tolist(),
         "category_id": 1,
         "id": 1
     }
 
 for contour in contours:
     contour = np.flip(contour, axis=1)
     segmentation = contour.ravel().tolist()
     annotation["segmentation"].append(segmentation)
     
 print(json.dumps(annotation, indent=4))
                                    
                                    
                                    
                                
Hi @induparkavi , This one can help you: https://github.com/cocodataset/cocoapi/issues/39#issuecomment-456641698
I think this should work for you, I think under segmentation each pair is x,y! I think this was asked before but I couldn't find the question I used this on.
temp_mask = r['masks'].astype(int) # Here we just take the first mask to see if it works ground_truth_binary_mask = np.array(temp_mask[:,:,1], dtype=np.uint8) fortran_ground_truth_binary_mask = np.asfortranarray(ground_truth_binary_mask) encoded_ground_truth = mask.encode(fortran_ground_truth_binary_mask) ground_truth_area = mask.area(encoded_ground_truth) ground_truth_bounding_box = mask.toBbox(encoded_ground_truth) contours = measure.find_contours(ground_truth_binary_mask, 0.5) annotation = { "segmentation": [], "area": ground_truth_area.tolist(), "iscrowd": 0, "image_id": 123, "bbox": ground_truth_bounding_box.tolist(), "category_id": 1, "id": 1 } for contour in contours: contour = np.flip(contour, axis=1) segmentation = contour.ravel().tolist() annotation["segmentation"].append(segmentation) print(json.dumps(annotation, indent=4))
What is "mask" here? Not defined before. @marcfielding1
Did someone figure this out????
I think this should work for you, I think under segmentation each pair is x,y! I think this was asked before but I couldn't find the question I used this on.
temp_mask = r['masks'].astype(int) # Here we just take the first mask to see if it works ground_truth_binary_mask = np.array(temp_mask[:,:,1], dtype=np.uint8) fortran_ground_truth_binary_mask = np.asfortranarray(ground_truth_binary_mask) encoded_ground_truth = mask.encode(fortran_ground_truth_binary_mask) ground_truth_area = mask.area(encoded_ground_truth) ground_truth_bounding_box = mask.toBbox(encoded_ground_truth) contours = measure.find_contours(ground_truth_binary_mask, 0.5) annotation = { "segmentation": [], "area": ground_truth_area.tolist(), "iscrowd": 0, "image_id": 123, "bbox": ground_truth_bounding_box.tolist(), "category_id": 1, "id": 1 } for contour in contours: contour = np.flip(contour, axis=1) segmentation = contour.ravel().tolist() annotation["segmentation"].append(segmentation) print(json.dumps(annotation, indent=4))What is "mask" here? Not defined before. @marcfielding1
@hamzahkhan
from pycocotools import mask