class_docstr: Unify different panoptic annotation/prediction formats
class_docstr_tok: ["Unify","different","panoptic","annotation\/prediction","formats"]
code: def __init__(self, panoptic_seg, segments_info, metadata=None):
      if segments_info is None:
          assert metadata is not None
          # If "segments_info" is None, we assume "panoptic_img" is a
          # H*W int32 image storing the panoptic_id in the format of
          # category_id * label_divisor + instance_id. We reserve -1 for
          # VOID label.
          label_divisor = metadata.label_divisor
          segments_info = []
          for panoptic_label in np.unique(panoptic_seg.numpy()):
              if panoptic_label == -1:
                  # VOID region.
                  continue
              pred_class = panoptic_label // label_divisor
              isthing = (
                  pred_class
                  in metadata.thing_dataset_id_to_contiguous_id.values()
              )
              segments_info.append(
                  {
                      "id": int(panoptic_label),
                      "category_id": int(pred_class),
                      "isthing": bool(isthing),
                  }
              )
      del metadata
  
      self._seg = panoptic_seg
  
      self._sinfo = {
          s["id"]: s for s in segments_info
      }  # seg id -> seg info
      segment_ids, areas = torch.unique(
          panoptic_seg, sorted=True, return_counts=True
      )
      areas = areas.numpy()
      sorted_idxs = np.argsort(-areas)
      self._seg_ids, self._seg_areas = (
          segment_ids[sorted_idxs],
          areas[sorted_idxs],
      )
      self._seg_ids = self._seg_ids.tolist()
      for sid, area in zip(self._seg_ids, self._seg_areas):
          if sid in self._sinfo:
              self._sinfo[sid]["area"] = float(area)
  
imports: import colorsys
  import logging
  import math
  import numpy
  from enum import Enum, unique
  import cv2
  import matplotlib
  import matplotlib.colors
  import matplotlib.figure
  import pycocotools.mask
  import torch
  from matplotlib.backends.backend_agg import FigureCanvasAgg
  from PIL import Image
  from detectron2.data import MetadataCatalog
  from detectron2.structures import BitMasks, Boxes, BoxMode, Keypoints, PolygonMasks, RotatedBoxes
  from detectron2.utils.file_io import PathManager
  from .colormap import random_color
label_desc: Use image node_id 1 to create a new _PanopticPrediction object  with example: obj = _PanopticPrediction(panoptic_seg, segments_info, metadata)