class_docstr: Refer to 'https://github.com/mcordts/cityscapesScripts/blob/master/cityscapesscripts/evaluation/evalInstanceLevelSemanticLabeling.py'
  Calculate the matching results of each image, each class, each IoU, and then get the final
  matching results of each class and each IoU of dataset. Base on the matching results, the AP
  and mAP can be calculated.
  we need two vectors for each class and for each overlap
  The first vector (y_true) is binary and is 1, where the ground truth says true,
  and is 0 otherwise.
  The second vector (y_score) is float [0...1] and represents the confidence of
  the prediction.
  We represent the following cases as:
                                        | y_true |   y_score
    gt instance with matched prediction |    1   | confidence
    gt instance w/o  matched prediction |    1   |     0.0
           false positive prediction    |    0   | confidence
  The current implementation makes only sense for an overlap threshold >= 0.5,
  since only then, a single prediction can either be ignored or matched, but
  never both. Further, it can never match to two gt instances.
  For matching, we vary the overlap and do the following steps:
    1.) remove all predictions that satisfy the overlap criterion with an ignore region (either void or *group)
    2.) remove matches that do not satisfy the overlap
    3.) mark non-matched predictions as false positive
  In the processing, 0 represent the first class of 'thing'. So the label will less 1 than the dataset.
  
  Args:
      num_classes (int): The unique number of target classes. Exclude background class, labeled 0 usually.
      overlaps (float|list, optional): The threshold of IoU. Default: 0.5.
      thing_list (list|None, optional): Thing class, only calculate AP for the thing class. Default: None.
docstr: compute y_true and y_score in this image.
  preds (list): tuple list [(label, confidence, mask), ...].
  gts (list): tuple list [(label, mask), ...].
  ignore_mask (np.ndarray): Mask to ignore.
code: def update(self, preds, gts, ignore_mask=None):
      """
      compute y_true and y_score in this image.
      preds (list): tuple list [(label, confidence, mask), ...].
      gts (list): tuple list [(label, mask), ...].
      ignore_mask (np.ndarray): Mask to ignore.
      """
  
      pred_instances, gt_instances = self.get_instances(
          preds, gts, ignore_mask=ignore_mask
      )
  
      for i in range(self.num_classes):
          if i not in self.thing_list:
              continue
          for oi, oth in enumerate(self.overlaps):
              cur_true = np.ones((len(gt_instances[i])))
              cur_score = np.ones(len(gt_instances[i])) * (
                  -float("inf")
              )
              cur_match = np.zeros(len(gt_instances[i]), dtype=np.bool)
              for gti, gt_instance in enumerate(gt_instances[i]):
                  found_match = False
                  for pred_instance in gt_instance["matched_pred"]:
                      overlap = float(pred_instance["intersection"]) / (
                          gt_instance["pixel_count"]
                          + pred_instance["pixel_count"]
                          - pred_instance["intersection"]
                      )
                      if overlap > oth:
                          confidence = pred_instance["confidence"]
  
                          # if we already has a prediction for this groundtruth
                          # the prediction with the lower score is automatically a false positive
                          if cur_match[gti]:
                              max_score = max(
                                  cur_score[gti], confidence
                              )
                              min_score = min(
                                  cur_score[gti], confidence
                              )
                              cur_score = max_score
                              # append false positive
                              cur_true = np.append(cur_true, 0)
                              cur_score = np.append(
                                  cur_score, min_score
                              )
                              cur_match = np.append(cur_match, True)
                          # otherwise set score
                          else:
                              found_match = True
                              cur_match[gti] = True
                              cur_score[gti] = confidence
  
                  if not found_match:
                      self.hard_fns[i][oi] += 1
              # remove not-matched ground truth instances
              cur_true = cur_true[cur_match == True]
              cur_score = cur_score[cur_match == True]
  
              # collect not-matched predictions as false positive
              for pred_instance in pred_instances[i]:
                  found_gt = False
                  for gt_instance in pred_instance["matched_gt"]:
                      overlap = float(gt_instance["intersection"]) / (
                          gt_instance["pixel_count"]
                          + pred_instance["pixel_count"]
                          - gt_instance["intersection"]
                      )
                      if overlap > oth:
                          found_gt = True
                          break
                  if not found_gt:
                      proportion_ignore = 0
                      if ignore_mask is not None:
                          nb_ignore_pixels = pred_instance[
                              "void_intersection"
                          ]
                          proportion_ignore = (
                              float(nb_ignore_pixels)
                              / pred_instance["pixel_count"]
                          )
                      if proportion_ignore <= oth:
                          cur_true = np.append(cur_true, 0)
                          cur_score = np.append(
                              cur_score, pred_instance["confidence"]
                          )
              self.y_true[i][oi] = np.append(
                  self.y_true[i][oi], cur_true
              )
              self.y_score[i][oi] = np.append(
                  self.y_score[i][oi], cur_score
              )
  
file_path: PaddleSeg/contrib/PanopticDeepLab/utils/evaluation/instance.py
imports: from collections import defaultdict, OrderedDict
  import numpy
label_desc: Use image node_id 2 for calling the InstanceEvaluator obj's underlying member method code with example usage: obj.update(preds, gts, ignore_mask) without return types