Skip to content

Partially revert #519 due to performance regression & other issues #521

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 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ def test_random_horizontal_flip(self):
# Checking if RandomHorizontalFlip can be printed as string
transforms.RandomHorizontalFlip().__repr__()

@unittest.skipIf(stats is None, 'scipt.stats is not available')
@unittest.skipIf(stats is None, 'scipy.stats is not available')
def test_normalize(self):
def samples_from_standard_normal(tensor):
p_value = stats.kstest(list(tensor.view(-1)), 'norm', args=(0, 1)).pvalue
Expand Down
7 changes: 4 additions & 3 deletions torchvision/transforms/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,10 @@ def normalize(tensor, mean, std):
if not _is_tensor_image(tensor):
raise TypeError('tensor is not a torch image.')

mean = torch.Tensor(mean).view((tensor.shape[0], 1, 1))
std = torch.Tensor(std).view((tensor.shape[0], 1, 1))
return tensor.sub_(mean).div_(std)
# This is faster than using broadcasting, don't change without benchmarking
for t, m, s in zip(tensor, mean, std):
t.sub_(m).div_(s)
return tensor


def resize(img, size, interpolation=Image.BILINEAR):
Expand Down