(self, preds, anchors)
| 37 | return targets |
| 38 | |
| 39 | def decode(self, preds, anchors): |
| 40 | if False: #self.cfg.MODEL.ATSS.REGRESSION_TYPE == 'POINT': |
| 41 | TO_REMOVE = 1 # TODO remove |
| 42 | anchors_w = anchors[:, 2] - anchors[:, 0] + TO_REMOVE |
| 43 | anchors_h = anchors[:, 3] - anchors[:, 1] + TO_REMOVE |
| 44 | anchors_cx = (anchors[:, 2] + anchors[:, 0]) / 2 |
| 45 | anchors_cy = (anchors[:, 3] + anchors[:, 1]) / 2 |
| 46 | |
| 47 | w = self.cfg.MODEL.ATSS.ANCHOR_SIZES[0] / self.cfg.MODEL.ATSS.ANCHOR_STRIDES[0] |
| 48 | x1 = anchors_cx - preds[:, 0] / w * anchors_w |
| 49 | y1 = anchors_cy - preds[:, 1] / w * anchors_h |
| 50 | x2 = anchors_cx + preds[:, 2] / w * anchors_w |
| 51 | y2 = anchors_cy + preds[:, 3] / w * anchors_h |
| 52 | pred_boxes = torch.stack([x1, y1, x2, y2], dim=1) |
| 53 | elif True: #self.cfg.MODEL.ATSS.REGRESSION_TYPE == 'BOX': |
| 54 | anchors = anchors.to(preds.dtype) |
| 55 | |
| 56 | TO_REMOVE = 1 # TODO remove |
| 57 | ex_length = anchors[:, 1] - anchors[:, 0] + TO_REMOVE |
| 58 | ex_center = (anchors[:, 1] + anchors[:, 0]) / 2 |
| 59 | |
| 60 | wx, ww = (10, 5.) |
| 61 | dx = preds[:, 0] / wx |
| 62 | dw = preds[:, 1] / ww |
| 63 | |
| 64 | # Prevent sending too large values into torch.exp() |
| 65 | dw = torch.clamp(dw, max=math.log(1000. / 16)) |
| 66 | |
| 67 | pred_ctr_x = (dx * ex_length + ex_center) |
| 68 | pred_w = (torch.exp(dw) * ex_length) |
| 69 | |
| 70 | pred_boxes = torch.zeros_like(preds) |
| 71 | pred_boxes[:, 0] = pred_ctr_x - 0.5 * (pred_w - 1) |
| 72 | pred_boxes[:, 1] = pred_ctr_x + 0.5 * (pred_w - 1) |
| 73 | return pred_boxes |
no test coverage detected