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

Add AffineTransformation #793

Merged
merged 34 commits into from
Mar 25, 2019
Merged

Add AffineTransformation #793

merged 34 commits into from
Mar 25, 2019

Conversation

ekagra-ranjan
Copy link
Contributor

In reference to #569 added AffineTransformation to superseed LinearTransformation.

update before transform
Add Affinetransformation to superseed LinearTransformation
Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

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

Hi,

Thanks for the PR!

I have one comment about LinearTransformation that I think should be addressed before this can be merged, otherwise this looks good, thanks!

def __init__(self, transformation_matrix):
warnings.warn("The use of the transforms.LinearTransformation transform is deprecated, " +
"please use transforms.AffineTransformation instead.")
super(LinearTransformation, self).__init__(transformation_matrix)
Copy link
Member

Choose a reason for hiding this comment

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

I suppose you want to pass a mean_vector filled with zeros here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What would you prefer for the dimension of mean_vector: 1xD or Dx1 given that transformation_matrix is DxD?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to the implementation of LinearTransformation I think it should be 1 x D.

I feel that the doc of the application of LinearTransformation about whitening is broken. The doc only shows the 1st line of the paragraph in the application block and the rest outside it. How do we write a multi-line bullet point? Do we replace - with ---?

Copy link
Member

Choose a reason for hiding this comment

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

@ekagra-ranjan the dimension of the tensor doesn't matter, you can pass a D tensor and it will be fine, given that broadcasting will happen and the tensor will be filled with all zeros anyway.

About the doc, I'm not sure about how to properly format things. I'd try compiling the documentation locally and checking it visually

torchvision/transforms/transforms.py Outdated Show resolved Hide resolved
torchvision/transforms/transforms.py Show resolved Hide resolved
@codecov-io
Copy link

codecov-io commented Mar 11, 2019

Codecov Report

Merging #793 into master will increase coverage by 0.03%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #793      +/-   ##
==========================================
+ Coverage    38.1%   38.13%   +0.03%     
==========================================
  Files          32       32              
  Lines        3128     3136       +8     
  Branches      488      489       +1     
==========================================
+ Hits         1192     1196       +4     
- Misses       1857     1860       +3     
- Partials       79       80       +1
Impacted Files Coverage Δ
torchvision/transforms/transforms.py 82.79% <66.66%> (-0.62%) ⬇️
torchvision/models/resnet.py 17.29% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8257aff...5883ef0. Read the comment docs.

@ekagra-ranjan ekagra-ranjan changed the title Patch AffineTransformation Add AffineTransformation Mar 16, 2019
@ekagra-ranjan
Copy link
Contributor Author

@fmassa Is there anything else that you want me to do with this PR?

@ekagra-ranjan
Copy link
Contributor Author

@fmassa Are the changes fine?

Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

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

I have a couple more comments, after that I believe this will be good to go

if transformation_matrix.size(0) != transformation_matrix.size(1):
raise ValueError("transformation_matrix should be square. Got " +
"[{} x {}] rectangular matrix.".format(*transformation_matrix.size()))

if mean_vector.size(1) != transformation_matrix.size(0):
Copy link
Member

Choose a reason for hiding this comment

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

this is raise an error if the user tries to use LinearTransformation, because the mean vector is 1d.

I really think that you should just make mean_vector here be 1d as well, and change it in the documentation.

Also, can you keep the tests for the LinearTransformation?

format_string += (str(self.transformation_matrix.numpy().tolist()) + ')')
format_string += (", (mean_vector=" + str(self.mean_vector.numpy().tolist()) + ')')
Copy link
Member

Choose a reason for hiding this comment

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

no need to convert to numpy here, tolist() also exists for torch tensors

Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

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

Thanks!

@fmassa fmassa merged commit c88d7fb into pytorch:master Mar 25, 2019
@yanfengliu
Copy link

Sorry if I misunderstood this, but I thought affine transformation means rotate, scale, shift, and shear, as shown in torchvision.transforms.functional.affine(img, angle, translate, scale, shear, resample=0, fillcolor=None)?

@fmassa
Copy link
Member

fmassa commented Apr 8, 2019

Hum, there seems to be indeed a problem with our naming, which will indeed make this very confusing

Given that this is not in the 0.2.2 release, I'll rename this function with another name.
Any advices on the naming?

@ekagra-ranjan
Copy link
Contributor Author

I have 2 suggestions for the name:

  1. We can let the name remain LinearTransformation as the new transformation is still a linear operation ( (X-mean)/std = AX - B, for some suitable A and B).

  2. We can rename it as PixelNormalization since the transformation is basically is normalizing the values at each pixel in the image with pixel specific mean and standard deviation.

@fmassa
Copy link
Member

fmassa commented Apr 9, 2019

@ekagra-ranjan I agree with leaving the name LinearTransformation.
Can you send a PR with this change?

@ekagra-ranjan
Copy link
Contributor Author

Sure.

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.

4 participants