Skip to content

Commit da67a1e

Browse files
kohr-hfmassa
authored andcommitted
Partially revert #519 due to performance regression & other issues (#521)
1 parent cf65f39 commit da67a1e

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

test/test_transforms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ def test_random_horizontal_flip(self):
652652
# Checking if RandomHorizontalFlip can be printed as string
653653
transforms.RandomHorizontalFlip().__repr__()
654654

655-
@unittest.skipIf(stats is None, 'scipt.stats is not available')
655+
@unittest.skipIf(stats is None, 'scipy.stats is not available')
656656
def test_normalize(self):
657657
def samples_from_standard_normal(tensor):
658658
p_value = stats.kstest(list(tensor.view(-1)), 'norm', args=(0, 1)).pvalue

torchvision/transforms/functional.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,10 @@ def normalize(tensor, mean, std):
167167
if not _is_tensor_image(tensor):
168168
raise TypeError('tensor is not a torch image.')
169169

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

174175

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

0 commit comments

Comments
 (0)