Skip to content

port tests in test_functional_tensor to pytest #3977

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

Merged
merged 3 commits into from
Jun 5, 2021
Merged

port tests in test_functional_tensor to pytest #3977

merged 3 commits into from
Jun 5, 2021

Conversation

sahilg06
Copy link
Contributor

@sahilg06 sahilg06 commented Jun 5, 2021

Refactored the following tests to pytest in the file test/test_functional_tensor.py mentioned in issue #3956

Group A

  • test_assert_image_tensor
  • test_vflip
  • test_hflip
  • test_crop

Group E

  • test_gaussian_blur

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 @sahilg06 ! This looks great, I only have some minor cosmetics comments, but LGTM when green!

@@ -1141,5 +1003,148 @@ def test_adjust_gamma(device, dtype, config):
)


@pytest.mark.parametrize('device', cpu_and_gpu())
@pytest.mark.parametrize('func, args', [(F_t._get_image_size, ()), (F_t.vflip, ()),
Copy link
Member

Choose a reason for hiding this comment

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

It's no big deal but I find this formatting to be a bit cleaner, and easier to read:

@pytest.mark.parametrize('func, args', [
    (F_t._get_image_size, ()),
    (F_t.vflip, ()),
    (F_t.hflip, ()),
    (F_t.crop, (1, 2, 4, 5)),
    (F_t.adjust_brightness, (0., )),
    (F_t.adjust_contrast, (1., )),
    ...
])



@pytest.mark.parametrize('device', cpu_and_gpu())
@pytest.mark.parametrize('top,left,height,width', [(1, 2, 4, 5), # crop inside top-left corner
Copy link
Member

Choose a reason for hiding this comment

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

We could do something similar here

Comment on lines 1110 to 1116
if image_size == 'small':

tensor = torch.from_numpy(
np.arange(3 * 10 * 12, dtype="uint8").reshape((10, 12, 3))
).permute(2, 0, 1).to(device)

else:
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 skip lines here:

Suggested change
if image_size == 'small':
tensor = torch.from_numpy(
np.arange(3 * 10 * 12, dtype="uint8").reshape((10, 12, 3))
).permute(2, 0, 1).to(device)
else:
if image_size == 'small':
tensor = torch.from_numpy(
np.arange(3 * 10 * 12, dtype="uint8").reshape((10, 12, 3))
).permute(2, 0, 1).to(device)
else:

@NicolasHug
Copy link
Member

So should I do the suggested cosmetic changes

Yes ;), I tend to approve early when the requested changes are easy / obvious. I sometimes make comments that don't really need to be addressed and for those I usually say they're Nits. The comments here were bordeline nits.

Thanks a lot for the PR!

@NicolasHug NicolasHug merged commit 6cb73eb into pytorch:master Jun 5, 2021
facebook-github-bot pushed a commit that referenced this pull request Jun 10, 2021
Reviewed By: NicolasHug

Differential Revision: D29027349

fbshipit-source-id: dcf94ab9ba52af22b3274edc96f70ac66ae9f397
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.

3 participants