Skip to content

Update test_transforms.py #500

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 1 commit into from
May 15, 2018
Merged

Update test_transforms.py #500

merged 1 commit into from
May 15, 2018

Conversation

vfdev-5
Copy link
Collaborator

@vfdev-5 vfdev-5 commented May 15, 2018

Nit improve test_pad_with_non_constant_padding_modes to avoid data multiplication in transforms.ToPILImage() on float data:

# From line 250
img = torch.zeros(3, 27, 27)  # Float32
img[:, :, 0] = 1   # we add 1 and not 255
img = transforms.ToPILImage()(img)  # This converts 1 to 255 due to [pic = pic.mul(255).byte()](https://github.com/pytorch/vision/blob/master/torchvision/transforms/functional.py#L107)

However original image value at the boundary is 1 and not 255.
If we modify img = torch.zeros(3, 27, 27).byte(), then test's correct values are [..., 200, 1, 0] instead of previous [..., 200, 255, 0]

Improve `test_pad_with_non_constant_padding_modes` to avoid data multiplication in `transforms.ToPILImage()` on float data:
```python
img = torch.zeros(3, 27, 27)  # Float32
img[:, :, 0] = 1   # we add 1 and not 255
img = transforms.ToPILImage()(img)  # This converts 1 to 255 due to [pic = pic.mul(255).byte()](https://github.com/pytorch/vision/blob/master/torchvision/transforms/functional.py#L107)
```
and thus test's correct values are [..., 200, 1, 0]
@fmassa fmassa merged commit 9f28cff into pytorch:master May 15, 2018
@fmassa
Copy link
Member

fmassa commented May 15, 2018

Thanks!

varunagrawal pushed a commit to varunagrawal/vision that referenced this pull request Jul 23, 2018
Improve `test_pad_with_non_constant_padding_modes` to avoid data multiplication in `transforms.ToPILImage()` on float data:
```python
img = torch.zeros(3, 27, 27)  # Float32
img[:, :, 0] = 1   # we add 1 and not 255
img = transforms.ToPILImage()(img)  # This converts 1 to 255 due to [pic = pic.mul(255).byte()](https://github.com/pytorch/vision/blob/master/torchvision/transforms/functional.py#L107)
```
and thus test's correct values are [..., 200, 1, 0]
@vfdev-5 vfdev-5 deleted the patch-1 branch August 3, 2020 15:32
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