def BBoxIOU(boxA, boxB):
  """BBoxIOU implements the IOU ratio.

  Args:
    boxA: the first bbox in shape (4,) of (x1, y1, x2, y2)
    boxB: the second bbox in shape (4,) of (x1, y1, x2, y2)

  Returns:
    iou: a float value represents the IOU ratio
  """
  iou = 0.0

  # determine the coordinates of the intersection rectangle
  xA = max(boxA[0], boxB[0])
  yA = max(boxA[1], boxB[1])
  xB = min(boxA[2], boxB[2])
  yB = min(boxA[3], boxB[3])

  # compute the area of the intersection area
  interArea = max(0, xB - xA + 1e-6) * max(0, yB - yA + 1e-6)

  # compute the area of both the prediction and ground-truth rectangle
  boxAArea = (boxA[2] - boxA[0] + 1e-6) * (boxA[3] - boxA[1] + 1e-6)
  boxBArea = (boxB[2] - boxB[0] + 1e-6) * (boxB[3] - boxB[1] + 1e-6)

  # calculate the iou based on the set theory
  iou = float(interArea) / float(boxAArea + boxBArea - interArea)

  return iou