Skip to content

Commit

Permalink
Doc, Test Fixes in Normalize (#1063)
Browse files Browse the repository at this point in the history
* updates on normalize

* test fixes

* Update test_transforms.py
  • Loading branch information
surgan12 authored and fmassa committed Jun 28, 2019
1 parent 3615802 commit 05ba3f5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,11 @@ def samples_from_standard_normal(tensor):
# Checking if Normalize can be printed as string
transforms.Normalize(mean, std).__repr__()

# Checking the optional in-place behaviour
tensor = torch.rand((1, 16, 16))
tensor_inplace = transforms.Normalize((0.5,), (0.5,), inplace=True)(tensor)
assert torch.equal(tensor, tensor_inplace)

def test_normalize_different_dtype(self):
for dtype1 in [torch.float32, torch.float64]:
img = torch.rand(3, 10, 10, dtype=dtype1)
Expand Down
1 change: 1 addition & 0 deletions torchvision/transforms/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def normalize(tensor, mean, std, inplace=False):
tensor (Tensor): Tensor image of size (C, H, W) to be normalized.
mean (sequence): Sequence of means for each channel.
std (sequence): Sequence of standard deviations for each channel.
inplace(bool,optional): Bool to make this operation inplace.
Returns:
Tensor: Normalized Tensor image.
Expand Down
2 changes: 2 additions & 0 deletions torchvision/transforms/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ class Normalize(object):
Args:
mean (sequence): Sequence of means for each channel.
std (sequence): Sequence of standard deviations for each channel.
inplace(bool,optional): Bool to make this operation in-place.
"""

def __init__(self, mean, std, inplace=False):
Expand Down

0 comments on commit 05ba3f5

Please sign in to comment.