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

n#

The number of augmentations to apply.

Type:

int

_getpolicy()[source]#

Returns the Kornia augmentation operation based on the name, probability, and magnitude.

compose_subpolicy_sequential()[source]#

Composes a subpolicy of augmentations sequentially.

get_forward_sequence()[source]#

Returns the forward sequence of augmentations based on the selected indices or parameters.

forward_parameters()[source]#

Computes the forward parameters for the augmentations.

compose_subpolicy_sequential(subpolicy)[source]#

Composes a subpolicy of augmentations sequentially.

Parameters:

subpolicy (List[Tuple[str, float, float]]) – The subpolicy of augmentations.

Returns:

The composed subpolicy of augmentations.

Return type:

kornia.augmentation.auto.PolicySequential

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.

_do_transform()[source]#

Performs the transformation without gradient computation.

forward()[source]#

Overrides the forward method to apply the transformation without gradient computation.

Return type:

Tensor

forward(*args, **kwargs)[source]#

Overrides the forward method to apply the transformation without gradient computation.

Parameters:
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns:

The transformed tensor.

Return type:

torch.Tensor

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:

Tensor

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:

torch.Tensor

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]