-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement tensor handling for ToTensor() #6780
Comments
Hey @SalmanHabeeb. That is a good proposal and we actually already implemented this in our prototype namespace:
However, vision/torchvision/prototype/transforms/_deprecated.py Lines 21 to 24 in 149edda
Thus, I don't want to introduce any new features on the current stable transform. While the prototype transform also takes numpy images, unfortunately there is no stable transform except for That being said, if you have PIL image and tensors, there is the stable tranform vision/torchvision/transforms/transforms.py Line 141 in 149edda
I would be happy to review a PR that makes this a no-op for tensors. |
@pmeier I have implemented your suggestions in a fork at Yet to make pull request for the same. Do I need to make any new unit tests? Or is this enough? |
@SalmanHabeeb as Philip said, at this point we don't want to update the ToTensor any further. This is because the implementation does too many things, for example rescaling the input as opposed to just converting them to tensors. This is why it's an idiom we try to phase out on the new API. I am going to close the issue as the proposal doesn't align with our plans for the new Transforms API. If you would like to contribute to the project, we have several potential issues we would love the help of the community. See here: |
@datumbox As suggested by me, the patch was made to
Given that we have the same tensor no-op behavior in the new I acknowledge that going by the name, passing tensors to @SalmanHabeeb Please wait with further patches until we have aligned if we want this change or not. As for your question: yes, we also need tests for the new behavior if we decide we want it. Plus, your current change is wrong, since it would return nothing in case we encounter a tensor. Instead of |
@pmeier Thanks for the comments. This is quite nuanced. I'll write my concerns here in more detail (mentioning things you already know) so that my position is clearer. The The operation quoted at My main concern about extending
For the above reasons, my recommendation is not to add any further magic features in |
🚀 The feature
The ToTensor() function of torchvision.transforms must be able to handle torch Tensors. If it gets a tensor, it must return the same tensor without modification
Motivation, pitch
The function ToTensor can take a NumPy array as input. But if a torch tensor is passed to it, the function raises an error. It will be better if the function can take PyTorch tensors too without raising error.
Alternatives
No response
Additional context
No response
cc @vfdev-5 @datumbox
The text was updated successfully, but these errors were encountered: