The network does not output raw coordinates. For each anchor it predicts four numbers that describe how to transform the anchor into the target box. The centre offsets dx and dy are expressed as a fraction of the anchor's width and height, which makes them scale-free: moving by 10% of the box means the same for a small and a large anchor. The size changes dw and dh are log-ratios, so that doubling the width is +ln 2 and halving is -ln 2, symmetric around zero and always positive when exponentiated. Encoding turns a ground-truth box into these four numbers for training, and decoding applies the predicted numbers to an anchor to get a box back.
Implement encode_boxes and decode_boxes.
(x1, y1, x2, y2). For an anchor with centre (ax, ay) and size (aw, ah) and a ground-truth box with centre (gx, gy) and size (gw, gh): dx = (gx - ax) / aw, dy = (gy - ay) / ah, dw = log(gw / aw), dh = log(gh / ah).encode_boxes(gt, anchors) takes two (N, 4) arrays and returns (N, 4) deltas [dx, dy, dw, dh].decode_boxes(deltas, anchors) is the exact inverse and returns (N, 4) boxes in (x1, y1, x2, y2).Convert corners to centre-size form first; do the maths there; convert back at the end.
decode(encode(gt, a), a) must reproduce gt.
No results yet
Run your code to check it against the examples, or submit to run every test.