correct generate_proposal

This commit is contained in:
ClF3 2024-11-19 14:11:54 +08:00
parent 36651b22de
commit a484bfa9ad
1 changed files with 21 additions and 3 deletions

View File

@ -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)
##############################################################################