Skip to content

Commit

Permalink
pil_to_tensor accimage backend return uint8 (pytorch#3109)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fmassa authored and vfdev-5 committed Dec 4, 2020
1 parent f1cd26d commit 92f966c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion torchvision/transforms/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 92f966c

Please sign in to comment.