import torch


def boxes_to_cornels(box_xy, box_wh):
    """Convert boxes from x_center,y_center, width, height to x_min, y_min, x_max, ymax

    Parameters
    ----------
    box_xy : torch.Tensor
        Predicted xy value
        shape [batch_size, num_anchors, 2, conv_height, conv_width]
    box_wh : torch.Tensor
        Predicted wh value shape [batch_size, num_anchors, 2, conv_height, conv_width]

    Returns
    -------
    torch.Tensor
        Boxes in x_min, y_min, x_max, y_max for mat
        shape [batch_size, num_anchors, 4, conv_height, conv_width]

    """

    box_mins = box_xy - box_wh / 2.
    box_maxes = box_xy + box_wh / 2.

    return torch.cat(
        (
            box_mins,
            box_maxes
        ),
        dim=2
    )