def stopping_criteria_met(eval_metrics, mask_min_ap, box_min_ap):
  """Returns true if both of the min precision criteria are met in the given
  evaluation metrics.

  Args:
    eval_metrics: dict of metrics names as keys and their corresponding values,
      containing "DetectionMasks_Precision/mAP", and
      "DetectionBoxes_Precision/mAP" fields.
    mask_min_ap: minimum desired mask average precision, will be ignored if -1
    box_min_ap: minimum desired box average precision, will be ignored if -1

  Returns:
    True if non -1 criteria are met, false o.w.
  """
  assert mask_min_ap == -1 or 0 < mask_min_ap < 1
  assert box_min_ap == -1 or 0 < box_min_ap < 1
  try:
    mask_mAP_reached = eval_metrics['DetectionMasks_Precision/mAP']
    box_mAP_reached = eval_metrics['DetectionBoxes_Precision/mAP']
  except KeyError as err:
    raise Exception('eval_metrics dict does not contain the mAP field') from err

  return (mask_min_ap == -1 or mask_mAP_reached > mask_min_ap) & \
         (box_min_ap == -1 or box_mAP_reached > box_min_ap) & \
         (mask_min_ap != -1 or box_min_ap != -1)