equiadapt.images.canonicalization package

Submodules

equiadapt.images.canonicalization.continuous_group module

class equiadapt.images.canonicalization.continuous_group.ContinuousGroupImageCanonicalization(canonicalization_network: Module, canonicalization_hyperparams: DictConfig, in_shape: tuple)[source]

Bases: ContinuousGroupCanonicalization

This class represents a continuous group image canonicalization model.

The model is designed to be equivariant under a continuous group of transformations, which can include rotations and reflections. Other specific continuous group image canonicalization classes can be derived from this class.

__init__()[source]

Initializes the ContinuousGroupImageCanonicalization instance.

get_rotation_matrix_from_vector()

This method takes the input vector and returns the rotation matrix.

get_groupelement()[source]

This method maps the input image to the group element.

transformations_before_canonicalization_network_forward()[source]

Applies transformations to the input image before forwarding it through the canonicalization network.

get_group_from_out_vectors()[source]

This method takes the output of the canonicalization network and returns the group element.

canonicalize()[source]

This method takes an image as input and returns the canonicalized image.

invert_canonicalization()[source]

Inverts the canonicalization process on the output of the canonicalized image.

canonicalize(x: Tensor, targets: List | None = None, **kwargs: Any) Tensor | Tuple[Tensor, List][source]

This method takes an image as input and returns the canonicalized image

Parameters:
  • x (torch.Tensor) – The input image.

  • targets (Optional[List]) – The targets, if any.

Returns:

canonicalized image

Return type:

torch.Tensor

get_group_from_out_vectors(out_vectors: Tensor) Tuple[dict, Tensor][source]

This method takes the output of the canonicalization network and returns the group element

Parameters:

out_vectors (torch.Tensor) – output of the canonicalization network

Returns:

group element torch.Tensor: group element representation

Return type:

dict

get_groupelement(x: Tensor) dict[source]

This method takes the input image and maps it to the group element

Parameters:

x (torch.Tensor) – input image

Returns:

group element

Return type:

dict

invert_canonicalization(x_canonicalized_out: Tensor, **kwargs: Any) Tensor[source]

Inverts the canonicalization process on the output of the canonicalized image.

Parameters:

x_canonicalized_out (torch.Tensor) – The output of the canonicalized image.

Returns:

The output corresponding to the original image.

Return type:

torch.Tensor

transformations_before_canonicalization_network_forward(x: Tensor) Tensor[source]

Applies transformations to the input image before forwarding it through the canonicalization network.

Parameters:

x (torch.Tensor) – The input image.

Returns:

The transformed image.

Return type:

torch.Tensor

class equiadapt.images.canonicalization.continuous_group.OptimizedSteerableImageCanonicalization(canonicalization_network: Module, canonicalization_hyperparams: DictConfig, in_shape: tuple)[source]

Bases: ContinuousGroupImageCanonicalization

This class represents an optimized steerable image canonicalization model.

The model is designed to be equivariant under a continuous group of transformations, which can include rotations and reflections.

__init__()[source]

Initializes the OptimizedSteerableImageCanonicalization instance.

get_rotation_matrix_from_vector()[source]

This method takes the input vector and returns the rotation matrix.

group_augment()[source]

This method applies random rotations and reflections to the input images.

get_groupelement()[source]

This method maps the input image to the group element.

get_optimization_specific_loss()[source]

This method returns the optimization specific loss.

get_groupelement(x: Tensor) dict[source]

Maps the input image to the group element.

Parameters:

x (torch.Tensor) – The input image.

Returns:

The group element.

Return type:

dict

get_optimization_specific_loss() Tensor[source]

This method returns the optimization specific loss

Returns:

optimization specific loss

Return type:

torch.Tensor

get_rotation_matrix_from_vector(vectors: Tensor) Tensor[source]

This method takes the input vector and returns the rotation matrix

Parameters:

vectors (torch.Tensor) – input vector

Returns:

rotation matrices

Return type:

torch.Tensor

group_augment(x: Tensor) Tuple[Tensor, Tensor][source]

Augmentation of the input images by applying random rotations and, if applicable, reflections, with corresponding transformation matrices.

Parameters:

x (torch.Tensor) – Input images of shape (batch_size, in_channels, height, width).

Returns:

Augmented images. torch.Tensor: Corresponding transformation matrices.

Return type:

torch.Tensor

class equiadapt.images.canonicalization.continuous_group.SteerableImageCanonicalization(canonicalization_network: Module, canonicalization_hyperparams: DictConfig, in_shape: tuple)[source]

Bases: ContinuousGroupImageCanonicalization

This class represents a steerable image canonicalization model.

The model is designed to be equivariant under a continuous group of euclidean transformations - rotations and reflections.

__init__()[source]

Initializes the SteerableImageCanonicalization instance.

get_rotation_matrix_from_vector()[source]

This method takes the input vector and returns the rotation matrix.

get_groupelement()[source]

This method maps the input image to the group element.

get_groupelement(x: Tensor) dict[source]

This method takes the input image and maps it to the group element

Parameters:

x (torch.Tensor) – input image

Returns:

group element

Return type:

dict

get_rotation_matrix_from_vector(vectors: Tensor) Tensor[source]

This method takes the input vector and returns the rotation matrix

Parameters:

vectors (torch.Tensor) – input vector

Returns:

rotation matrices

Return type:

torch.Tensor

equiadapt.images.canonicalization.discrete_group module

class equiadapt.images.canonicalization.discrete_group.DiscreteGroupImageCanonicalization(canonicalization_network: Module, canonicalization_hyperparams: DictConfig, in_shape: tuple)[source]

Bases: DiscreteGroupCanonicalization

This class represents a discrete group image canonicalization model.

The model is designed to be equivariant under a discrete group of transformations, which can include rotations and reflections. Other discrete group canonicalizers can be derived from this class.

__init__()[source]

Initializes the DiscreteGroupImageCanonicalization instance.

groupactivations_to_groupelement()[source]

Takes the activations for each group element as input and returns the group element.

get_groupelement()[source]

Maps the input image to a group element.

transformations_before_canonicalization_network_forward()[source]

Applies transformations to the input images before passing it through the canonicalization network.

canonicalize()[source]

Canonicalizes the input images.

invert_canonicalization()[source]

Inverts the canonicalization of the output of the canonicalized image.

canonicalize(x: Tensor, targets: List | None = None, **kwargs: Any) Tensor | Tuple[Tensor, List][source]

Canonicalizes the input images.

Parameters:
  • x (torch.Tensor) – The input images.

  • targets (Optional[List], optional) – The targets for instance segmentation. Defaults to None.

  • **kwargs (Any) – Additional keyword arguments.

Returns:

The canonicalized image, and optionally the targets.

Return type:

Union[torch.Tensor, Tuple[torch.Tensor, List]]

get_group_activations(x: Tensor) Tensor[source]

Gets the group activations for the input images.

Parameters:

x (torch.Tensor) – The input images.

Returns:

The group activations.

Return type:

torch.Tensor

get_groupelement(x: Tensor) Dict[str, Tensor][source]

Maps the input image to a group element.

Parameters:

x (torch.Tensor) – The input images.

Returns:

The corresponding group elements.

Return type:

dict[str, torch.Tensor]

groupactivations_to_groupelement(group_activations: Tensor) dict[source]

This method takes the activations for each group element as input and returns the group element

Parameters:

group_activations (torch.Tensor) – activations for each group element.

Returns:

group element.

Return type:

dict

invert_canonicalization(x_canonicalized_out: Tensor, **kwargs: Any) Tensor[source]

Inverts the canonicalization of the output of the canonicalized image.

Parameters:
  • x_canonicalized_out (torch.Tensor) – The output of the canonicalized image.

  • **kwargs (Any) – Additional keyword arguments.

Returns:

The output corresponding to the original image.

Return type:

torch.Tensor

transformations_before_canonicalization_network_forward(x: Tensor) Tensor[source]

Applies transformations to the input images before passing it through the canonicalization network.

Parameters:

x (torch.Tensor) – The input image.

Returns:

The pre-canonicalized image.

Return type:

torch.Tensor

class equiadapt.images.canonicalization.discrete_group.GroupEquivariantImageCanonicalization(canonicalization_network: Module, canonicalization_hyperparams: DictConfig, in_shape: tuple)[source]

Bases: DiscreteGroupImageCanonicalization

This class represents a discrete group equivariant image canonicalization model.

The model is designed to be equivariant under a discrete group of transformations, which can include rotations and reflections.

__init__()[source]

Initializes the GroupEquivariantImageCanonicalization instance.

get_group_activations()[source]

Gets the group activations for the input images.

get_group_activations(x: Tensor) Tensor[source]

Gets the group activations for the input image.

This method takes an image as input, applies transformations before forwarding it through the canonicalization network, and then returns the group activations.

Parameters:

x (torch.Tensor) – The input image.

Returns:

The group activations.

Return type:

torch.Tensor

class equiadapt.images.canonicalization.discrete_group.OptimizedGroupEquivariantImageCanonicalization(canonicalization_network: Module, canonicalization_hyperparams: DictConfig, in_shape: tuple)[source]

Bases: DiscreteGroupImageCanonicalization

This class represents an optimized (discrete) group equivariant image canonicalization model.

The model is designed to be equivariant under a discrete group of transformations, which can include rotations and reflections.

__init__()[source]

Initializes the OptimizedGroupEquivariantImageCanonicalization instance.

rotate_and_maybe_reflect()[source]

Rotate and maybe reflect the input images.

group_augment()[source]

Augment the input images by applying group transformations (rotations and reflections).

get_group_activations()[source]

Gets the group activations for the input images.

get_optimization_specific_loss()[source]

Gets the loss specific to the optimization process.

get_group_activations(x: Tensor) Tensor[source]

Gets the group activations for the input image.

Parameters:

x (torch.Tensor) – The input image.

Returns:

The group activations.

Return type:

torch.Tensor

get_optimization_specific_loss() Tensor[source]

Gets the loss specific to the optimization process.

Returns:

The loss.

Return type:

torch.Tensor

group_augment(x: Tensor) Tensor[source]

Augment the input images by applying group transformations (rotations and reflections).

Parameters:

x (torch.Tensor) – The input image.

Returns:

The augmented image.

Return type:

torch.Tensor

rotate_and_maybe_reflect(x: Tensor, degrees: Tensor, reflect: bool = False) List[Tensor][source]

Rotate and maybe reflect the input images.

Parameters:
  • x (torch.Tensor) – The input image.

  • degrees (torch.Tensor) – The degrees of rotation.

  • reflect (bool, optional) – Whether to reflect the image. Defaults to False.

Returns:

The list of rotated and maybe reflected images.

Return type:

List[torch.Tensor]

Module contents

class equiadapt.images.canonicalization.ContinuousGroupImageCanonicalization(canonicalization_network: Module, canonicalization_hyperparams: DictConfig, in_shape: tuple)[source]

Bases: ContinuousGroupCanonicalization

This class represents a continuous group image canonicalization model.

The model is designed to be equivariant under a continuous group of transformations, which can include rotations and reflections. Other specific continuous group image canonicalization classes can be derived from this class.

__init__()[source]

Initializes the ContinuousGroupImageCanonicalization instance.

get_rotation_matrix_from_vector()

This method takes the input vector and returns the rotation matrix.

get_groupelement()[source]

This method maps the input image to the group element.

transformations_before_canonicalization_network_forward()[source]

Applies transformations to the input image before forwarding it through the canonicalization network.

get_group_from_out_vectors()[source]

This method takes the output of the canonicalization network and returns the group element.

canonicalize()[source]

This method takes an image as input and returns the canonicalized image.

invert_canonicalization()[source]

Inverts the canonicalization process on the output of the canonicalized image.

canonicalize(x: Tensor, targets: List | None = None, **kwargs: Any) Tensor | Tuple[Tensor, List][source]

This method takes an image as input and returns the canonicalized image

Parameters:
  • x (torch.Tensor) – The input image.

  • targets (Optional[List]) – The targets, if any.

Returns:

canonicalized image

Return type:

torch.Tensor

get_group_from_out_vectors(out_vectors: Tensor) Tuple[dict, Tensor][source]

This method takes the output of the canonicalization network and returns the group element

Parameters:

out_vectors (torch.Tensor) – output of the canonicalization network

Returns:

group element torch.Tensor: group element representation

Return type:

dict

get_groupelement(x: Tensor) dict[source]

This method takes the input image and maps it to the group element

Parameters:

x (torch.Tensor) – input image

Returns:

group element

Return type:

dict

invert_canonicalization(x_canonicalized_out: Tensor, **kwargs: Any) Tensor[source]

Inverts the canonicalization process on the output of the canonicalized image.

Parameters:

x_canonicalized_out (torch.Tensor) – The output of the canonicalized image.

Returns:

The output corresponding to the original image.

Return type:

torch.Tensor

transformations_before_canonicalization_network_forward(x: Tensor) Tensor[source]

Applies transformations to the input image before forwarding it through the canonicalization network.

Parameters:

x (torch.Tensor) – The input image.

Returns:

The transformed image.

Return type:

torch.Tensor

class equiadapt.images.canonicalization.DiscreteGroupImageCanonicalization(canonicalization_network: Module, canonicalization_hyperparams: DictConfig, in_shape: tuple)[source]

Bases: DiscreteGroupCanonicalization

This class represents a discrete group image canonicalization model.

The model is designed to be equivariant under a discrete group of transformations, which can include rotations and reflections. Other discrete group canonicalizers can be derived from this class.

__init__()[source]

Initializes the DiscreteGroupImageCanonicalization instance.

groupactivations_to_groupelement()[source]

Takes the activations for each group element as input and returns the group element.

get_groupelement()[source]

Maps the input image to a group element.

transformations_before_canonicalization_network_forward()[source]

Applies transformations to the input images before passing it through the canonicalization network.

canonicalize()[source]

Canonicalizes the input images.

invert_canonicalization()[source]

Inverts the canonicalization of the output of the canonicalized image.

canonicalize(x: Tensor, targets: List | None = None, **kwargs: Any) Tensor | Tuple[Tensor, List][source]

Canonicalizes the input images.

Parameters:
  • x (torch.Tensor) – The input images.

  • targets (Optional[List], optional) – The targets for instance segmentation. Defaults to None.

  • **kwargs (Any) – Additional keyword arguments.

Returns:

The canonicalized image, and optionally the targets.

Return type:

Union[torch.Tensor, Tuple[torch.Tensor, List]]

get_group_activations(x: Tensor) Tensor[source]

Gets the group activations for the input images.

Parameters:

x (torch.Tensor) – The input images.

Returns:

The group activations.

Return type:

torch.Tensor

get_groupelement(x: Tensor) Dict[str, Tensor][source]

Maps the input image to a group element.

Parameters:

x (torch.Tensor) – The input images.

Returns:

The corresponding group elements.

Return type:

dict[str, torch.Tensor]

groupactivations_to_groupelement(group_activations: Tensor) dict[source]

This method takes the activations for each group element as input and returns the group element

Parameters:

group_activations (torch.Tensor) – activations for each group element.

Returns:

group element.

Return type:

dict

invert_canonicalization(x_canonicalized_out: Tensor, **kwargs: Any) Tensor[source]

Inverts the canonicalization of the output of the canonicalized image.

Parameters:
  • x_canonicalized_out (torch.Tensor) – The output of the canonicalized image.

  • **kwargs (Any) – Additional keyword arguments.

Returns:

The output corresponding to the original image.

Return type:

torch.Tensor

transformations_before_canonicalization_network_forward(x: Tensor) Tensor[source]

Applies transformations to the input images before passing it through the canonicalization network.

Parameters:

x (torch.Tensor) – The input image.

Returns:

The pre-canonicalized image.

Return type:

torch.Tensor

class equiadapt.images.canonicalization.GroupEquivariantImageCanonicalization(canonicalization_network: Module, canonicalization_hyperparams: DictConfig, in_shape: tuple)[source]

Bases: DiscreteGroupImageCanonicalization

This class represents a discrete group equivariant image canonicalization model.

The model is designed to be equivariant under a discrete group of transformations, which can include rotations and reflections.

__init__()[source]

Initializes the GroupEquivariantImageCanonicalization instance.

get_group_activations()[source]

Gets the group activations for the input images.

get_group_activations(x: Tensor) Tensor[source]

Gets the group activations for the input image.

This method takes an image as input, applies transformations before forwarding it through the canonicalization network, and then returns the group activations.

Parameters:

x (torch.Tensor) – The input image.

Returns:

The group activations.

Return type:

torch.Tensor

class equiadapt.images.canonicalization.OptimizedGroupEquivariantImageCanonicalization(canonicalization_network: Module, canonicalization_hyperparams: DictConfig, in_shape: tuple)[source]

Bases: DiscreteGroupImageCanonicalization

This class represents an optimized (discrete) group equivariant image canonicalization model.

The model is designed to be equivariant under a discrete group of transformations, which can include rotations and reflections.

__init__()[source]

Initializes the OptimizedGroupEquivariantImageCanonicalization instance.

rotate_and_maybe_reflect()[source]

Rotate and maybe reflect the input images.

group_augment()[source]

Augment the input images by applying group transformations (rotations and reflections).

get_group_activations()[source]

Gets the group activations for the input images.

get_optimization_specific_loss()[source]

Gets the loss specific to the optimization process.

get_group_activations(x: Tensor) Tensor[source]

Gets the group activations for the input image.

Parameters:

x (torch.Tensor) – The input image.

Returns:

The group activations.

Return type:

torch.Tensor

get_optimization_specific_loss() Tensor[source]

Gets the loss specific to the optimization process.

Returns:

The loss.

Return type:

torch.Tensor

group_augment(x: Tensor) Tensor[source]

Augment the input images by applying group transformations (rotations and reflections).

Parameters:

x (torch.Tensor) – The input image.

Returns:

The augmented image.

Return type:

torch.Tensor

rotate_and_maybe_reflect(x: Tensor, degrees: Tensor, reflect: bool = False) List[Tensor][source]

Rotate and maybe reflect the input images.

Parameters:
  • x (torch.Tensor) – The input image.

  • degrees (torch.Tensor) – The degrees of rotation.

  • reflect (bool, optional) – Whether to reflect the image. Defaults to False.

Returns:

The list of rotated and maybe reflected images.

Return type:

List[torch.Tensor]

class equiadapt.images.canonicalization.OptimizedSteerableImageCanonicalization(canonicalization_network: Module, canonicalization_hyperparams: DictConfig, in_shape: tuple)[source]

Bases: ContinuousGroupImageCanonicalization

This class represents an optimized steerable image canonicalization model.

The model is designed to be equivariant under a continuous group of transformations, which can include rotations and reflections.

__init__()[source]

Initializes the OptimizedSteerableImageCanonicalization instance.

get_rotation_matrix_from_vector()[source]

This method takes the input vector and returns the rotation matrix.

group_augment()[source]

This method applies random rotations and reflections to the input images.

get_groupelement()[source]

This method maps the input image to the group element.

get_optimization_specific_loss()[source]

This method returns the optimization specific loss.

get_groupelement(x: Tensor) dict[source]

Maps the input image to the group element.

Parameters:

x (torch.Tensor) – The input image.

Returns:

The group element.

Return type:

dict

get_optimization_specific_loss() Tensor[source]

This method returns the optimization specific loss

Returns:

optimization specific loss

Return type:

torch.Tensor

get_rotation_matrix_from_vector(vectors: Tensor) Tensor[source]

This method takes the input vector and returns the rotation matrix

Parameters:

vectors (torch.Tensor) – input vector

Returns:

rotation matrices

Return type:

torch.Tensor

group_augment(x: Tensor) Tuple[Tensor, Tensor][source]

Augmentation of the input images by applying random rotations and, if applicable, reflections, with corresponding transformation matrices.

Parameters:

x (torch.Tensor) – Input images of shape (batch_size, in_channels, height, width).

Returns:

Augmented images. torch.Tensor: Corresponding transformation matrices.

Return type:

torch.Tensor

class equiadapt.images.canonicalization.SteerableImageCanonicalization(canonicalization_network: Module, canonicalization_hyperparams: DictConfig, in_shape: tuple)[source]

Bases: ContinuousGroupImageCanonicalization

This class represents a steerable image canonicalization model.

The model is designed to be equivariant under a continuous group of euclidean transformations - rotations and reflections.

__init__()[source]

Initializes the SteerableImageCanonicalization instance.

get_rotation_matrix_from_vector()[source]

This method takes the input vector and returns the rotation matrix.

get_groupelement()[source]

This method maps the input image to the group element.

get_groupelement(x: Tensor) dict[source]

This method takes the input image and maps it to the group element

Parameters:

x (torch.Tensor) – input image

Returns:

group element

Return type:

dict

get_rotation_matrix_from_vector(vectors: Tensor) Tensor[source]

This method takes the input vector and returns the rotation matrix

Parameters:

vectors (torch.Tensor) – input vector

Returns:

rotation matrices

Return type:

torch.Tensor