Skip to content

Invertable affine augmentations#10

Open
FynnBe wants to merge 9 commits into
constantinpape:mainfrom
FynnBe:invertable_augs
Open

Invertable affine augmentations#10
FynnBe wants to merge 9 commits into
constantinpape:mainfrom
FynnBe:invertable_augs

Conversation

@FynnBe

@FynnBe FynnBe commented May 28, 2021

Copy link
Copy Markdown
Contributor

idea: the augmentation pipleine gets an additional kwarg: return_transform (default False) just like all kornia augmentations have. If True it returns a the transformed tensors and the responding affine transformation matrices. These can be used, e.g. to call AugmentaionPipeline.apply_inverse to invert the (geometric part of the) transformations.

FynnBe added 6 commits May 28, 2021 11:23
...to (Kornia)AugmentationPipeline.
Returned trans_matrices allow apply_inverse
even if aug.return_transform is False
failed on windows before, due to drive letter being interpreted as uri schema

@constantinpape constantinpape left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the augmentation pipleine gets an additional kwarg: return_transform (default False) just like all kornia augmentations have.

I think that part makes sense.

If True it returns a the transformed tensors and the responding affine transformation matrices.

But the transformation is in general not an affine matrix. Quite a few augmentations can be expressed as affine, but this does not hold true in general, e.g. for elastic deformations.

These can be used, e.g. to call AugmentaionPipeline.apply_inverse to invert the (geometric part of the) transformations.

I think we need to be aware of what transformation and then choose the correct inverse function based on the transformation (or throw some error if the inverse for the transformation is not defined.)

Comment thread torch_em/transform/augmentation.py
Comment thread torch_em/transform/augmentation.py
Comment thread torch_em/transform/augmentation.py Outdated
class KorniaAugmentationPipeline(torch.nn.Module):
interpolatable_torch_tpyes = [torch.float16, torch.float32, torch.float64]
interpolatable_numpy_types = [np.dtype('float32'), np.dtype('float64')]
class AugmentationPipeline(torch.nn.Module):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "KorniaAugmentationPipeline" makes more sense as a name, because it's not for generic Augmentations.

Comment thread torch_em/transform/augmentation.py Outdated
def halo(self, shape):
return self.halo

def apply_inverse(self, *tensors: torch.Tensor, forward_transforms: Sequence[torch.Tensor], padding_mode="border"):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only works for affine trafos / anything that can be expressed as affine trafo. But that's certainly not the case for all augmentations we have, e.g. elastic deformations.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed it to apply_inverse_affine to make it explicit that it applies only to transformations that can be expressed as an affine transformation.

@FynnBe FynnBe changed the title Invertable augmentations Invertable affine augmentations May 31, 2021
@constantinpape

Copy link
Copy Markdown
Owner

I think it would still make sense to eventually come up with a more general functionality for inverting the augmentations, but for now we can go with this option. I think we should def. add tests here though...

constantinpape pushed a commit that referenced this pull request Dec 20, 2023
* Update distance transform (#11 - Getting instance segmentations from the distance transform)

* Making the encoder argument flexible (to either pytorch modules or model name as str)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants