import torch


def xyxy_to_xywh(boxes: torch.Tensor):
    """Converts a set of boxes in [top_left_x, top_left_y, bottom_right_x, bottom_right_y] format to
    [top_left_x, top_left_y, width, height] format"""
    assert boxes.shape[-1] == 4
    converted = boxes.clone()
    converted[..., 2:] -= converted[..., :2]
    return converted