Shortcuts

Cityscapes

class torchvision.datasets.Cityscapes(root: Union[str, Path], 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)[source]

Cityscapes Dataset.

Parameters:
  • root (str or pathlib.Path) – 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

dataset = Cityscapes('./data/cityscapes', split='train', mode='fine',
                     target_type='semantic')

img, smnt = dataset[0]

Get multiple targets

dataset = Cityscapes('./data/cityscapes', split='train', mode='fine',
                     target_type=['instance', 'color', 'polygon'])

img, (inst, col, poly) = dataset[0]

Validate on the “coarse” set

dataset = Cityscapes('./data/cityscapes', split='val', mode='coarse',
                     target_type='semantic')

img, smnt = dataset[0]
Special-members:

__getitem__(index: int) Tuple[Any, Any][source]
Parameters:

index (int) – Index

Returns:

(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.

Return type:

tuple

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources