import torch


def boxes_xyxy2xywh(boxes):
    """Convert boxes from xyxy format to xywh format."""
    x_min, y_min, x_max, y_max = torch.split(boxes, 1, dim=-1)
    ctr_x = 0.5 * (x_min + x_max)
    ctr_y = 0.5 * (y_min + y_max)
    w = x_max - x_min
    h = y_max - y_min
    return torch.cat([ctr_x, ctr_y, w, h], dim=-1)