class_docstr: MMDetection Local Visualizer.
  
  Args:
      name (str): Name of the instance. Defaults to 'visualizer'.
      image (np.ndarray, optional): the origin image to draw. The format
          should be RGB. Defaults to None.
      vis_backends (list, optional): Visual backend config list.
          Defaults to None.
      save_dir (str, optional): Save file dir for all storage backends.
          If it is None, the backend storage will not save any data.
      bbox_color (str, tuple(int), optional): Color of bbox lines.
          The tuple of color should be in BGR order. Defaults to None.
      text_color (str, tuple(int), optional): Color of texts.
          The tuple of color should be in BGR order.
          Defaults to (200, 200, 200).
      mask_color (str, tuple(int), optional): Color of masks.
          The tuple of color should be in BGR order.
          Defaults to None.
      line_width (int, float): The linewidth of lines.
          Defaults to 3.
      alpha (int, float): The transparency of bboxes or mask.
          Defaults to 0.8.
  
  Examples:
      >>> import numpy as np
      >>> import torch
      >>> from mmengine.structures import InstanceData
      >>> from mmdet.structures import DetDataSample
      >>> from mmdet.visualization import DetLocalVisualizer
  
      >>> det_local_visualizer = DetLocalVisualizer()
      >>> image = np.random.randint(0, 256,
      ...                     size=(10, 12, 3)).astype('uint8')
      >>> gt_instances = InstanceData()
      >>> gt_instances.bboxes = torch.Tensor([[1, 2, 2, 5]])
      >>> gt_instances.labels = torch.randint(0, 2, (1,))
      >>> gt_det_data_sample = DetDataSample()
      >>> gt_det_data_sample.gt_instances = gt_instances
      >>> det_local_visualizer.add_datasample('image', image,
      ...                         gt_det_data_sample)
      >>> det_local_visualizer.add_datasample(
      ...                       'image', image, gt_det_data_sample,
      ...                        out_file='out_file.jpg')
      >>> det_local_visualizer.add_datasample(
      ...                        'image', image, gt_det_data_sample,
      ...                         show=True)
      >>> pred_instances = InstanceData()
      >>> pred_instances.bboxes = torch.Tensor([[2, 4, 4, 8]])
      >>> pred_instances.labels = torch.randint(0, 2, (1,))
      >>> pred_det_data_sample = DetDataSample()
      >>> pred_det_data_sample.pred_instances = pred_instances
      >>> det_local_visualizer.add_datasample('image', image,
      ...                         gt_det_data_sample,
      ...                         pred_det_data_sample)
class_docstr_tok: ["MMDetection","Local","Visualizer",".","Args",":","name","(","str",")",":","Name","of","the","instance",".","Defaults","to","'visualizer","'",".","image","(","np.ndarray",",","optional",")",":","the","origin","image","to","draw",".","The","format","should","be","RGB",".","Defaults","to","None",".","vis_backends","(","list",",","optional",")",":","Visual","backend","config","list",".","Defaults","to","None",".","save_dir","(","str",",","optional",")",":","Save","file","dir","for","all","storage","backends",".","If","it","is","None",",","the","backend","storage","will","not","save","any","data",".","bbox_color","(","str",",","tuple","(","int",")",",","optional",")",":","Color","of","bbox","lines",".","The","tuple","of","color","should","be","in","BGR","order",".","Defaults","to","None",".","text_color","(","str",",","tuple","(","int",")",",","optional",")",":","Color","of","texts",".","The","tuple","of","color","should","be","in","BGR","order",".","Defaults","to","(","200",",","200",",","200",")",".","mask_color","(","str",",","tuple","(","int",")",",","optional",")",":","Color","of","masks",".","The","tuple","of","color","should","be","in","BGR","order",".","Defaults","to","None",".","line_width","(","int",",","float",")",":","The","linewidth","of","lines",".","Defaults","to","3.","alpha","(","int",",","float",")",":","The","transparency","of","bboxes","or","mask",".","Defaults","to","0.8",".","Examples",":",">",">",">","import","numpy","as","np",">",">",">","import","torch",">",">",">","from","mmengine.structures","import","InstanceData",">",">",">","from","mmdet.structures","import","DetDataSample",">",">",">","from","mmdet.visualization","import","DetLocalVisualizer",">",">",">","det_local_visualizer","=","DetLocalVisualizer","(",")",">",">",">","image","=","np.random.randint","(","0",",","256",",","...","size=","(","10",",","12",",","3",")",")",".astype","(","'uint8","'",")",">",">",">","gt_instances","=","InstanceData","(",")",">",">",">","gt_instances.bboxes","=","torch.Tensor","(","[","[","1",",","2",",","2",",","5","]","]",")",">",">",">","gt_instances.labels","=","torch.randint","(","0",",","2",",","(","1",",",")",")",">",">",">","gt_det_data_sample","=","DetDataSample","(",")",">",">",">","gt_det_data_sample.gt_instances","=","gt_instances",">",">",">","det_local_visualizer.add_datasample","(","'image","'",",","image",",","...","gt_det_data_sample",")",">",">",">","det_local_visualizer.add_datasample","(","...","'image","'",",","image",",","gt_det_data_sample",",","...","out_file='out_file.jpg","'",")",">",">",">","det_local_visualizer.add_datasample","(","...","'image","'",",","image",",","gt_det_data_sample",",","...","show=True",")",">",">",">","pred_instances","=","InstanceData","(",")",">",">",">","pred_instances.bboxes","=","torch.Tensor","(","[","[","2",",","4",",","4",",","8","]","]",")",">",">",">","pred_instances.labels","=","torch.randint","(","0",",","2",",","(","1",",",")",")",">",">",">","pred_det_data_sample","=","DetDataSample","(",")",">",">",">","pred_det_data_sample.pred_instances","=","pred_instances",">",">",">","det_local_visualizer.add_datasample","(","'image","'",",","image",",","...","gt_det_data_sample",",","...","pred_det_data_sample",")"]
docstr: Draw semantic seg of GT or prediction.
  
  Args:
      image (np.ndarray): The image to draw.
      sem_seg (:obj:`PixelData`): Data structure for pixel-level
          annotations or predictions.
      classes (list, optional): Input classes for result rendering, as
          the prediction of segmentation model is a segment map with
          label indices, `classes` is a list which includes items
          responding to the label indices. If classes is not defined,
          visualizer will take `cityscapes` classes by default.
          Defaults to None.
      palette (list, optional): Input palette for result rendering, which
          is a list of color palette responding to the classes.
          Defaults to None.
  
  Returns:
      np.ndarray: the drawn image which channel is RGB.
docstr_tok: ["Draw","semantic","seg","of","GT","or","prediction",".","Args",":","image","(","np.ndarray",")",":","The","image","to","draw",".","sem_seg","(",":","obj",":","`","PixelData","`",")",":","Data","structure","for","pixel-level","annotations","or","predictions",".","classes","(","list",",","optional",")",":","Input","classes","for","result","rendering",",","as","the","prediction","of","segmentation","model","is","a","segment","map","with","label","indices",",","`","classes","`","is","a","list","which","includes","items","responding","to","the","label","indices",".","If","classes","is","not","defined",",","visualizer","will","take","`","cityscapes","`","classes","by","default",".","Defaults","to","None",".","palette","(","list",",","optional",")",":","Input","palette","for","result","rendering",",","which","is","a","list","of","color","palette","responding","to","the","classes",".","Defaults","to","None",".","Returns",":","np.ndarray",":","the","drawn","image","which","channel","is","RGB","."]
code: def _draw_sem_seg(
      self,
      image: np.ndarray,
      sem_seg: PixelData,
      classes: Optional[List],
      palette: Optional[List],
  ) -> np.ndarray:
      """Draw semantic seg of GT or prediction.
  
      Args:
          image (np.ndarray): The image to draw.
          sem_seg (:obj:`PixelData`): Data structure for pixel-level
              annotations or predictions.
          classes (list, optional): Input classes for result rendering, as
              the prediction of segmentation model is a segment map with
              label indices, `classes` is a list which includes items
              responding to the label indices. If classes is not defined,
              visualizer will take `cityscapes` classes by default.
              Defaults to None.
          palette (list, optional): Input palette for result rendering, which
              is a list of color palette responding to the classes.
              Defaults to None.
  
      Returns:
          np.ndarray: the drawn image which channel is RGB.
      """
      sem_seg_data = sem_seg.sem_seg
      if isinstance(sem_seg_data, torch.Tensor):
          sem_seg_data = sem_seg_data.numpy()
  
      # 0 ~ num_class, the value 0 means background
      ids = np.unique(sem_seg_data)
      ignore_index = sem_seg.metainfo.get("ignore_index", 255)
      ids = ids[ids != ignore_index]
  
      if "label_names" in sem_seg:
          # open set semseg
          label_names = sem_seg.metainfo["label_names"]
      else:
          label_names = classes
  
      labels = np.array(ids, dtype=np.int64)
      colors = [palette[label] for label in labels]
  
      self.set_image(image)
  
      # draw semantic masks
      for i, (label, color) in enumerate(zip(labels, colors)):
          masks = sem_seg_data == label
          self.draw_binary_masks(
              masks, colors=[color], alphas=self.alpha
          )
          label_text = label_names[label]
          _, _, stats, centroids = cv2.connectedComponentsWithStats(
              masks[0].astype(np.uint8), connectivity=8
          )
          if stats.shape[0] > 1:
              largest_id = np.argmax(stats[1:, -1]) + 1
              centroids = centroids[largest_id]
  
              areas = stats[largest_id, -1]
              scales = _get_adaptive_scales(areas)
  
              self.draw_texts(
                  label_text,
                  centroids,
                  colors=(255, 255, 255),
                  font_sizes=int(13 * scales),
                  horizontal_alignments="center",
                  bboxes=[
                      {
                          "facecolor": "black",
                          "alpha": 0.8,
                          "pad": 0.7,
                          "edgecolor": "none",
                      }
                  ],
              )
  
      return self.get_image()
  
imports: from typing import Dict, List, Optional, Tuple, Union
  import cv2
  import mmcv
  import numpy
  import torch
  from mmengine.dist import master_only
  from mmengine.structures import InstanceData, PixelData
  from mmengine.visualization import Visualizer
  from ..evaluation import INSTANCE_OFFSET
  from ..registry import VISUALIZERS
  from ..structures import DetDataSample
  from ..structures.mask import BitmapMasks, PolygonMasks, bitmap_to_polygon
  from .palette import _get_adaptive_scales, get_palette, jitter_color
label_desc: Use image node_id 4 for calling the DetLocalVisualizer obj's underlying member method code with example usage: obj._draw_sem_seg(image, sem_seg, classes, palette) and returns: self