import torch


def bounding_box_x0y0x1y1_to_xcycwh(bounding_boxes: torch.Tensor) -> torch.Tensor:
    """
    This function converts a given bounding bix of the format
    [batch size, instances, 4 (x0, y0, x1, y1)] to [batch size, instances, 4 (x center, y center, width, height)].
    :param bounding_boxes: Bounding box of shape [batch size, instances, 4 (x0, y0, x1, y1)]
    :return: Converted bounding box of shape [batch size, instances, 4 (x center, y center, width, height)]
    """
    x_0, y_0, x_1, y_1 = bounding_boxes.unbind(dim=-1)
    bounding_box_converted = [((x_0 + x_1) / 2),
                              ((y_0 + y_1) / 2),
                              (x_1 - x_0),
                              (y_1 - y_0)]
    return torch.stack(tensors=bounding_box_converted, dim=-1)