delta_bbox_coder.py 1.3 KB
Newer Older
B
Blake 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
import paddle
import numpy as np
from ppdet.core.workspace import register
from ppdet.modeling.bbox_utils import delta2bbox_v2, bbox2delta_v2

__all__ = ['DeltaBBoxCoder']


@register
class DeltaBBoxCoder:
    """Encode bboxes in terms of delta/offset of a reference bbox.
    Args:
        norm_mean (list[float]): the mean to normalize delta
        norm_std (list[float]): the std to normalize delta
        wh_ratio_clip (float): to clip delta wh of decoded bboxes
        ctr_clip (float or None): whether to clip delta xy of decoded bboxes
    """
    def __init__(self,
                 norm_mean=[0.0, 0.0, 0.0, 0.0],
                 norm_std=[1., 1., 1., 1.],
                 wh_ratio_clip=16/1000.0,
                 ctr_clip=None):
        self.norm_mean = norm_mean
        self.norm_std = norm_std
        self.wh_ratio_clip = wh_ratio_clip
        self.ctr_clip = ctr_clip

    def encode(self, bboxes, tar_bboxes):
        return bbox2delta_v2(
            bboxes, tar_bboxes, means=self.norm_mean, stds=self.norm_std)

    def decode(self, bboxes, deltas, max_shape=None):
        return delta2bbox_v2(
            bboxes,
            deltas,
            max_shape=max_shape,
            wh_ratio_clip=self.wh_ratio_clip,
            ctr_clip=self.ctr_clip,
            means=self.norm_mean,
            stds=self.norm_std)