import torch


def corner_bbox_to_center_bbox(corner_bboxes: torch.Tensor) -> torch.Tensor:
    """Convert x1, y1, x2, y2 form to x, y, w, h."""
    xy = (corner_bboxes[..., :2] + corner_bboxes[..., 2:]) / 2
    wh = corner_bboxes[..., 2:] - corner_bboxes[..., :2]
    return torch.cat([xy, wh], corner_bboxes.dim() - 1)