MCPcopy
hub / github.com/hustvl/Vim / get_deltas

Method get_deltas

det/detectron2/modeling/box_regression.py:43–76  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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 """

Callers 4

test_reconstructionMethod · 0.95
get_ground_truthMethod · 0.45

Calls

no outgoing calls

Tested by 1

test_reconstructionMethod · 0.76