Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pil_to_tensor to functionals (#2092)
* Adds as_tensor to functional.py Similar functionality to to_tensor without the default conversion to float and division by 255. Also adds support for Image mode 'L'. * Adds tests to AsTensor() Adds tests to AsTensor and removes the conversion to float and division by 255. * Adds AsTensor to transforms.py Calls the as_tensor function in functionals and adds the function AsTensor as callable from transforms. * Removes the pic.mode == 'L' This was handled by the else condition previously so I'll remove it. * Fix Lint issue Adds two line breaks between functions to fix lint issue * Replace from_numpy with as_tensor Removes the extra if conditionals and replaces from_numpy with as_tensor. * Renames as_tensor to pil_to_tensor Renames the function as_tensor to pil_to_tensor and narrows the scope of the function. At the same time also creates a flag that defaults to True for swapping to the channels first format. * Renames AsTensor to PILToImage Renames the function AsTensor to PILToImage and modifies the description. Adds the swap_to_channelsfirst boolean variable to indicate if the user wishes to change the shape of the input. * Add the __init__ function to PILToTensor Add the __init__ function to PILToTensor since it contains the swap_to_channelsfirst parameter now. * fix lint issue remove trailing white space * Fix the tests Reflects the name change to PILToTensor and the parameter to the function as well as the new narrowed scope that the function only accepts PIL images. * fix tests Instead of undoing the transpose just create a new tensor and test that one. * Add the view back Add img.view(pic.size[1], pic.size[0], len(pic.getbands())) back to outside the if condition. * fix test fix conversion from torch tensor to PIL back to torch tensor. * fix lint issues * fix lint remove trailing white space * Fixed the channel swapping tensor test Torch tranpose operates differently than numpy transpose. Changed operation to permute. * Add mode='F' Add mode information when converting to PIL Image from Float Tensor. * Added inline comments to follow shape changes * ToPILImage converts FloatTensors to uint8 * Remove testing not swapping * Removes the swap_channelsfirst parameter Makes the channel swapping the default behavior. * Remove the swap_channelsfirst argument Remove the swap_channelsfirst argument and makes the swapping the default functionality.
- Loading branch information