question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The Affine transform currently does not have an affine matrix parameter

See original GitHub issue

Is your feature request related to a problem? Please describe. The Affine transform forwards its parameters to the AffineGrid class. But it currently does not provide the “affine” parameter which the AffineGrid class also has.

This allows to directly define a affine transformation matrix instead of individual parameters for transformations like rotation. If computations are directly done with affine transformation matrices, this parameter is really helpful (necessary).

Describe the solution you’d like The only change necessary, is to add the affine parameter and to forward it to the AffineGrid class.

class Affine(Transform):
    ...
    def __init__(
        ...
        affine: Optional[NdarrayOrTensor] = None,
        ...
    ) -> None:
        ...
        self.affine_grid = AffineGrid(
            ...
            affine=affine,
            ...
        )

Describe alternatives you’ve considered We patched the affine transform locally.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Nic-Macommented, Nov 11, 2021

Hi @Spenhouet ,

Thanks for your feedback. @wyli @ericspod I think this feature request can help improve the user experience, if you guys don’t have other concerns, I will try to add it based on the suggestion here.

Thanks in advance.

0reactions
Spenhouetcommented, Nov 11, 2021

@wyli Maybe I misunderstood. We are not using the method to apply a static Affine in the pipeline. We are in fact using it like mentioned above.

I get where you are coming from, but I wonder if this is the right case to focus on this. The if-else branches already exist. The suggestion simply exposes the affine parameter to the Affine transform to not need to implement it like you suggested.

I don’t think it will make the Affine transform any more complicated.

EDIT: But it will make other methods which use this Affine transform simpler. So we save on complexity there.

EDIT2: Or how would you rate the code complexity on these two code snippets:

transform = Affine(affine=projection[:3, :3], mode=self.mode)
transformed_matrix, _ = transform(img.squeeze(0)) 

vs.

transform = Affine(mode=self.mode)
transformed_matrix = transform.resampler(img.squeeze(0), transform.affinegrid(projection[:3, :3])[0])

EDIT3: Also the first one will also output the resulting affine while the second will not and will need additional code (further increasing code complexity and boilerplate).

Read more comments on GitHub >

github_iconTop Results From Across the Web

trying to understand the Affine Transform - Stack Overflow
Bonus: 'e' parameter is actually not a transformation. It can have values 1,-1. If it is 1 then nothing happens, but if it...
Read more >
Get Affine Transformation Matrix from TransformParameters
Yes, fixed parameters (usually center of rotation) matter. They are usually initialized to all zeroes, but that might not be true in your...
Read more >
Affine transformations - Washington
Two-dimensional transformations. Here's all you get with a 2 x 2 transformation matrix. M: So: We will develop some intimacy with the elements...
Read more >
Affine Transformations
The affine transforms scale, rotate and shear are actually linear transforms and can be represented by a matrix multiplication of a point represented...
Read more >
What is affine transformation in regard to neural networks?
It is a linear transformation. For example, lines that were parallel before the transformation are still parallel. Scaling, rotation, reflection etcetera.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found