KORNIA UTILS#
Classes#
- class utils.kornia_utils.CustomKorniaRandAugment(n, policy)[source]#
Bases:
PolicyAugmentBase
A custom augmentation class that applies randaug as a Kornia augmentation.
Inherits from kornia.augmentation.auto.PolicyAugmentBase.
- Parameters:
n (int) – The number of augmentations to apply.
policy – The policy of augmentations to apply.
- rand_selector#
A categorical distribution for selecting augmentations randomly.
- Type:
torch.distributions.Categorical
- _getpolicy()[source]#
Returns the Kornia augmentation operation based on the name, probability, and magnitude.
- get_forward_sequence()[source]#
Returns the forward sequence of augmentations based on the selected indices or parameters.
- compose_subpolicy_sequential(subpolicy)[source]#
Composes a subpolicy of augmentations sequentially.
- forward_parameters(batch_shape)[source]#
Computes the forward parameters for the augmentations.
- Parameters:
batch_shape (torch.Size) – The shape of the input batch.
- Returns:
The forward parameters for the augmentations.
- Return type:
List[ParamItem]
- get_forward_sequence(params=None)[source]#
Returns the forward sequence of augmentations based on the selected indices or parameters.
- Parameters:
params (List[ParamItem], optional) – The parameters of the augmentations. Defaults to None.
- Returns:
The forward sequence of augmentations.
- Return type:
List[Tuple[str, kornia.augmentation.auto.operations.ops]]
- class utils.kornia_utils.KorniaAugNoGrad(*args, **kwargs)[source]#
Bases:
AugmentationSequential
A custom augmentation class that applies Kornia augmentations without gradient computation.
Inherits from kornia.augmentation.AugmentationSequential.
- Parameters:
*args – Variable length argument list.
**kwargs – Arbitrary keyword arguments.
- forward()[source]#
Overrides the forward method to apply the transformation without gradient computation.
- Return type:
- class utils.kornia_utils.KorniaMultiAug(n_augs, aug_list)[source]#
Bases:
AugmentationSequential
A custom augmentation class that performs multiple Kornia augmentations.
- Parameters:
n_augs (int) – The number of augmentations to apply.
aug_list (List[kornia.augmentation.AugmentationBase2D]) – The list of augmentations to apply.
- forward()[source]#
Overrides the forward method to apply the transformation without gradient computation.
- Return type:
- forward(x)[source]#
Overrides the forward method to apply the transformation without gradient computation.
- Parameters:
x (torch.Tensor) – The input tensor.
- Returns:
The transformed tensor.
- Return type:
Functions#
- utils.kornia_utils.to_kornia_transform(transform, apply=True)[source]#
Converts PIL transforms to Kornia transforms.
- Parameters:
transform (transforms.Compose) – The torchvision transform to be converted.
apply (bool, optional) – Whether to convert the processed kornia transforms list into a KorniaAugNoGrad object. Defaults to True.
- Returns:
The converted Kornia transforms.
- Return type:
Union[List[kornia.augmentation.AugmentationBase2D], KorniaAugNoGrad]