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

Port affine transform tests in test_tranforms to pytest #3984

Merged
merged 3 commits into from
Jun 8, 2021

Conversation

Ishan-Kumar2
Copy link
Contributor

Refactor Group C as mentioned in #3945

  • test_affine
  • test_random_affine

@NicolasHug I converted the test_affine function into a class so as to optimize the parameterisation. Let me know if the names of the functions need to be changed.

Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

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

thanks @Ishan-Kumar2 , I made a few comments but this looks good!

result_matrix[2, 2] = 1
return np.linalg.inv(result_matrix)

def _test_transformation(self, a, t, s, sh, PIL_Image):
Copy link
Member

Choose a reason for hiding this comment

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

here and in the rest of the code, let's take this opportunity to use better names: angle, translate, scale, shear, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay, will do

Comment on lines 1931 to 1935
@pytest.mark.parametrize("pt", [(16, 16), (20, 16), (20, 20)])
@pytest.mark.parametrize("i", range(-5, 5))
@pytest.mark.parametrize("j", range(-5, 5))
def test_make_img_affine(self, pt, i, j):
self.input_img[pt[0] + i, pt[1] + j, :] = [255, 155, 55]
Copy link
Member

Choose a reason for hiding this comment

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

Hm, this almost works 😄
The problem is that this assumes that test_make_img_affine is called before the rest of the tests, which isn't an assumption we should make. Also, filling the values of the input_img isn't a test in itself so we should use a different logic here.

This is a good case for using a fixture https://docs.pytest.org/en/6.2.x/fixture.html:

@pytest.fixture(scope='class')
def input_img(self):
    out = np.zeros((40, 40, 3), dtype=np.uint8)
    for pt in ...
        for i in ...
            for j in ...
    ...
    return out

and then we can use input_img in PIL_Image directly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha yeah it makes sense. Guess I got carried away by pytest's parameterisation 😆

F.affine(self.input_img, 10, translate=0, scale=1, shear=1)

@pytest.fixture
def PIL_Image(self):
Copy link
Member

Choose a reason for hiding this comment

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

Here and everywhere else, let's rename this into pil_image as the current case suggests that this is a class instead of an instance

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, will do

@Ishan-Kumar2
Copy link
Contributor Author

@NicolasHug thanks a lot for the feedback and detailed review. I have made the changes. Let me know if anything else needs to be updated :)

Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

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

Thanks @Ishan-Kumar2 !

@NicolasHug NicolasHug merged commit 9dca76d into pytorch:master Jun 8, 2021
facebook-github-bot pushed a commit that referenced this pull request Jun 14, 2021
Reviewed By: fmassa

Differential Revision: D29097725

fbshipit-source-id: 8913fc8e9f8f11beb1de512c22807c8bd39690c0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants