MCPcopy Create free account
hub / github.com/PeizeSun/SparseR-CNN / process_annotation

Method process_annotation

tests/layers/test_mask_ops.py:100–138  ·  view source on GitHub ↗
(self, ann, mask_side_len=28)

Source from the content-addressed store, hash-verified

98 self.assertTrue(res_dic["roialign"]["aligned"] > 0.95)
99
100 def process_annotation(self, ann, mask_side_len=28):
101 # Parse annotation data
102 img_info = self.coco.loadImgs(ids=[ann["image_id"]])[0]
103 height, width = img_info["height"], img_info["width"]
104 gt_polygons = [np.array(p, dtype=np.float64) for p in ann["segmentation"]]
105 gt_bbox = BoxMode.convert(ann["bbox"], BoxMode.XYWH_ABS, BoxMode.XYXY_ABS)
106 gt_bit_mask = polygons_to_bitmask(gt_polygons, height, width)
107
108 # Run rasterize ..
109 torch_gt_bbox = torch.tensor(gt_bbox).to(dtype=torch.float32).reshape(-1, 4)
110 box_bitmasks = {
111 "polygon": PolygonMasks([gt_polygons]).crop_and_resize(torch_gt_bbox, mask_side_len)[0],
112 "gridsample": rasterize_polygons_with_grid_sample(gt_bit_mask, gt_bbox, mask_side_len),
113 "roialign": BitMasks(torch.from_numpy(gt_bit_mask[None, :, :])).crop_and_resize(
114 torch_gt_bbox, mask_side_len
115 )[0],
116 }
117
118 # Run paste ..
119 results = defaultdict(dict)
120 for k, box_bitmask in box_bitmasks.items():
121 padded_bitmask, scale = pad_masks(box_bitmask[None, :, :], 1)
122 scaled_boxes = scale_boxes(torch_gt_bbox, scale)
123
124 r = results[k]
125 r["old"] = paste_mask_in_image_old(
126 padded_bitmask[0], scaled_boxes[0], height, width, threshold=0.5
127 )
128 r["aligned"] = paste_masks_in_image(
129 box_bitmask[None, :, :], Boxes(torch_gt_bbox), (height, width)
130 )[0]
131
132 table = []
133 for rasterize_method, r in results.items():
134 for paste_method, mask in r.items():
135 mask = np.asarray(mask)
136 iou = iou_between_full_image_bit_masks(gt_bit_mask.astype("uint8"), mask)
137 table.append((rasterize_method, paste_method, iou))
138 return table
139
140 def test_polygon_area(self):
141 # Draw polygon boxes

Callers 1

Calls 13

polygons_to_bitmaskFunction · 0.90
PolygonMasksClass · 0.90
BitMasksClass · 0.90
pad_masksFunction · 0.90
scale_boxesFunction · 0.90
paste_mask_in_image_oldFunction · 0.90
paste_masks_in_imageFunction · 0.90
BoxesClass · 0.90
convertMethod · 0.80
toMethod · 0.45

Tested by

no test coverage detected