From a484bfa9add460abe5e70a032b647742e634bf15 Mon Sep 17 00:00:00 2001 From: ClF3 Date: Tue, 19 Nov 2024 14:11:54 +0800 Subject: [PATCH] correct generate_proposal --- utils.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/utils.py b/utils.py index ccd8151..c03e451 100644 --- a/utils.py +++ b/utils.py @@ -234,9 +234,27 @@ def generate_proposal(anchors, offsets): # compute the proposal coordinates using the transformation formulas above. # ############################################################################## # Replace "pass" statement with your code - proposals = torch.zeros_like(anchors) - proposals[:, :2] = anchors[:, :2] + offsets[:, :2] * (anchors[:, 2:4] - anchors[:, :2]) - proposals[:, 2:4] = anchors[:, 2:4] * torch.exp(offsets[:, 2:4]) + x1, y1, x2, y2 =anchors[:, 0], anchors[:, 1], anchors[:, 2], anchors[:, 3] + + pw = x2 - x1 + ph = y2 - y1 + + px = x1 + 0.5 * pw + py = y1 + 0.5 * ph + + tx, ty, tw, th = offsets[:, 0], offsets[:, 1], offsets[:, 2], offsets[:, 3] + + proposal_x = px + tx * pw + proposal_y = py + ty * ph + proposal_w = pw * torch.exp(tw) + proposal_h = ph * torch.exp(th) + + proposal_x1 = proposal_x - 0.5 * proposal_w + proposal_y1 = proposal_y - 0.5 * proposal_h + proposal_x2 = proposal_x + 0.5 * proposal_w + proposal_y2 = proposal_y + 0.5 * proposal_h + + proposals = torch.stack((proposal_x1, proposal_y1, proposal_x2, proposal_y2),dim=1) ##############################################################################