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]
docstr: Args:
      index (int): Index
  Returns:
      tuple: (image, target) where target is a tuple of all target types if target_type is a list with more
      than one item. Otherwise target is a json object if target_type="polygon", else the image segmentation.
docstr_tok: ["Args",":","index","(","int",")",":","Index","Returns",":","tuple",":","(","image",",","target",")","where","target","is","a","tuple","of","all","target","types","if","target_type","is","a","list","with","more","than","one","item",".","Otherwise","target","is","a","json","object","if","target_type=","''","polygon","''",",","else","the","image","segmentation","."]
code: def __getitem__(self, index: int) -> Tuple[Any, Any]:
      """
      Args:
          index (int): Index
      Returns:
          tuple: (image, target) where target is a tuple of all target types if target_type is a list with more
          than one item. Otherwise target is a json object if target_type="polygon", else the image segmentation.
      """
      image = Image.open(self.images[index]).convert("RGB")
  
      target = Image.open(self.targets[index])
      target = np.array(target)
  
      target_copy = target.copy()
      for k, v in Cityscapes.label2trainid.items():
          binary_target = target == k
          target_copy[binary_target] = v
      target = target_copy
  
      target = Image.fromarray(target.astype(np.uint8))
  
      if self.transforms is not None:
          image, target = self.transforms(image, target)
  
      return image, target
  
file_path: megatron-lm/tasks/vision/segmentation/cityscapes.py
imports: import torch
  import json
  import os
  from collections import namedtuple
  from typing import Any, Callable, Dict, List, Optional, Union, Tuple
  import numpy
  from torchvision.datasets.utils import extract_archive, verify_str_arg, iterable_to_str
  from torchvision.datasets import VisionDataset
  from PIL import Image
  from megatron import print_rank_0
label_desc: Use image node_id 2 for calling the Cityscapes obj's underlying member method code with example usage: obj.__getitem__(index) and returns: image,  target