-
Notifications
You must be signed in to change notification settings - Fork 7.1k
..functional.rotate() arguments broke with 0.5 update #1759
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
Comments
Thanks for the report. Indeed vision/torchvision/transforms/functional.py Lines 726 to 729 in add2ecc
causes the error. I will investigate this tomorrow and send a fix. For your next bug report, please post the full stack trace. That makes it easier for us to investigate where the error might originate from. |
Hi, This error happens because you have an old version of Pillow. If you update pillow, this should work. @pmeier we should add a compatibility fix for older versions of PIL, and add a test (which was missing before) |
FYI, |
I don't think this is the issue here. The problem is that we always convert a scalar into a tuple of 3. This works fine for RGB images but fails for greyscale images like in the example given. Actually this will fail for every image with a number of bands / channels different from 3. From the official documentation:
The documentation of
Apart from that I agree that we should add a compatibility fix for @Jarei002 For a quick fix add Img=torch.rand(1,32,32)
Img_PIL=torchvision.transforms.functional.to_pil_image(Img)
Img_PIL_Rot=torchvision.transforms.functional.rotate(Img_PIL, 5, fill=(0,))
Img=torchvision.transforms.functional.to_tensor(Img_PIL_Rot)*255 |
Okay, here is the complete stack trace:
The current PIL version is 7.0.0.
As seen from the stack trace, Thanks for the quick responses so far. |
You missed a comma there. It should be |
Astonishing that things work when they are done right. Somehow the comma moved outside the parantheses, works now. Thanks again. As a general question, should I close this issue now, or is this done by someone else at later stages once the actual fix is implemented? |
You don't need to close it manually. If the PR I send gets merged, this issue will be closed automatically. Until then its good to be open so others know that this is still worked on. |
I still get the error with
|
@IvonaTau Could you please post your complete code? A quick test by me run without any error import numpy as np
from PIL import Image
from torchvision import transforms
img = np.zeros((100, 100), dtype=np.uint8)
img = Image.fromarray(img, mode="L")
transform = transforms.RandomRotation(10, fill=(0,))
transform(img) |
I had the same problem with torchvision v0.5.0 & PIL v7.0.0. Downgrading to torchvision 0.4.0 & PIL v6.2.0 solved the problem for me. |
This is a bug in If you are bound to If you can use an older version, I suggest you downgrade to Alternatively, if you are not bound to a stable version, you can use the |
I get this issue as well with torchvision 0.5.0 and Pillow 7.1.1 as well as 7.0.0. Complete trace below:
|
I've outlined possible workarounds in that comment. If they do not work for you, please open a new bug report issue. |
I was surprised a fix has been pushed for so long but no updates to torch vision stable have been put out yet. |
I think a new release is just around the corner, but I have no precise information about that. |
Next release is ready and will be made available early next week |
is totally ok. but I change the data_cube axis:
it runs error,
add it really strange. |
@Interesting6 I believe your image doesn't have the right number of channels, but without further information it's hard to say more |
data_cube is a numpy ndarray with dimensions [c=4, h=906, w=463] read from segyio. |
@Interesting6 could you please open a new issue with the torchvision version that you are using, and a self-contained example reproducing the issue? |
Thanks, @pmeier, this works. But I don't understand why. |
If you already have |
@pmeier Thanks for the quick reply. ValueError: The number of elements in 'fill' does not match the number of bands of the image (1 != 3) Not sure if this helps, but I used this tranform # I am randomly choosing rotation value
transforms.RandomRotation((rot, rot), fill=(0, )), P.S. Let me know if I should open a new issue with the exact stack trace :) |
The error message is telling you what the problem is: by using |
Awesome @pmeier! I am handling multiple datasets, both grayscaled and RGB. I think, in my case, this might do the trick: try:
# for RGB images
transforms.RandomRotation((rot, rot))
except:
# for grayscaled
transforms.RandomRotation((rot, rot), fill=(0, )), Do correct me if I am wrong. Thanks for your help! |
Not sure what you are trying to do:
|
Thanks @pmeier
Sorry, my bad.
Got it. Thanks :) Just one last question. If |
No, it shouldn't. If it does, this is a bug and you might file an issue so we can investigate. |
Hey, I just did a fresh install of Pytorch and torchvision on a clean ubuntu 18.04 os.
When I run my code, I get the following Error message
TypeError: function takes exactly 1 argument (3 given)
even though i did not change my code.
torchvision.__version__
= 0.5.0pytorch.__version__
=1.4.0Running the same code on an older machine (0.4.2 and 1.3.1 respectively) works without an issue, I guess it has something to do with the new addition of the fill-colour of the 0.5 update.
How to reproduce:
Expeceted result:
rotated Image
Result:
The text was updated successfully, but these errors were encountered: