Automatic Augmentation Methods¶
Augmentation Policy¶
This module contains common data augmentation policies that can improve the accuracy of image classification models.
- class kornia.augmentation.auto.AutoAugment(policy='imagenet', transformation_matrix_mode='silent')[source]¶
Apply AutoAugment [CZM+18] searched strategies.
- Parameters:
policy (
Union[str,List[List[Tuple[str,Union[float,int],Union[float,int,None]]]]], optional) – a customized policy config or presets of “imagenet”, “cifar10”, and “svhn”. Default:"imagenet"transformation_matrix_mode (
str, optional) – computation mode for the chained transformation matrix, via .transform_matrix attribute. If silent, transformation matrix will be computed silently and the non-rigid modules will be ignored as identity transformations. If rigid, transformation matrix will be computed silently and the non-rigid modules will trigger errors. If skip, transformation matrix will be totally ignored. Default:"silent"
Examples
>>> import torch >>> import kornia.augmentation as K >>> in_tensor = torch.rand(5, 3, 30, 30) >>> aug = K.AugmentationSequential(AutoAugment()) >>> aug(in_tensor).shape torch.Size([5, 3, 30, 30])
- get_transformation_matrix(input, params=None, recompute=False, extra_args=None)[source]¶
Compute the transformation matrix according to the provided parameters.
- Parameters:
input (
Tensor) – the input torch.Tensor.params (
Optional[List[ParamItem]], optional) – params for the sequence. Default:Nonerecompute (
bool, optional) – if to recompute the transformation matrix according to the params. default: False. Default:Falseextra_args (
Optional[Dict[str,Any]], optional) – Optional dictionary of extra arguments with specific options for different input types. Default:None
- Return type:
- forward_parameters(batch_shape)[source]¶
Generate per-module parameters for one policy forward pass.
- class kornia.augmentation.auto.RandAugment(n, m, policy=None, transformation_matrix_mode='silent')[source]¶
Apply RandAugment [CZSL20] augmentation strategies.
- Parameters:
n (
int) – the number of augmentations to apply sequentially.m (
int) – magnitude for all the augmentations, ranged from [0, 30].policy (
Optional[List[List[Tuple[str,Union[float,int],Union[float,int,None]]]]], optional) – candidate transformations. If None, a default candidate list will be used. Default:Nonetransformation_matrix_mode (
str, optional) – computation mode for the chained transformation matrix, via .transform_matrix attribute. If silent, transformation matrix will be computed silently and the non-rigid modules will be ignored as identity transformations. If rigid, transformation matrix will be computed silently and the non-rigid modules will trigger errors. If skip, transformation matrix will be totally ignored. Default:"silent"
Examples
>>> import kornia.augmentation as K >>> in_tensor = torch.rand(5, 3, 30, 30) >>> aug = K.AugmentationSequential(RandAugment(n=2, m=10)) >>> aug(in_tensor).shape torch.Size([5, 3, 30, 30])
- get_transformation_matrix(input, params=None, recompute=False, extra_args=None)[source]¶
Compute the transformation matrix according to the provided parameters.
- Parameters:
input (
Tensor) – the input torch.Tensor.params (
Optional[List[ParamItem]], optional) – params for the sequence. Default:Nonerecompute (
bool, optional) – if to recompute the transformation matrix according to the params. default: False. Default:Falseextra_args (
Optional[Dict[str,Any]], optional) – Optional dictionary of extra arguments with specific options for different input types. Default:None
- Return type:
- class kornia.augmentation.auto.TrivialAugment(policy=None, transformation_matrix_mode='silent')[source]¶
Apply TrivialAugment [MullerH21] augmentation strategies.
- Parameters:
policy (
Optional[List[List[Tuple[str,Union[float,int],Union[float,int,None]]]]], optional) – candidate transformations. If None, a default candidate list will be used. Default:Nonetransformation_matrix_mode (
str, optional) – computation mode for the chained transformation matrix, via .transform_matrix attribute. If silent, transformation matrix will be computed silently and the non-rigid modules will be ignored as identity transformations. If rigid, transformation matrix will be computed silently and the non-rigid modules will trigger errors. If skip, transformation matrix will be totally ignored. Default:"silent"
Examples
>>> import kornia.augmentation as K >>> in_tensor = torch.rand(5, 3, 30, 30) >>> aug = K.AugmentationSequential(TrivialAugment()) >>> aug(in_tensor).shape torch.Size([5, 3, 30, 30])
- get_transformation_matrix(input, params=None, recompute=False, extra_args=None)[source]¶
Compute the transformation matrix according to the provided parameters.
- Parameters:
input (
Tensor) – the input torch.Tensor.params (
Optional[List[ParamItem]], optional) – params for the sequence. Default:Nonerecompute (
bool, optional) – if to recompute the transformation matrix according to the params. default: False. Default:Falseextra_args (
Optional[Dict[str,Any]], optional) – Optional dictionary of extra arguments with specific options for different input types. Default:None
- Return type:
- forward_parameters(batch_shape)[source]¶
Generate per-module parameters for one policy forward pass.
Augmentation Search Methods¶
WIP. This module contains common data augmentation search methods.