BatchRandomColorJitter#
- class torchaug.batch_transforms.BatchRandomColorJitter(brightness=0, contrast=0, saturation=0, hue=0, p=0.5, num_rand_calls=-1, inplace=False, value_check=False)[source]#
Randomly change the brightness, contrast, saturation and hue to a batch of images.
The batch is expected to have [B, …, 1 or 3, H, W] shape, where … means an arbitrary number of dimensions.
- Parameters:
brightness (
float|tuple[float,float], optional) – How much to jitter brightness. brightness factor is chosen uniformly from [max(0, 1 - brightness), 1 + brightness] or the given [min, max]. Should be non negative numbers.Default:0contrast (
float|tuple[float,float], optional) – How much to jitter contrast. contrast factor is chosen uniformly from [max(0, 1 - contrast), 1 + contrast] or the given [min, max]. Should be non-negative numbers.Default:0saturation (
float|tuple[float,float], optional) – How much to jitter saturation. saturation factor is chosen uniformly from [max(0, 1 - saturation), 1 + saturation] or the given [min, max]. Should be non negative numbers.Default:0hue (
float|tuple[float,float], optional) – How much to jitter hue. hue_factor is chosen uniformly from [-hue, hue] or the given [min, max]. Should have 0 <= hue <= 0.5 or -0.5 <= min <= max <= 0.5. To jitter hue, the pixel values of the input image has to be non-negative for conversion to HSV space; thus it does not work if you normalize your image to an interval with negative values, or use an interpolation that generates negative values before using this function.Default:0p (
float, optional) – Probability to apply color jitter.Default:0.5num_rand_calls (
int, optional) – Number of random calls performed to apply augmentations at different orders on sub-batches. If -1, B calls are performed. The maximum is 24 = 4!, adjusted automatically if num_rand_calls > 24.Default:-1inplace (
bool, optional) – If True, perform inplace operation to save memory and time.Default:Falsevalue_check (
bool, optional) – Bool to perform tensor value check. Might cause slow down on some devices because of synchronization or large batch size.Default:False- apply_transform(imgs)[source]#
Color jitter the batch of images.
Note
Apply different transformation orders based on
num_rand_calls.- Parameters:
imgs (
Tensor) – Batch of images to jitter.- Return type:
Tensor- Returns:
Randomly color jittered batch of images.
- static get_params(brightness, contrast, saturation, hue, batch_size)[source]#
Get the parameters for the randomized transform to be applied on image.
- Parameters:
brightness (tensor (min, max), optional) – The range from which the brightness factor is chosen uniformly. Pass None to turn off the transformation.
contrast (tensor (min, max), optional) – The range from which the contrast factor is chosen uniformly. Pass None to turn off the transformation.
saturation (tensor (min, max), optional) – The range from which the saturation factor is chosen uniformly. Pass None to turn off the transformation.
hue (
Optional[Tensor]) – The range from which the hue_factor is chosen uniformly. Pass None to turn off the transformation.batch_size (
int) – The number of samples to draw.
- Return type:
tuple[Tensor,Optional[Tensor],Optional[Tensor],Optional[Tensor],Optional[Tensor]]