data.functional

The corruption functions are modelled after D. Hendrycks and T. Dietterich: Benchmarking Neural Network Robustness to Common Corruptions and Perturbations (ICLR 2019) and the code provided by their authors in https://github.com/hendrycks/robustness/ but our implementation is expected to differ in details from theirs.

It is important to use 0..1-values image tensors as inputs. This means that you need to do the normalization after applying these. In the traditional default PyTorch/TorchVision pipeline, images are normalized in the dataset, which may be too early. In our examples, we like to move the normalization to the beginning of the model itself or in a separate augmentation model.

torchdrift.data.functional.gaussian_blur(x: torch.Tensor, severity: int = 1) → torch.Tensor

Applies gaussian blur

Args:

x: input image, tensor in 0..1 range

severity: integer severity from 1 to 5

The intensity adapts to the image size to interpolate between the parameters they set by Hendrycks and Dieterich for CIFAR and ImageNet.

torchdrift.data.functional.gaussian_noise(x: torch.Tensor, severity: int = 1) → torch.Tensor

Applys gaussian noise.

Args:

x: input image, tensor in 0..1 range

severity: integer severity from 1 to 5

The intensity adapts to the image size to interpolate between the parameters they set by Hendrycks and Dieterich for CIFAR and ImageNet.

torchdrift.data.functional.impulse_noise(x: torch.Tensor, severity: int = 1) → torch.Tensor

Applies impulse noise

Args:

x: input image, tensor in 0..1 range

severity: integer severity from 1 to 5

The intensity adapts to the image size to interpolate between the parameters they set by Hendrycks and Dieterich for CIFAR and ImageNet.

torchdrift.data.functional.shot_noise(x: torch.Tensor, severity: int = 1) → torch.Tensor

Applys shot noise.

Args:

x: input image, tensor in 0..1 range

severity: integer severity from 1 to 5

The intensity adapts to the image size to interpolate between the parameters they set by Hendrycks and Dieterich for CIFAR and ImageNet.

torchdrift.data.functional.speckle_noise(x: torch.Tensor, severity: int = 1) → torch.Tensor

Applies speckle noise

Args:

x: input image, tensor in 0..1 range

severity: integer severity from 1 to 5

The intensity adapts to the image size to interpolate between the parameters they set by Hendrycks and Dieterich for CIFAR and ImageNet.