{"action":"created","issue":{"url":"https://api.github.com/repos/pytorch/vision/issues/448","repository_url":"https://api.github.com/repos/pytorch/vision","labels_url":"https://api.github.com/repos/pytorch/vision/issues/448/labels{/name}","comments_url":"https://api.github.com/repos/pytorch/vision/issues/448/comments","events_url":"https://api.github.com/repos/pytorch/vision/issues/448/events","html_url":"https://github.com/pytorch/vision/issues/448","id":306493505,"node_id":"MDU6SXNzdWUzMDY0OTM1MDU=","number":448,"title":"Bug: torchvision/transforms/functional/to_pil_image always converts 1-channel (gray) FloatTensor images to 8-bit unsigned int","user":{"login":"mathski","id":3429621,"node_id":"MDQ6VXNlcjM0Mjk2MjE=","avatar_url":"https://avatars0.githubusercontent.com/u/3429621?v=4","gravatar_id":"","url":"https://api.github.com/users/mathski","html_url":"https://github.com/mathski","followers_url":"https://api.github.com/users/mathski/followers","following_url":"https://api.github.com/users/mathski/following{/other_user}","gists_url":"https://api.github.com/users/mathski/gists{/gist_id}","starred_url":"https://api.github.com/users/mathski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mathski/subscriptions","organizations_url":"https://api.github.com/users/mathski/orgs","repos_url":"https://api.github.com/users/mathski/repos","events_url":"https://api.github.com/users/mathski/events{/privacy}","received_events_url":"https://api.github.com/users/mathski/received_events","type":"User","site_admin":false},"labels":[{"id":478619882,"node_id":"MDU6TGFiZWw0Nzg2MTk4ODI=","url":"https://api.github.com/repos/pytorch/vision/labels/bug","name":"bug","color":"ee0701","default":true},{"id":478619885,"node_id":"MDU6TGFiZWw0Nzg2MTk4ODU=","url":"https://api.github.com/repos/pytorch/vision/labels/help%20wanted","name":"help wanted","color":"128A0C","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-03-19T14:46:25Z","updated_at":"2018-09-20T21:44:36Z","closed_at":null,"author_association":"NONE","body":"- OS: Ubuntu 16.04.4 LTS x64\r\n- PyTorch version: 0.3.0\r\n- Torchvision version: 0.2.0\r\n- How you installed PyTorch (conda, pip, source): conda\r\n- Python version: 3\r\n- CUDA/cuDNN version: 8.0\r\n- GPU models and configuration: Titan X (Maxwell)\r\n\r\nERROR:\r\n**ValueError: Incorrect mode (<class 'float'>) supplied for input type <class 'numpy.dtype'>. Should be L**\r\n\r\nThe *torchvision* transform **ToPILImage(mode=float)** will always break for input of type *torch.FloatTensor*\r\n**ToPILImage()** uses the internal function **to_pil_image** found in *torchvision/transforms/functional.py*\r\n\r\nIn *https://github.com/pytorch/vision/blob/master/torchvision/transforms/functional.py*:\r\nLine 104 checks if the input is of type *torch.FloatTensor*\r\nIf so, line 105 scales the input by 255, but then converts it to **byte**\r\nLines 113-127 check if the user-specified mode is the expected mode, and throws an error if not.\r\nThe expected mode is assigned by **npimg.dtype**, which return **np.uint8** if line 105 is executed \r\n\r\nI believe the bug can be fixed by changing line 105 from:\r\n**pic = pic.mul(255).byte()**\r\n-to-\r\n**pic = pic.mul(255)**\r\n\r\n**Test script:**\r\nimport torch\r\nfrom torchvision import transforms\r\na = torch.FloatTensor(1,64,64)\r\ntform = transforms.Compose([transforms.ToPILImage(mode='F')])\r\nb = tform(a)\r\n\r\nPlease let me know if I am in error. \r\nThank you.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/pytorch/vision/issues/comments/423343782","html_url":"https://github.com/pytorch/vision/issues/448#issuecomment-423343782","issue_url":"https://api.github.com/repos/pytorch/vision/issues/448","id":423343782,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMzM0Mzc4Mg==","user":{"login":"mathski","id":3429621,"node_id":"MDQ6VXNlcjM0Mjk2MjE=","avatar_url":"https://avatars0.githubusercontent.com/u/3429621?v=4","gravatar_id":"","url":"https://api.github.com/users/mathski","html_url":"https://github.com/mathski","followers_url":"https://api.github.com/users/mathski/followers","following_url":"https://api.github.com/users/mathski/following{/other_user}","gists_url":"https://api.github.com/users/mathski/gists{/gist_id}","starred_url":"https://api.github.com/users/mathski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mathski/subscriptions","organizations_url":"https://api.github.com/users/mathski/orgs","repos_url":"https://api.github.com/users/mathski/repos","events_url":"https://api.github.com/users/mathski/events{/privacy}","received_events_url":"https://api.github.com/users/mathski/received_events","type":"User","site_admin":false},"created_at":"2018-09-20T21:44:36Z","updated_at":"2018-09-20T21:44:36Z","author_association":"NONE","body":"I'd be interested to see this. \r\nAs you suggest, I imagine an `Image` class would be most useful for those looking seeking flexibility in range and data type for image processing.\r\n\r\nPlease let me know if there is anything I can contribute here. \r\nThanks."}}
{"actor":{"display_login":"mathski"}}