Apply transformations to the proposals in dataset_dict, if any. Args: dataset_dict (dict): a dict read from the dataset, possibly contains fields "proposal_boxes", "proposal_objectness_logits", "proposal_bbox_mode" image_shape (tuple): height, width tran
(dataset_dict, image_shape, transforms, *, proposal_topk, min_box_size=0)
| 210 | |
| 211 | |
| 212 | def transform_proposals(dataset_dict, image_shape, transforms, *, proposal_topk, min_box_size=0): |
| 213 | """ |
| 214 | Apply transformations to the proposals in dataset_dict, if any. |
| 215 | |
| 216 | Args: |
| 217 | dataset_dict (dict): a dict read from the dataset, possibly |
| 218 | contains fields "proposal_boxes", "proposal_objectness_logits", "proposal_bbox_mode" |
| 219 | image_shape (tuple): height, width |
| 220 | transforms (TransformList): |
| 221 | proposal_topk (int): only keep top-K scoring proposals |
| 222 | min_box_size (int): proposals with either side smaller than this |
| 223 | threshold are removed |
| 224 | |
| 225 | The input dict is modified in-place, with abovementioned keys removed. A new |
| 226 | key "proposals" will be added. Its value is an `Instances` |
| 227 | object which contains the transformed proposals in its field |
| 228 | "proposal_boxes" and "objectness_logits". |
| 229 | """ |
| 230 | if "proposal_boxes" in dataset_dict: |
| 231 | # Transform proposal boxes |
| 232 | boxes = transforms.apply_box( |
| 233 | BoxMode.convert( |
| 234 | dataset_dict.pop("proposal_boxes"), |
| 235 | dataset_dict.pop("proposal_bbox_mode"), |
| 236 | BoxMode.XYXY_ABS, |
| 237 | ) |
| 238 | ) |
| 239 | boxes = Boxes(boxes) |
| 240 | objectness_logits = torch.as_tensor( |
| 241 | dataset_dict.pop("proposal_objectness_logits").astype("float32") |
| 242 | ) |
| 243 | |
| 244 | boxes.clip(image_shape) |
| 245 | keep = boxes.nonempty(threshold=min_box_size) |
| 246 | boxes = boxes[keep] |
| 247 | objectness_logits = objectness_logits[keep] |
| 248 | |
| 249 | proposals = Instances(image_shape) |
| 250 | proposals.proposal_boxes = boxes[:proposal_topk] |
| 251 | proposals.objectness_logits = objectness_logits[:proposal_topk] |
| 252 | dataset_dict["proposals"] = proposals |
| 253 | |
| 254 | |
| 255 | def transform_instance_annotations( |