Augmentations

Vision

Contains augmentations for computer vision tasks.

PixMix

class pytorch_ood.augment.img.PixMixDataset(dataset, mixing_set, beta=3, aug_severity=3, k=4, std=(1.0, 1.0, 1.0), mean=(1.0, 1.0, 1.0))[source]

Dataset wrapper to perform PixMix, from the paper PixMix: Dreamlike Pictures Comprehensively Improve Safety Measures.

See Paper:

ArXiv

Note

Some of the augmentations primitives used in the paper are not yet implemented.

Pixmix sketch
Parameters:
  • dataset – original dataset

  • mixing_set – dataset used for mixing

  • beta – mixing coefficient

  • aug_severity – severity used for augmentation primitives

  • k – number of mixing iterations

  • mean – used for normalization

  • std – used for normalization

InsertCOCO

class pytorch_ood.augment.img.InsertCOCO(coco_dir: str, p: float = 0.1, n: int = 1, exclude_classes: List[str] | str | None = None, annotation_per_image: int = 1, ood_mask_value: int = -1, upscale: float = 1.4150357439499515, year: int = 2017, min_img_size: int = 480, download: bool = False)[source]

Transformation that inserts cropped COCO objects into images, marking the corresponding pixels of a segmentation mask as OOD.

The inserted objects can be used as synthetic OOD objects for supervised training of OOD detectors.

This was proposed in the paper Entropy Maximization and Meta Classification for Out-Of-Distribution Detection in Semantic Segmentation.

insert_coco = InsertCOCO(
    coco_dir="data/coco",
    exclude_classes=["train", "bicycle"],
    p=0.1
)

img, mask = insert_coco(img, mask)
See Paper:

ArXiv

Parameters:
  • coco_dir – Directory to store the coco dataset

  • p – Probability of inserting an OOD object to the image

  • n – Number of inserted OOD objects per image

  • exclude_classes – List of classes that should not be used for the OOD generation. Can also be one of bddAnomaly or Streethazards.

  • annotation_per_image – Number of different annotation that are used for the ood object per coco image. (E.g. if there are 2 elephants on a COCO image, if this parameter is 1, only 1 elephant is inserted)

  • ood_mask_value – Value of the OOD segmentation mask pixels

  • upscale – Upscale factor for the OOD object

  • year – Year of the coco dataset

  • min_img_size – Minimum size of the used coco image

  • download – Set True to automatically download the COCO dataset

__call__(img: Image, target: Tensor) Tuple[Image, Tensor][source]

Check if OOD should be added and add it with the given probability

Parameters:
  • img – input image

  • target – segmentation mask for image

Returns:

Tuple with image and target tensor with inserted object(s)