pil_to_tensor() raises a "NumPy array is not writeable" warning
See original GitHub issue🐛 Describe the bug
Steps to reproduce:
import torchvision
from PIL import Image
img = Image.open("test/assets/encode_jpeg/grace_hopper_517x606.jpg")
torchvision.transforms.functional.pil_to_tensor(img)
Raises:
./vision/torchvision/transforms/functional.py:177: UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at ./torch/csrc/utils/tensor_numpy.cpp:187.)
img = torch.as_tensor(np.asarray(pic))
There are a few options including copying the data, suppressing the warnings etc (see discussion below). The person who picks this up can comment on this issue which solution they are going for.
Versions
Latest main (f749835057ec16886f16d5533928e269860f1760)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:16 (15 by maintainers)
Top Results From Across the Web
UserWarning: The given NumPy array is not writeable
This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to...
Read more >The given NumPy array is not writeable, and PyTorch does not ...
Why i'm getting the message "UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors."?
Read more >Warning "The given NumPy array is not writeable" raised by ...
Due to a possible bug of torchvision.datasets.MNIST, the first time this downloads its data the following UserWarning is raised: The given ...
Read more >the given numpy array is not writeable, and pytorch ... - You.com
Sidenote : the warning about writable numpy arrays is completely unrelated, it just means that pytorch will possibly override the "non-writable" data of...
Read more >[Torchvision] Image Random Transforming Baseline - Kaggle
/opt/conda/lib/python3.7/site-packages/ipykernel_launcher.py:7: UserWarning: The given NumPy array is not writeable, and PyTorch does not support ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As discussed offline with @datumbox I am going to proceed with the copy option for now.
Sounds good to me. You can implement it like this if you want. Please make sure you pass
True
when you update the code inside thereferences
folder because there we want to avoid the warning. 😃