Get box regression transformation deltas (dx, dy, dw, dh) that can be used to transform the `src_boxes` into the `target_boxes`. That is, the relation ``target_boxes == self.apply_deltas(deltas, src_boxes)`` is true (unless any delta is too large and is clamped).
(self, src_boxes, target_boxes)
| 41 | self.scale_clamp = scale_clamp |
| 42 | |
| 43 | def get_deltas(self, src_boxes, target_boxes): |
| 44 | """ |
| 45 | Get box regression transformation deltas (dx, dy, dw, dh) that can be used |
| 46 | to transform the `src_boxes` into the `target_boxes`. That is, the relation |
| 47 | ``target_boxes == self.apply_deltas(deltas, src_boxes)`` is true (unless |
| 48 | any delta is too large and is clamped). |
| 49 | |
| 50 | Args: |
| 51 | src_boxes (Tensor): source boxes, e.g., object proposals |
| 52 | target_boxes (Tensor): target of the transformation, e.g., ground-truth |
| 53 | boxes. |
| 54 | """ |
| 55 | assert isinstance(src_boxes, torch.Tensor), type(src_boxes) |
| 56 | assert isinstance(target_boxes, torch.Tensor), type(target_boxes) |
| 57 | |
| 58 | src_widths = src_boxes[:, 2] - src_boxes[:, 0] |
| 59 | src_heights = src_boxes[:, 3] - src_boxes[:, 1] |
| 60 | src_ctr_x = src_boxes[:, 0] + 0.5 * src_widths |
| 61 | src_ctr_y = src_boxes[:, 1] + 0.5 * src_heights |
| 62 | |
| 63 | target_widths = target_boxes[:, 2] - target_boxes[:, 0] |
| 64 | target_heights = target_boxes[:, 3] - target_boxes[:, 1] |
| 65 | target_ctr_x = target_boxes[:, 0] + 0.5 * target_widths |
| 66 | target_ctr_y = target_boxes[:, 1] + 0.5 * target_heights |
| 67 | |
| 68 | wx, wy, ww, wh = self.weights |
| 69 | dx = wx * (target_ctr_x - src_ctr_x) / src_widths |
| 70 | dy = wy * (target_ctr_y - src_ctr_y) / src_heights |
| 71 | dw = ww * torch.log(target_widths / src_widths) |
| 72 | dh = wh * torch.log(target_heights / src_heights) |
| 73 | |
| 74 | deltas = torch.stack((dx, dy, dw, dh), dim=1) |
| 75 | assert (src_widths > 0).all().item(), "Input boxes to Box2BoxTransform are not valid!" |
| 76 | return deltas |
| 77 | |
| 78 | def apply_deltas(self, deltas, boxes): |
| 79 | """ |
no outgoing calls