def _generate_pred_bbox(self, bbox_delta, anchors):
"""get predictions boxes from bbox_delta and anchors.
Args:
bbox_delta: (dcx, dcy, dw, dh)
shape:(H*W*num_anchor, 4)
anchor: (cx, cy, h, w)
shape:(H*W*num_anchor, 4)
Output:
output: (x_min, y_min, x_max, y_max)
"""
assert bbox_delta.dim() == anchors.dim(), "dim is not equal"
pred_xy = torch.sigmoid(bbox_delta[:, :2]) + anchors[:, :2]
pred_wh = torch.exp(bbox_delta[:, 2:]) * anchors[:, 2:]
pred_bbox = torch.cat((pred_xy, pred_wh), dim=1).contiguous()
# change (cx, xy, h, w) to (x_min, y_min, x_max, y_max)
pred_bbox[:, 0:2] = pred_bbox[:, 0:2] - pred_bbox[:, 2:4] / 2
pred_bbox[:, 2:4] = pred_bbox[:, 0:2] + pred_bbox[:, 2:4]
pred_bbox[:, 0::2] = pred_bbox[:, 0::2] / self.W
pred_bbox[:, 1::2] = pred_bbox[:, 1::2] / self.H
return pred_bbox
评论列表
文章目录