mednet.data.augmentations

Image transformations for our pipelines.

Differences between methods here and those from torchvision.transforms is that these support multiple simultaneous image inputs, which are required to feed segmentation networks (e.g. image and labels or masks). We also take care of data augmentations, in which random flipping and rotation needs to be applied across all input images, but color jittering, for example, only on the input image.

Classes

ElasticDeformation([alpha, sigma, ...])

Elastic deformation of 2D image slightly adapted from [SSP03].

class mednet.data.augmentations.ElasticDeformation(alpha=1000.0, sigma=30.0, spline_order=1, mode='nearest', p=1.0, seed=None)[source]

Bases: object

Elastic deformation of 2D image slightly adapted from [SSP03].

This implementation is based on 2 scipy functions (scipy.ndimage.gaussian_filter() and scipy.ndimage.map_coordinates()). It is very inefficient since it requires data to be moved off the current running device and then back.

Warning

Furthermore, this transform is not scriptable and therefore cannot run on a CUDA or MPS device. Applying it effectively creates a bottleneck in model training.

Source: https://gist.github.com/oeway/2e3b989e0343f0884388ed7ed82eb3b0

Parameters:
  • alpha (float) – A multiplier for the gaussian filter outputs.

  • sigma (float) – Standard deviation for Gaussian kernel.

  • spline_order (int) – The order of the spline interpolation, default is 1. The order has to be in the range 0-5.

  • mode (str) – The mode parameter determines how the input array is extended beyond its boundaries.

  • p (float) – Probability that this transformation will be applied. Meaningful when using it as a data augmentation technique.

  • seed (int | None) – Set the random generator seed, if given. Otherwise, initializes the generator with a random seed (c.f. numpy.random.default_rng()).