pytorch / vision

Datasets, Transforms and Models specific to Computer Vision
https://pytorch.org/vision
BSD 3-Clause "New" or "Revised" License
16.33k stars 6.97k forks source link

torchvision.io.decode_image can not be used as document #8698

Open malfet opened 1 month ago

malfet commented 1 month ago

šŸ› Describe the bug

By looking at https://pytorch.org/vision/0.20/generated/torchvision.io.decode_image.html it feels like one should be able to do something like

from torchvision.io import decode_image
decode_image("foo.png")

but it fails with

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/nshulga/miniconda3/envs/py-311/lib/python3.11/site-packages/torchvision/io/image.py", line 269, in decode_image
    output = torch.ops.image.decode_image(input, mode.value, apply_exif_orientation)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nshulga/miniconda3/envs/py-311/lib/python3.11/site-packages/torch/_ops.py", line 1061, in __call__
    return self_._op(*args, **(kwargs or {}))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: image::decode_image() Expected a value of type 'Tensor' for argument 'data' but instead found type 'str'.
Position: 0
Value: 'foo.png'
Declaration: image::decode_image(Tensor data, int mode, bool apply_exif_orientation=False) -> Tensor
Cast error details: Unable to cast foo.png to Tensor

But read_image works as expeted:

from torchvision.io import read_image
read_image("foo.png")

Versions

0.19.1

NicolasHug commented 1 month ago

Hi @malfet ,

This is a new feature introduced in 0.20. Can you try to update torchvision and let me know if there's any issue?