import torch


def wh_iou(box1, box2):
    """
    Returns the IoU of wh1 to wh2. wh1 is 2, wh2 is nx2

    :param box1: anchor (default anchor) --> 2
    :param box2: targets (ground truth)  --> n x 2
    :return: IoU of box1 to box2
    """

    box2 = box2.t()

    # w, h = box1
    box1_w, box1_h = box1[0], box1[1]
    box2_w, box2_h = box2[0], box2[1]

    # Intersection area
    inter_area = torch.min(box1_w, box2_w) * torch.min(box1_h, box2_h)

    # Union Area
    union_area = (box1_w * box1_h + 1e-16) + box2_w * box2_h - inter_area

    return inter_area / union_area