class_docstr: Custom dataset for semantic segmentation. An example of file structure
  is as followed.
  
  .. code-block:: none
  
      ├── data
      │   ├── my_dataset
      │   │   ├── img_dir
      │   │   │   ├── train
      │   │   │   │   ├── xxx{img_suffix}
      │   │   │   │   ├── yyy{img_suffix}
      │   │   │   │   ├── zzz{img_suffix}
      │   │   │   ├── val
      │   │   ├── ann_dir
      │   │   │   ├── train
      │   │   │   │   ├── xxx{seg_map_suffix}
      │   │   │   │   ├── yyy{seg_map_suffix}
      │   │   │   │   ├── zzz{seg_map_suffix}
      │   │   │   ├── val
  
  The img/gt_semantic_seg pair of BaseSegDataset should be of the same
  except suffix. A valid img/gt_semantic_seg filename pair should be like
  ``xxx{img_suffix}`` and ``xxx{seg_map_suffix}`` (extension is also included
  in the suffix). If split is given, then ``xxx`` is specified in txt file.
  Otherwise, all files in ``img_dir/``and ``ann_dir`` will be loaded.
  Please refer to ``docs/en/tutorials/new_dataset.md`` for more details.
  
  
  Args:
      ann_file (str): Annotation file path. Defaults to ''.
      metainfo (dict, optional): Meta information for dataset, such as
          specify classes to load. Defaults to None.
      data_root (str, optional): The root directory for ``data_prefix`` and
          ``ann_file``. Defaults to None.
      data_prefix (dict, optional): Prefix for training data. Defaults to
          dict(img_path=None, seg_map_path=None).
      img_suffix (str): Suffix of images. Default: '.jpg'
      seg_map_suffix (str): Suffix of segmentation maps. Default: '.png'
      filter_cfg (dict, optional): Config for filter data. Defaults to None.
      indices (int or Sequence[int], optional): Support using first few
          data in annotation file to facilitate training/testing on a smaller
          dataset. Defaults to None which means using all ``data_infos``.
      serialize_data (bool, optional): Whether to hold memory using
          serialized objects, when enabled, data loader workers can use
          shared RAM from master process instead of making a copy. Defaults
          to True.
      pipeline (list, optional): Processing pipeline. Defaults to [].
      test_mode (bool, optional): ``test_mode=True`` means in test phase.
          Defaults to False.
      lazy_init (bool, optional): Whether to load annotation during
          instantiation. In some cases, such as visualization, only the meta
          information of the dataset is needed, which is not necessary to
          load annotation file. ``Basedataset`` can skip load annotations to
          save time by set ``lazy_init=True``. Defaults to False.
      use_label_map (bool, optional): Whether to use label map.
          Defaults to False.
      max_refetch (int, optional): If ``Basedataset.prepare_data`` get a
          None img. The maximum extra number of cycles to get a valid
          image. Defaults to 1000.
      backend_args (dict, Optional): Arguments to instantiate a file backend.
          See https://mmengine.readthedocs.io/en/latest/api/fileio.htm
          for details. Defaults to None.
          Notes: mmcv>=2.0.0rc4 required.
docstr: Update palette after loading metainfo.
  
  If length of palette is equal to classes, just return the palette.
  If palette is not defined, it will randomly generate a palette.
  If classes is updated by customer, it will return the subset of
  palette.
  
  Returns:
      Sequence: Palette for current dataset.
docstr_tok: ["Update","palette","after","loading","metainfo",".","If","length","of","palette","is","equal","to","classes",",","just","return","the","palette",".","If","palette","is","not","defined",",","it","will","randomly","generate","a","palette",".","If","classes","is","updated","by","customer",",","it","will","return","the","subset","of","palette",".","Returns",":","Sequence",":","Palette","for","current","dataset","."]
code: def _update_palette(self) -> list:
      """Update palette after loading metainfo.
  
      If length of palette is equal to classes, just return the palette.
      If palette is not defined, it will randomly generate a palette.
      If classes is updated by customer, it will return the subset of
      palette.
  
      Returns:
          Sequence: Palette for current dataset.
      """
      palette = self._metainfo.get("palette", [])
      classes = self._metainfo.get("classes", [])
      # palette does match classes
      if len(palette) == len(classes):
          return palette
  
      if len(palette) == 0:
          # Get random state before set seed, and restore
          # random state later.
          # It will prevent loss of randomness, as the palette
          # may be different in each iteration if not specified.
          # See: https://github.com/open-mmlab/mmdetection/issues/5844
          state = np.random.get_state()
          np.random.seed(42)
          # random palette
          new_palette = np.random.randint(
              0, 255, size=(len(classes), 3)
          ).tolist()
          np.random.set_state(state)
      elif len(palette) >= len(classes) and self.label_map is not None:
          new_palette = []
          # return subset of palette
          for old_id, new_id in sorted(
              self.label_map.items(), key=lambda x: x[1]
          ):
              # 0 is background
              if new_id != 0:
                  new_palette.append(palette[old_id])
          new_palette = type(palette)(new_palette)
      elif len(palette) >= len(classes):
          # Allow palette length is greater than classes.
          return palette
      else:
          raise ValueError(
              "palette does not match classes "
              f"as metainfo is {self._metainfo}."
          )
      return new_palette
  
file_path: mmdetection/mmdet/datasets/base_semseg_dataset.py
imports: import copy
  import os.path
  from typing import Callable, Dict, List, Optional, Sequence, Union
  import mmengine
  import mmengine.fileio
  import numpy
  from mmengine.dataset import BaseDataset, Compose
  from mmdet.registry import DATASETS
label_desc: Use image node_id 3 for calling the BaseSegDataset obj's underlying member method code with example usage: obj._update_palette() and returns: new_palette, palette, palette