def compute_iou(box1, box2):
    """
    Compute IoU between two boxes.

    box1: [b1_y1, b1_x1, b1_y2, b1_x2]
    box2: [b2_y1, b2_x1, b2_y2, b2_x2]
    return: float
    """
    # Compute intersection
    b1_y1, b1_x1, b1_h, b1_w = box1
    b2_y1, b2_x1, b2_h, b2_w = box2
    b1_y2, b1_x2 = b1_y1+b1_h, b1_x1+b1_w
    b2_y2, b2_x2 = b2_y1+b2_h, b2_x1+b2_w

    y1 = max(b1_y1, b2_y1)
    x1 = max(b1_x1, b2_x1)
    y2 = min(b1_y2, b2_y2)
    x2 = min(b1_x2, b2_x2)
    intersection = max(x2 - x1, 0)*max(y2 - y1, 0)

    # Compute unions
    b1_area = (b1_y2 - b1_y1) * (b1_x2 - b1_x1)
    b2_area = (b2_y2 - b2_y1) * (b2_x2 - b2_x1)
    union = b1_area + b2_area - intersection

    iou = intersection / union
    return iou