Unverified Commit 85b8fe6f authored by Joao Gomes's avatar Joao Gomes Committed by GitHub
Browse files

Explicitly copying array in pil_to_tensor (#4566)



* mExplicitly copying array in pil_to_tensor

* Update torchvision/transforms/functional.py
Co-authored-by: default avatarNicolas Hug <contact@nicolas-hug.com>

* Adding comments regarding implicit array deep copy in PILToTensor transform

* Update torchvision/transforms/transforms.py
Co-authored-by: default avatarNicolas Hug <contact@nicolas-hug.com>
Co-authored-by: default avatarNicolas Hug <contact@nicolas-hug.com>
Co-authored-by: default avatarVasilis Vryniotis <datumbox@users.noreply.github.com>
parent dbb76791
...@@ -156,6 +156,10 @@ def pil_to_tensor(pic): ...@@ -156,6 +156,10 @@ def pil_to_tensor(pic):
See :class:`~torchvision.transforms.PILToTensor` for more details. See :class:`~torchvision.transforms.PILToTensor` for more details.
.. note::
A deep copy of the underlying array is performed.
Args: Args:
pic (PIL Image): Image to be converted to tensor. pic (PIL Image): Image to be converted to tensor.
...@@ -172,7 +176,7 @@ def pil_to_tensor(pic): ...@@ -172,7 +176,7 @@ def pil_to_tensor(pic):
return torch.as_tensor(nppic) return torch.as_tensor(nppic)
# handle PIL Image # handle PIL Image
img = torch.as_tensor(np.asarray(pic)) img = torch.as_tensor(np.array(pic, copy=True))
img = img.view(pic.size[1], pic.size[0], len(pic.getbands())) img = img.view(pic.size[1], pic.size[0], len(pic.getbands()))
# put it from HWC to CHW format # put it from HWC to CHW format
img = img.permute((2, 0, 1)) img = img.permute((2, 0, 1))
......
...@@ -142,6 +142,10 @@ class PILToTensor: ...@@ -142,6 +142,10 @@ class PILToTensor:
def __call__(self, pic): def __call__(self, pic):
""" """
.. note::
A deep copy of the underlying array is performed.
Args: Args:
pic (PIL Image): Image to be converted to tensor. pic (PIL Image): Image to be converted to tensor.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment