original_docstring: Compute the IoU between two sets of boolean masks
  
      Args:
          gt_masks: boolean masks of shape (N, H, W)
          pred_masks: boolean masks of shape (N, H, W)
  
      Returns:
          the IoU vector of shape [N]
          the precision vector of shape [N]
          the recall vector of shape [N]
      
docstring: Compute the IoU between two sets of boolean masks
docstring_tokens: Compute the IoU between two sets of boolean masks
code: def mask_iou(
      gt_masks: np.ndarray, pred_masks: np.ndarray
  ) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
      """Compute the IoU between two sets of boolean masks
  
      Args:
          gt_masks: boolean masks of shape (N, H, W)
          pred_masks: boolean masks of shape (N, H, W)
  
      Returns:
          the IoU vector of shape [N]
          the precision vector of shape [N]
          the recall vector of shape [N]
      """
  
      if gt_masks.shape != pred_masks.shape:
          raise AssertionError("both boolean masks should have the same spatial shape")
  
      iou_vec = np.zeros((gt_masks.shape[0],), dtype=np.float32)
      precision = np.zeros((gt_masks.shape[0],), dtype=np.float32)
      recall = np.zeros((gt_masks.shape[0],), dtype=np.float32)
  
      if gt_masks.shape[0] > 0 and pred_masks.shape[0] > 0:
          intersection = np.logical_and(gt_masks, pred_masks).sum(axis=(1, 2))
          union = np.logical_or(gt_masks, pred_masks).sum(axis=(1, 2))
          prec_deno = pred_masks.sum(axis=(1, 2))
          gt_deno = gt_masks.sum(axis=(1, 2))
  
          iou_vec = intersection / (union + 1e-6)
          precision = intersection / (prec_deno + 1e-6)
          recall = intersection / (gt_deno + 1e-6)
  
      return iou_vec, precision, recall
code_tokens: def mask_iou ( gt_masks : np . ndarray , pred_masks : np . ndarray ) -> Tuple [ np . ndarray , np . ndarray , np . ndarray ] : if gt_masks . shape != pred_masks . shape : raise AssertionError ( "both boolean masks should have the same spatial shape" ) iou_vec = np . zeros ( ( gt_masks . shape [ 0 ] , ) , dtype = np . float32 ) precision = np . zeros ( ( gt_masks . shape [ 0 ] , ) , dtype = np . float32 ) recall = np . zeros ( ( gt_masks . shape [ 0 ] , ) , dtype = np . float32 ) if gt_masks . shape [ 0 ] > 0 and pred_masks . shape [ 0 ] > 0 : intersection = np . logical_and ( gt_masks , pred_masks ) . sum ( axis = ( 1 , 2 ) ) union = np . logical_or ( gt_masks , pred_masks ) . sum ( axis = ( 1 , 2 ) ) prec_deno = pred_masks . sum ( axis = ( 1 , 2 ) ) gt_deno = gt_masks . sum ( axis = ( 1 , 2 ) ) iou_vec = intersection / ( union + 1e-6 ) precision = intersection / ( prec_deno + 1e-6 ) recall = intersection / ( gt_deno + 1e-6 ) return iou_vec , precision , recall
short_docstring: Compute the IoU between two sets of boolean masks
short_docstring_tokens: Compute the IoU between two sets of boolean masks
comment: """Compute the IoU between two sets of boolean masks
  
      Args:
          gt_masks: boolean masks of shape (N, H, W)
          pred_masks: boolean masks of shape (N, H, W)
  
      Returns:
          the IoU vector of shape [N]
          the precision vector of shape [N]
          the recall vector of shape [N]
      """