(points, hws, offsets, 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_heightwidth2bbox(points, hws, offsets, 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] + (offsets[:, 1])*stride
    y = points[:, 1] + (offsets[:, 0])*stride
    # print(stride)
    # print(torch.stack([y, x], -1))
    # print(points)
    heights = hws[..., 0] * stride
    widths = hws[..., 1] * stride
    x1 = x - widths * 0.5
    y1 = y - heights * 0.5
    x2 = x + widths * 0.5
    y2 = y + heights * 0.5

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