(self, reference_boxes, proposals)
| 315 | self.apply_to_remove = apply_to_remove |
| 316 | |
| 317 | def encode(self, reference_boxes, proposals): |
| 318 | TO_REMOVE = self.apply_to_remove # TODO remove |
| 319 | ex_widths = proposals[..., 2] - proposals[..., 0] + TO_REMOVE |
| 320 | ex_heights = proposals[..., 3] - proposals[..., 1] + TO_REMOVE |
| 321 | ex_ctr_x = proposals[..., 0] + 0.5 * ex_widths |
| 322 | ex_ctr_y = proposals[..., 1] + 0.5 * ex_heights |
| 323 | |
| 324 | gt_widths = reference_boxes[..., 2] - reference_boxes[..., 0] + TO_REMOVE |
| 325 | gt_heights = reference_boxes[..., 3] - reference_boxes[..., 1] + TO_REMOVE |
| 326 | gt_ctr_x = reference_boxes[..., 0] + 0.5 * gt_widths |
| 327 | gt_ctr_y = reference_boxes[..., 1] + 0.5 * gt_heights |
| 328 | |
| 329 | wx, wy, ww, wh = self.weights |
| 330 | targets_dx = wx * (gt_ctr_x - ex_ctr_x) / ex_widths |
| 331 | targets_dy = wy * (gt_ctr_y - ex_ctr_y) / ex_heights |
| 332 | targets_dw = ww * Tensor.log(gt_widths / ex_widths) |
| 333 | targets_dh = wh * Tensor.log(gt_heights / ex_heights) |
| 334 | |
| 335 | targets = Tensor.stack(targets_dx, targets_dy, targets_dw, targets_dh, dim=-1) |
| 336 | return targets |
| 337 | |
| 338 | def decode(self, rel_codes, boxes): |
| 339 | boxes = boxes.cast(rel_codes.dtype) |
no test coverage detected