(points, heights, offsets, stride=1, wh_ratio = 0.41, max_shape=None, upper_factor=0.4, is_upper=True, is_left=True)
return torch.stack([x1, y1, x2, y2], -1)
Decode height and offset prediction to bounding box.

        Args:
            points (Tensor): Shape (n, 2), [x, y].
            heights (Tensor): height of the bounding box
            offsets (Tensor): offset of the bounding box center.
            stride: stride of coordinates
            wh_ratio: ratio of width and height, equal to width/height
            max_shape (tuple): Shape of the image.

        Returns:
            Tensor: Decoded bboxes.
Decode height and offset prediction to bounding box.
Decode height and offset prediction to bounding box .
def csp_height2bbox_four_part(points, heights, offsets, stride=1, wh_ratio = 0.41, max_shape=None, upper_factor=0.4, is_upper=True, is_left=True):
    """Decode height and offset prediction to bounding box.

        Args:
            points (Tensor): Shape (n, 2), [x, y].
            heights (Tensor): height of the bounding box
            offsets (Tensor): offset of the bounding box center.
            stride: stride of coordinates
            wh_ratio: ratio of width and height, equal to width/height
            max_shape (tuple): Shape of the image.

        Returns:
            Tensor: Decoded bboxes.
        """
    x = points[:, 0] + (0.5 + offsets[:, 1])*stride
    y = points[:, 1] + (0.5  + offsets[:, 0])*stride
    heights = heights[..., 0] * stride
    # print(stride)
    # print(torch.stack([y, x], -1))
    # print(points)
    if is_left:
        x1 = x - wh_ratio * heights / 2
    else:
        x1 = x - wh_ratio * heights / 2 * 3

    if is_upper:
        y1 = y - heights/2
        x2 = x1 + wh_ratio * heights/upper_factor
        y2 = y1 + heights/upper_factor
    else:
        x2 = x1 + wh_ratio * heights/(1-upper_factor)
        y2 = y + heights/2
        y1 = y2 - heights/(1-upper_factor)

    if max_shape is not None:
        x1 = x1.clamp(min=0, max=max_shape[1] - 1)
        y1 = y1.clamp(min=0, max=max_shape[0] - 1)
        x2 = x2.clamp(min=0, max=max_shape[1] - 1)
        y2 = y2.clamp(min=0, max=max_shape[0] - 1)
    return torch.stack([x1, y1, x2, y2], -1)
def csp_height2bbox_four_part ( points , heights , offsets , stride = 1 , wh_ratio = 0.41 , max_shape = None , upper_factor = 0.4 , is_upper = True , is_left = True ) : x = points [ : , 0 ] + ( 0.5 + offsets [ : , 1 ] ) * stride y = points [ : , 1 ] + ( 0.5 + offsets [ : , 0 ] ) * stride heights = heights [ ... , 0 ] * stride # print(stride) # print(torch.stack([y, x], -1)) # print(points) if is_left : x1 = x - wh_ratio * heights / 2 else : x1 = x - wh_ratio * heights / 2 * 3 if is_upper : y1 = y - heights / 2 x2 = x1 + wh_ratio * heights / upper_factor y2 = y1 + heights / upper_factor else : x2 = x1 + wh_ratio * heights / ( 1 - upper_factor ) y2 = y + heights / 2 y1 = y2 - heights / ( 1 - upper_factor ) if max_shape is not None : x1 = x1 . clamp ( min = 0 , max = max_shape [ 1 ] - 1 ) y1 = y1 . clamp ( min = 0 , max = max_shape [ 0 ] - 1 ) x2 = x2 . clamp ( min = 0 , max = max_shape [ 1 ] - 1 ) y2 = y2 . clamp ( min = 0 , max = max_shape [ 0 ] - 1 ) return torch . stack ( [ x1 , y1 , x2 , y2 ] , - 1 )