composer.datasets.ade20k#

composer.datasets.ade20k

Functions

dataclass

Returns the same class as was passed in, with dunder methods added based on the fields defined in the class.

pil_image_collate

Constructs a BatchPair from datasets that yield samples of type PIL.Image.Image.

Classes

ADE20k

PyTorch Dataset for ADE20k.

DataSpec

Specifications for operating and training on data.

Dataset

An abstract class representing a Dataset.

NormalizationFn

Normalizes input data and removes the background class from target data if desired.

PadToSize

Pad an image to a specified size.

PhotometricDistoration

Applies a combination of brightness, contrast, saturation, and hue jitters with random intensity.

RandomCropPair

Crop the image and target at a randomly sampled position.

RandomHFlipPair

Flip the image and target horizontally with a specified probability.

RandomResizePair

Resize the image and target to base_size scaled by a randomly sampled value.

SyntheticBatchPairDataset

Emulates a dataset of provided size and shape.

Hparams

These classes are used with yahp for YAML-based configuration.

ADE20kDatasetHparams

Defines an instance of the ADE20k dataset for semantic segmentation.

DatasetHparams

Abstract base class for hyperparameters to initialize a dataset.

SyntheticHparamsMixin

Synthetic dataset parameter mixin for DatasetHparams.

Attributes

  • IMAGENET_CHANNEL_MEAN

  • IMAGENET_CHANNEL_STD

  • Optional

  • Tuple

  • Union

  • ceil

class composer.datasets.ade20k.ADE20k(datadir, split='train', both_transforms=None, image_transforms=None, target_transforms=None)[source]#

Bases: torch.utils.data.dataset.Dataset

PyTorch Dataset for ADE20k.

Parameters
  • datadir (str) โ€“ the path to the ADE20k folder.

  • split (str) โ€“ the dataset split to use, either โ€˜trainโ€™, โ€˜valโ€™, or โ€˜testโ€™. Default is โ€˜trainโ€™.

  • both_transforms (Module) โ€“ transformations to apply to the image and target simultaneously. Default is None.

  • image_transforms (Module) โ€“ transformations to apply to the image only. Default is None.

  • target_transforms (Module) โ€“ transformations to apply to the target only. Default is None.

class composer.datasets.ade20k.ADE20kDatasetHparams(use_synthetic=False, synthetic_num_unique_samples=100, synthetic_device='cpu', synthetic_memory_format=MemoryFormat.CONTIGUOUS_FORMAT, is_train=True, drop_last=True, shuffle=True, datadir=None, split='train', base_size=512, min_resize_scale=0.5, max_resize_scale=2.0, final_size=512, ignore_background=True)[source]#

Bases: composer.datasets.hparams.DatasetHparams, composer.datasets.hparams.SyntheticHparamsMixin

Defines an instance of the ADE20k dataset for semantic segmentation.

Parameters
  • use_synthetic (bool, optional) โ€“ Whether to use synthetic data. (Default: False)

  • synthetic_num_unique_samples (int, optional) โ€“ The number of unique samples to allocate memory for. Ignored if use_synthetic is False. (Default: 100)

  • synthetic_device (str, optonal) โ€“ The device to store the sample pool. Set to cuda to store samples on the GPU and eliminate PCI-e bandwidth with the dataloader. Set to cpu to move data between host memory and the device on every batch. Ignored if use_synthetic is False. (Default: cpu)

  • synthetic_memory_format โ€“ The MemoryFormat to use. Ignored if use_synthetic is False. (Default: CONTIGUOUS_FORMAT)

  • datadir (str) โ€“ The path to the data directory.

  • is_train (bool) โ€“ Whether to load the training data (the default) or validation data.

  • drop_last (bool) โ€“ If the number of samples is not divisible by the batch size, whether to drop the last batch (the default) or pad the last batch with zeros.

  • shuffle (bool) โ€“ Whether to shuffle the dataset. Defaults to True.

  • split (str) โ€“ the dataset split to use either โ€˜trainโ€™, โ€˜valโ€™, or โ€˜testโ€™. Default is train.

  • base_size (int) โ€“ initial size of the image and target before other augmentations. Default is 512.

  • min_resize_scale (float) โ€“ the minimum value the samples can be rescaled. Default is 0.5.

  • max_resize_scale (float) โ€“ the maximum value the samples can be rescaled. Default is 2.0.

  • final_size (int) โ€“ the final size of the image and target. Default is 512.

  • ignore_background (bool) โ€“ if true, ignore the background class when calculating the training loss. Default is true.

initialize_object(batch_size, dataloader_hparams)[source]#

Creates a DataLoader or DataloaderSpec for this dataset.

Parameters
  • batch_size (int) โ€“ The size of the batch the dataloader should yield. This batch size is device-specific and already incorporates the world size.

  • dataloader_hparams (DataloaderHparams) โ€“ The dataset-independent hparams for the dataloader

Returns
  • Dataloader or DataSpec โ€“ The dataloader, or if the dataloader yields batches of custom types,

  • a :class:`DataSpec`.

validate()[source]#

Validate that the hparams are of the correct types. Recurses through sub-hparams.

Raises

TypeError โ€“ Raises a TypeError if any fields are an incorrect type.

class composer.datasets.ade20k.PadToSize(size, fill=0)[source]#

Bases: torch.nn.modules.module.Module

Pad an image to a specified size.

Parameters
  • size (Tuple[int, int]) โ€“ the size (height x width) of the image after padding.

  • fill (Union[int, Tuple[int, int, int]]) โ€“ the value to use for the padded pixels. Default is 0.

class composer.datasets.ade20k.PhotometricDistoration(brightness, contrast, saturation, hue)[source]#

Bases: torch.nn.modules.module.Module

Applies a combination of brightness, contrast, saturation, and hue jitters with random intensity.

This is a less severe form of PyTorchโ€™s ColorJitter used by the mmsegmentation library here: https://github.com/open-mmlab/mmsegmentation/blob/master/mmseg/datasets/pipelines/transforms.py#L837

Parameters
  • brightness (float) โ€“ max and min to jitter brightness.

  • contrast (float) โ€“ max and min to jitter contrast.

  • saturation (float) โ€“ max and min to jitter saturation.

  • hue (float) โ€“ max and min to jitter hue.

class composer.datasets.ade20k.RandomCropPair(crop_size)[source]#

Bases: torch.nn.modules.module.Module

Crop the image and target at a randomly sampled position.

Parameters

crop_size (Tuple[int, int]) โ€“ the size (height x width) of the crop.

class composer.datasets.ade20k.RandomHFlipPair(probability=0.5)[source]#

Bases: torch.nn.modules.module.Module

Flip the image and target horizontally with a specified probability.

Parameters

probability (float) โ€“ the probability of flipping the image and target. Default is 0.5.

class composer.datasets.ade20k.RandomResizePair(min_scale, max_scale, base_size=None)[source]#

Bases: torch.nn.modules.module.Module

Resize the image and target to base_size scaled by a randomly sampled value.

Parameters
  • min_scale (float) โ€“ the minimum value the samples can be rescaled.

  • max_scale (float) โ€“ the maximum value the samples can be rescaled.

  • base_size (Tuple[int, int]) โ€“ a specified base size (height x width) to scale to get the resized dimensions. When this is None (default), use the input image size.