import torch


def xyxy2xywh(boxes):
    """ xyxy -> xywh
    (xmin,ymin,xmax,ymax) and (xcenter,ycenter,width,height)
    Args:
        boxes: torch.FloatTensor[N,4]
    """
    w = boxes[:, 2] - boxes[:, 0] + 1
    h = boxes[:, 3] - boxes[:, 1] + 1
    # center
    x = boxes[:, 0] + 0.5 * w
    y = boxes[:, 1] + 0.5 * h

    return torch.stack([x, y, w, h]).transpose(0, 1)