Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invertable affine augmentations #10

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

FynnBe
Copy link
Contributor

@FynnBe FynnBe commented May 28, 2021

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.

...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
Copy link
Owner

@constantinpape constantinpape left a comment

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.)

torch_em/transform/augmentation.py Show resolved Hide resolved
torch_em/transform/augmentation.py Show resolved Hide resolved
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
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.


def halo(self, shape):
return self.halo

def apply_inverse(self, *tensors: torch.Tensor, forward_transforms: Sequence[torch.Tensor], padding_mode="border"):
Copy link
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
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
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