class_docstr: Class for KITTI Semantic Segmentation Benchmark dataset
  Dataset link - http://www.cvlibs.net/datasets/kitti/eval_semseg.php?benchmark=semantics2015
  Manually download at https://s3.eu-central-1.amazonaws.com/avg-kitti/data_semantics.zip
  There are 34 classes in the given labels. However, not all of them are useful for training
  (like railings on highways, road dividers, etc.).
  So, these useless classes (the pixel values of these classes) are stored in the `void_labels`.
  The useful classes are stored in the `valid_labels`.
  The `encode_segmap` function sets all pixels with any of the `void_labels` to `ignore_index`
  (250 by default). It also sets all of the valid pixels to the appropriate value between 0 and
  `len(valid_labels)` (since that is the number of valid classes), so it can be used properly by
  the loss function when comparing with the output.
  The `get_filenames` function retrieves the filenames of all images in the given `path` and
  saves the absolute path in a list.
  In the `get_item` function, images and masks are resized to the given `img_size`, masks are
  encoded using `encode_segmap`, and given `transform` (if any) are applied to the image only
  (mask does not usually require transforms, but they can be implemented in a similar way).
  >>> from pl_examples import _DATASETS_PATH
  >>> dataset_path = os.path.join(_DATASETS_PATH, "Kitti")
  >>> _create_synth_kitti_dataset(dataset_path, image_dims=(1024, 512))
  >>> KITTI(dataset_path, 'train')  # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
  <...semantic_segmentation.KITTI object at ...>
class_docstr_tok: ["Class","for","KITTI","Semantic","Segmentation","Benchmark","dataset","Dataset","link","-","http",":","\/\/www.cvlibs.net\/datasets\/kitti\/eval_semseg.php","?","benchmark=semantics2015","Manually","download","at","https",":","\/\/s3.eu-central-1.amazonaws.com\/avg-kitti\/data_semantics.zip","There","are","34","classes","in","the","given","labels",".","However",",","not","all","of","them","are","useful","for","training","(","like","railings","on","highways",",","road","dividers",",","etc.",")",".","So",",","these","useless","classes","(","the","pixel","values","of","these","classes",")","are","stored","in","the","`","void_labels","`",".","The","useful","classes","are","stored","in","the","`","valid_labels","`",".","The","`","encode_segmap","`","function","sets","all","pixels","with","any","of","the","`","void_labels","`","to","`","ignore_index","`","(","250","by","default",")",".","It","also","sets","all","of","the","valid","pixels","to","the","appropriate","value","between","0","and","`","len","(","valid_labels",")","`","(","since","that","is","the","number","of","valid","classes",")",",","so","it","can","be","used","properly","by","the","loss","function","when","comparing","with","the","output",".","The","`","get_filenames","`","function","retrieves","the","filenames","of","all","images","in","the","given","`","path","`","and","saves","the","absolute","path","in","a","list",".","In","the","`","get_item","`","function",",","images","and","masks","are","resized","to","the","given","`","img_size","`",",","masks","are","encoded","using","`","encode_segmap","`",",","and","given","`","transform","`","(","if","any",")","are","applied","to","the","image","only","(","mask","does","not","usually","require","transforms",",","but","they","can","be","implemented","in","a","similar","way",")",".",">",">",">","from","pl_examples","import","_DATASETS_PATH",">",">",">","dataset_path","=","os.path.join","(","_DATASETS_PATH",",","``","Kitti","''",")",">",">",">","_create_synth_kitti_dataset","(","dataset_path",",","image_dims=","(","1024",",","512",")",")",">",">",">","KITTI","(","dataset_path",",","'train","'",")","#","doctest",":","+ELLIPSIS","+NORMALIZE_WHITESPACE","<","...","semantic_segmentation.KITTI","object","at","...",">"]
code: def __init__(
      self,
      data_path: str,
      split: str,
      img_size: tuple = (1242, 376),
      void_labels: tuple = DEFAULT_VOID_LABELS,
      valid_labels: tuple = DEFAULT_VALID_LABELS,
      transform=None,
  ):
      self.img_size = img_size
      self.void_labels = void_labels
      self.valid_labels = valid_labels
      self.ignore_index = 250
      self.class_map = dict(
          zip(self.valid_labels, range(len(self.valid_labels)))
      )
      self.transform = transform
  
      self.split = split
      self.data_path = data_path
      self.img_path = os.path.join(self.data_path, self.IMAGE_PATH)
      self.mask_path = os.path.join(self.data_path, self.MASK_PATH)
      self.img_list = self.get_filenames(self.img_path)
      self.mask_list = self.get_filenames(self.mask_path)
  
      # Split between train and valid set (80/20)
      random_inst = random.Random(12345)  # for repeatability
      n_items = len(self.img_list)
      idxs = random_inst.sample(range(n_items), n_items // 5)
      if self.split == "train":
          idxs = [idx for idx in range(n_items) if idx not in idxs]
      self.img_list = [self.img_list[i] for i in idxs]
      self.mask_list = [self.mask_list[i] for i in idxs]
  
imports: import os
  import random
  from argparse import ArgumentParser, Namespace
  import numpy
  import torch
  import torch.nn.functional
  from bigdl.nano.pytorch.vision.transforms import transforms
  from PIL import Image
  from torch.utils.data import DataLoader, Dataset
  from typing import Union
  import pytorch_lightning
  from pl_examples import cli_lightning_logo
  from pl_examples.domain_templates.unet import UNet
  from pytorch_lightning.utilities.argparse import from_argparse_args
  from bigdl.nano.pytorch import Trainer
label_desc: Use image node_id 1 to create a new KITTI object from inherited base classes: Dataset with example: obj = KITTI(data_path, split, img_size, void_labels, valid_labels, transform)