From 1fcce8e5ea19fae783e52ee3d25456f548bb96ea Mon Sep 17 00:00:00 2001 From: Francisco Massa Date: Thu, 3 Dec 2020 19:37:44 +0100 Subject: [PATCH] pil_to_tensor accimage backend return uint8 accimage always stores images as uint8, so let's be compatible with the internal representation. Tests were failing without this as it would return a float32 image normalized between 0-1 --- torchvision/transforms/functional.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/torchvision/transforms/functional.py b/torchvision/transforms/functional.py index 72baf021f9d..7ba161ba377 100644 --- a/torchvision/transforms/functional.py +++ b/torchvision/transforms/functional.py @@ -155,7 +155,8 @@ def pil_to_tensor(pic): raise TypeError('pic should be PIL Image. Got {}'.format(type(pic))) if accimage is not None and isinstance(pic, accimage.Image): - nppic = np.zeros([pic.channels, pic.height, pic.width], dtype=np.float32) + # accimage format is always uint8 internally, so always return uint8 here + nppic = np.zeros([pic.channels, pic.height, pic.width], dtype=np.uint8) pic.copyto(nppic) return torch.as_tensor(nppic)