code: def seg_to_masks(
      frames: List[Frame],
      out_base: str,
      config: Config,
      nproc: int = NPROC,
      mode: str = "sem_seg",
      back_color: int = IGNORE_LABEL,
      closed: bool = True,
  ) -> None:
      """Converting segmentation poly2d to 1-channel masks."""
      os.makedirs(out_base, exist_ok=True)
      img_shape = config.imageSize
  
      out_paths: List[str] = []
      shapes: List[ImageSize] = []
      colors_list: List[List[NDArrayU8]] = []
      poly2ds_list: List[List[List[Poly2D]]] = []
  
      categories = dict(
          sem_seg=labels, drivable=drivables, lane_mark=lane_categories
      )[mode]
      cat_name2id = {
          cat.name: cat.trainId
          for cat in categories
          if cat.trainId != IGNORE_LABEL
      }
  
      logger.info("Preparing annotations for Semseg to Bitmasks")
  
      for image_anns in tqdm(frames):
          # Mask in .png format
          image_name = image_anns.name.replace(".jpg", ".png")
          image_name = os.path.split(image_name)[-1]
          out_path = os.path.join(out_base, image_name)
          out_paths.append(out_path)
  
          if img_shape is None:
              if image_anns.size is not None:
                  img_shape = image_anns.size
              else:
                  raise ValueError("Image shape not defined!")
          shapes.append(img_shape)
  
          colors: List[NDArrayU8] = []
          poly2ds: List[List[Poly2D]] = []
          colors_list.append(colors)
          poly2ds_list.append(poly2ds)
  
          if image_anns.labels is None:
              continue
  
          for label in image_anns.labels:
              if label.category not in cat_name2id:
                  continue
              if label.poly2d is None:
                  continue
  
              category_id = cat_name2id[label.category]
              if mode in ["sem_seg", "drivable"]:
                  color: NDArrayU8 = np.array(
                      [category_id], dtype=np.uint8
                  )
              else:
                  color = set_lane_color(label, category_id)
  
              colors.append(color)
              poly2ds.append(label.poly2d)
  
      logger.info("Start Conversion for Seg to Masks")
      frames_to_masks(
          nproc,
          out_paths,
          shapes,
          colors_list,
          poly2ds_list,
          with_instances=False,
          back_color=back_color,
          closed=closed,
      )
  
imports: import os
  from functools import partial
  from multiprocessing import Pool
  from typing import Callable, Dict, List
  import matplotlib
  import matplotlib.pyplot
  import numpy
  from PIL import Image
  from scalabel.common.parallel import NPROC
  from scalabel.common.typing import NDArrayU8
  from scalabel.label.io import group_and_sort, load
  from scalabel.label.transforms import poly_to_patch
  from scalabel.label.typing import Config, Frame, ImageSize, Label, Poly2D
  from scalabel.label.utils import check_crowd, check_ignored, get_leaf_categories
  from tqdm import tqdm
  from bdd100k.common.logger import logger
  from bdd100k.common.typing import BDD100KConfig
  from bdd100k.common.utils import get_bdd100k_instance_id, load_bdd100k_config
  from bdd100k.label.label import drivables, labels, lane_categories
  from bdd100k.label.to_coco import parse_args
  from bdd100k.label.to_scalabel import bdd100k_to_scalabel
label_desc: Use image node_id 5 for calling a global function with example usage: seg_to_masks(frames, out_base, config, nproc, mode, back_color, closed) without return types