def intersection(masks1, masks2):
  """Compute pairwise intersection areas between masks.

  Args:
    masks1: a numpy array with shape [N, height, width] holding N masks. Masks
      values are of type np.uint8 and values are in {0,1}.
    masks2: a numpy array with shape [M, height, width] holding M masks. Masks
      values are of type np.uint8 and values are in {0,1}.

  Returns:
    a numpy array with shape [N*M] representing pairwise intersection area.

  Raises:
    ValueError: If masks1 and masks2 are not of type np.uint8.
  """
  if masks1.dtype != np.uint8 or masks2.dtype != np.uint8:
    raise ValueError('masks1 and masks2 should be of type np.uint8')
  n = masks1.shape[0]
  m = masks2.shape[0]
  answer = np.zeros([n, m], dtype=np.float32)
  for i in np.arange(n):
    for j in np.arange(m):
      answer[i, j] = np.sum(np.minimum(masks1[i], masks2[j]), dtype=np.float32)
  return answer
Compute pairwise intersection areas between masks.

  Args:
    masks1: a numpy array with shape [N, height, width] holding N masks. Masks
      values are of type np.uint8 and values are in {0,1}.
    masks2: a numpy array with shape [M, height, width] holding M masks. Masks
      values are of type np.uint8 and values are in {0,1}.

  Returns:
    a numpy array with shape [N*M] representing pairwise intersection area.

  Raises:
    ValueError: If masks1 and masks2 are not of type np.uint8.
  
inference_api/src/main/object_detection/utils/np_mask_ops.py