(points, heights, offsets, vis_full, stride=1, wh_ratio = 0.41, max_shape=None)
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_vis_height2bbox(points, heights, offsets, vis_full, stride=1, wh_ratio = 0.41, max_shape=None):
    """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] + vis_full[:, 0])*stride
    y = points[:, 1] + (0.5  + offsets[:, 0])*stride
    # print(stride)
    # print(torch.stack([y, x], -1))
    # print(points)
    heights = heights[..., 0] * stride
    y1 = y - heights * 0.5 - vis_full[:, 1] * stride
    y2 = y + heights * 0.5 + vis_full[:, 2] * stride
    heights = y2 - y1
    x1 = x - wh_ratio * heights/2
    x2 = x + wh_ratio * heights/2


    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_vis_height2bbox ( points , heights , offsets , vis_full , stride = 1 , wh_ratio = 0.41 , max_shape = None ) : x = points [ : , 0 ] + ( 0.5 + offsets [ : , 1 ] + vis_full [ : , 0 ] ) * stride y = points [ : , 1 ] + ( 0.5 + offsets [ : , 0 ] ) * stride # print(stride) # print(torch.stack([y, x], -1)) # print(points) heights = heights [ ... , 0 ] * stride y1 = y - heights * 0.5 - vis_full [ : , 1 ] * stride y2 = y + heights * 0.5 + vis_full [ : , 2 ] * stride heights = y2 - y1 x1 = x - wh_ratio * heights / 2 x2 = x + wh_ratio * heights / 2 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 )