lightly.transforms
The lightly.transforms package provides additional augmentations.
Contains implementations of Gaussian blur and random rotations which are not part of torchvisions transforms.
.gaussian_blur
Gaussian Blur
- class lightly.transforms.gaussian_blur.GaussianBlur(kernel_size: Optional[float] = None, prob: float = 0.5, scale: Optional[float] = None, sigmas: Tuple[float, float] = (0.2, 2))
Implementation of random Gaussian blur.
Utilizes the built-in ImageFilter method from PIL to apply a Gaussian blur to the input image with a certain probability. The blur is further randomized by sampling uniformly the values of the standard deviation of the Gaussian kernel.
- kernel_size
Will be deprecated in favor of sigmas argument. If set, the old behavior applies and sigmas is ignored. Used to calculate sigma of gaussian blur with kernel_size * input_size.
- prob
Probability with which the blur is applied.
- scale
Will be deprecated in favor of sigmas argument. If set, the old behavior applies and sigmas is ignored. Used to scale the kernel_size of a factor of kernel_scale
- sigmas
Tuple of min and max value from which the std of the gaussian kernel is sampled. Is ignored if kernel_size is set.
.rotation
Random Rotation
- class lightly.transforms.rotation.RandomRotate(prob: float = 0.5, angle: int = 90)
Implementation of random rotation.
Randomly rotates an input image by a fixed angle. By default, we rotate the image by 90 degrees with a probability of 50%.
This augmentation can be very useful for rotation invariant images such as in medical imaging or satellite imaginary.
- prob
Probability with which image is rotated.
- angle
Angle by which the image is rotated. We recommend multiples of 90 to prevent rasterization artifacts. If you pick numbers like 90, 180, 270 the tensor will be rotated without introducing any artifacts.
- class lightly.transforms.rotation.RandomRotateDegrees(prob: float, degrees: Union[float, Tuple[float, float]])
Random rotate image between two rotation angles with a random probability.
- prob
Probability with which image is rotated.
- degrees
Range of degrees to select from. If degrees is a number instead of a sequence like (min, max), the range of degrees will be (-degrees, +degrees). The image is rotated counter-clockwise with a random angle in the (min, max) range or in the (-degrees, +degrees) range.
.solarize
Solarization
- class lightly.transforms.solarize.RandomSolarization(prob: float = 0.5, threshold: int = 128)
Implementation of random image Solarization.
Utilizes the integrated image operation solarize from Pillow. Solarization inverts all pixel values above a threshold (default: 128).
- probability
Probability to apply the transformation
- threshold
Threshold for solarization.