From 8863226519eb659a68b22e24b3fb411e49a6c86b Mon Sep 17 00:00:00 2001 From: Holger Kohr Date: Sat, 26 May 2018 17:06:16 +0200 Subject: [PATCH 1/2] Fix PIL link --- torchvision/transforms/functional.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torchvision/transforms/functional.py b/torchvision/transforms/functional.py index ea939726f67..0f2c8481f22 100644 --- a/torchvision/transforms/functional.py +++ b/torchvision/transforms/functional.py @@ -94,7 +94,7 @@ def to_pil_image(pic, mode=None): pic (Tensor or numpy.ndarray): Image to be converted to PIL Image. mode (`PIL.Image mode`_): color space and pixel depth of input data (optional). - .. _PIL.Image mode: http://pillow.readthedocs.io/en/3.4.x/handbook/concepts.html#modes + .. _PIL.Image mode: https://pillow.readthedocs.io/en/latest/handbook/concepts.html#concept-modes Returns: PIL Image: Image converted to PIL Image. From 0bbbf34f06811e9bb155afe28c453f7a6e6c3cd7 Mon Sep 17 00:00:00 2001 From: Holger Kohr Date: Sat, 26 May 2018 17:07:10 +0200 Subject: [PATCH 2/2] Make normalize more efficient --- torchvision/transforms/functional.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/torchvision/transforms/functional.py b/torchvision/transforms/functional.py index 0f2c8481f22..74f7234ad65 100644 --- a/torchvision/transforms/functional.py +++ b/torchvision/transforms/functional.py @@ -163,10 +163,10 @@ def normalize(tensor, mean, std): """ if not _is_tensor_image(tensor): raise TypeError('tensor is not a torch image.') - # TODO: make efficient - for t, m, s in zip(tensor, mean, std): - t.sub_(m).div_(s) - return tensor + + 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) def resize(img, size, interpolation=Image.BILINEAR):