class_docstr: `Cityscapes <http://www.cityscapes-dataset.com/>`_ Dataset.
  
  Args:
      root (string): Root directory of dataset where directory ``leftImg8bit``
          and ``gtFine`` or ``gtCoarse`` are located.
      split (string, optional): The image split to use, ``train``, ``test`` or ``val`` if mode="fine"
          otherwise ``train``, ``train_extra`` or ``val``
      mode (string, optional): The quality mode to use, ``fine`` or ``coarse``
      target_type (string or list, optional): Type of target to use, ``instance``, ``semantic``, ``polygon``
          or ``color``. Can also be a list to output a tuple with all specified target types.
      transform (callable, optional): A function/transform that takes in a PIL image
          and returns a transformed version. E.g, ``transforms.RandomCrop``
      target_transform (callable, optional): A function/transform that takes in the
          target and transforms it.
      transforms (callable, optional): A function/transform that takes input sample and its target as entry
          and returns a transformed version.
  
  Examples:
  
      Get semantic segmentation target
  
      .. code-block:: python
  
          dataset = Cityscapes('./data/cityscapes', split='train', mode='fine',
                               target_type='semantic')
  
          img, smnt = dataset[0]
  
      Get multiple targets
  
      .. code-block:: python
  
          dataset = Cityscapes('./data/cityscapes', split='train', mode='fine',
                               target_type=['instance', 'color', 'polygon'])
  
          img, (inst, col, poly) = dataset[0]
  
      Validate on the "coarse" set
  
      .. code-block:: python
  
          dataset = Cityscapes('./data/cityscapes', split='val', mode='coarse',
                               target_type='semantic')
  
          img, smnt = dataset[0]
class_docstr_tok: ["`","Cityscapes","<","http",":","\/\/www.cityscapes-dataset.com\/",">","`","_","Dataset",".","Args",":","root","(","string",")",":","Root","directory","of","dataset","where","directory","``","leftImg8bit","``","and","``","gtFine","``","or","``","gtCoarse","``","are","located",".","split","(","string",",","optional",")",":","The","image","split","to","use",",","``","train","``",",","``","test","``","or","``","val","``","if","mode=","''","fine","''","otherwise","``","train","``",",","``","train_extra","``","or","``","val","``","mode","(","string",",","optional",")",":","The","quality","mode","to","use",",","``","fine","``","or","``","coarse","``","target_type","(","string","or","list",",","optional",")",":","Type","of","target","to","use",",","``","instance","``",",","``","semantic","``",",","``","polygon","``","or","``","color","``",".","Can","also","be","a","list","to","output","a","tuple","with","all","specified","target","types",".","transform","(","callable",",","optional",")",":","A","function\/transform","that","takes","in","a","PIL","image","and","returns","a","transformed","version",".","E.g",",","``","transforms.RandomCrop","``","target_transform","(","callable",",","optional",")",":","A","function\/transform","that","takes","in","the","target","and","transforms","it",".","transforms","(","callable",",","optional",")",":","A","function\/transform","that","takes","input","sample","and","its","target","as","entry","and","returns","a","transformed","version",".","Examples",":","Get","semantic","segmentation","target","..","code-block",":",":","python","dataset","=","Cityscapes","(","'.\/data\/cityscapes","'",",","split='train","'",",","mode='fine","'",",","target_type='semantic","'",")","img",",","smnt","=","dataset","[","0","]","Get","multiple","targets","..","code-block",":",":","python","dataset","=","Cityscapes","(","'.\/data\/cityscapes","'",",","split='train","'",",","mode='fine","'",",","target_type=","[","'instance","'",",","'color","'",",","'polygon","'","]",")","img",",","(","inst",",","col",",","poly",")","=","dataset","[","0","]","Validate","on","the","``","coarse","''","set","..","code-block",":",":","python","dataset","=","Cityscapes","(","'.\/data\/cityscapes","'",",","split='val","'",",","mode='coarse","'",",","target_type='semantic","'",")","img",",","smnt","=","dataset","[","0","]"]
code: def __init__(
      self,
      root: str,
      split: str = "train",
      mode: str = "fine",
      target_type: Union[List[str], str] = "instance",
      transform: Optional[Callable] = None,
      target_transform: Optional[Callable] = None,
      transforms: Optional[Callable] = None,
  ) -> None:
      super().__init__(root, transforms, transform, target_transform)
      self.mode = "gtFine" if mode == "fine" else "gtCoarse"
      self.images_dir = os.path.join(self.root, "leftImg8bit", split)
      self.targets_dir = os.path.join(self.root, self.mode, split)
      self.target_type = target_type
      self.split = split
      self.images = []
      self.targets = []
  
      verify_str_arg(mode, "mode", ("fine", "coarse"))
      if mode == "fine":
          valid_modes = ("train", "test", "val")
      else:
          valid_modes = ("train", "train_extra", "val")
      msg = "Unknown value '{}' for argument split if mode is '{}'. Valid values are {{{}}}."
      msg = msg.format(split, mode, iterable_to_str(valid_modes))
      verify_str_arg(split, "split", valid_modes, msg)
  
      if not isinstance(target_type, list):
          self.target_type = [target_type]
      [
          verify_str_arg(
              value,
              "target_type",
              ("instance", "semantic", "polygon", "color"),
          )
          for value in self.target_type
      ]
  
      if not os.path.isdir(self.images_dir) or not os.path.isdir(
          self.targets_dir
      ):
          if split == "train_extra":
              image_dir_zip = os.path.join(
                  self.root, "leftImg8bit_trainextra.zip"
              )
          else:
              image_dir_zip = os.path.join(
                  self.root, "leftImg8bit_trainvaltest.zip"
              )
  
          if self.mode == "gtFine":
              target_dir_zip = os.path.join(
                  self.root, f"{self.mode}_trainvaltest.zip"
              )
          elif self.mode == "gtCoarse":
              target_dir_zip = os.path.join(
                  self.root, f"{self.mode}.zip"
              )
  
          if os.path.isfile(image_dir_zip) and os.path.isfile(
              target_dir_zip
          ):
              extract_archive(
                  from_path=image_dir_zip, to_path=self.root
              )
              extract_archive(
                  from_path=target_dir_zip, to_path=self.root
              )
          else:
              raise RuntimeError(
                  "Dataset not found or incomplete. Please make sure all required folders for the"
                  ' specified "split" and "mode" are inside the "root" directory'
              )
  
      for city in os.listdir(self.images_dir):
          img_dir = os.path.join(self.images_dir, city)
          target_dir = os.path.join(self.targets_dir, city)
          for file_name in os.listdir(img_dir):
              target_types = []
              for t in self.target_type:
                  target_name = "{}_{}".format(
                      file_name.split("_leftImg8bit")[0],
                      self._get_target_suffix(self.mode, t),
                  )
                  target_types.append(
                      os.path.join(target_dir, target_name)
                  )
  
              self.images.append(os.path.join(img_dir, file_name))
              self.targets.append(target_types)
  
file_path: vision/torchvision/datasets/cityscapes.py
imports: import json
  import os
  from collections import namedtuple
  from typing import Any, Callable, Dict, List, Optional, Tuple, Union
  from PIL import Image
  from .utils import extract_archive, iterable_to_str, verify_str_arg
  from .vision import VisionDataset
label_desc: Use image node_id 1 to create a new Cityscapes object from inherited base classes: VisionDataset with example: obj = Cityscapes(root, split, mode, target_type, transform, target_transform, transforms)