yolov2.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:yolov2 作者: zhangkaij 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号