[Reporting Bug] Expected String but got Blob

from torchvision.io import read_image
im = read_image(“nbs/images/grizzly.jpg”)
Traceback (most recent call last):
File “”, line 1, in
File “/Users/germangoldszmidt/mambaforge/lib/python3.9/site-packages/torchvision/io/image.py”, line 245, in read_image
data = read_file(path)
File “/Users/germangoldszmidt/mambaforge/lib/python3.9/site-packages/torchvision/io/image.py”, line 47, in read_file
data = torch.ops.image.read_file(path)
File “/Users/germangoldszmidt/mambaforge/lib/python3.9/site-packages/torch/_ops.py”, line 143, in call
return self._op(*args, **kwargs or {})
RuntimeError: isString()INTERNAL ASSERT FAILED at “/Users/germangoldszmidt/mambaforge/lib/python3.9/site-packages/torch/include/ATen/core/ivalue_inl.h”:2088, please report a bug to PyTorch. Expected String but got Blob
import torch
torch.version
‘1.12.1’

I cannot reproduce the error using torchvision==0.14.1+cu117 and can properly load a random image:

>>> from torchvision.io import read_image
>>> im = read_image("fake.jpeg")
>>> im
tensor([[[200, 202, 207,  ..., 210, 205, 197],
         [208, 207, 209,  ..., 210, 208, 205],
         [213, 210, 208,  ..., 208, 211, 212],
         ...,

Thanks @ptrblck .

I was running torchvision==0.12.0.
Now upgraded to torchvision==0.14.1 and got the following error:

from torchvision.io import read_image
/Users/germangoldszmidt/mambaforge/lib/python3.9/site-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension: dlopen(/Users/germangoldszmidt/mambaforge/lib/python3.9/site-packages/torchvision/image.so, 0x0006): Symbol not found: __ZN2at4_ops19empty_memory_format4callEN3c108ArrayRefINS2_6SymIntEEENS2_8optionalINS2_10ScalarTypeEEENS6_INS2_6LayoutEEENS6_INS2_6DeviceEEENS6_IbEENS6_INS2_12MemoryFormatEEE
Referenced from: /Users/germangoldszmidt/mambaforge/lib/python3.9/site-packages/torchvision/image.so
Expected in: <2323D885-BE27-397B-B74E-2A78902E48D2> /Users/germangoldszmidt/mambaforge/lib/python3.9/site-packages/torch/lib/libtorch_cpu.dylib
warn(f"Failed to load image Python extension: {e}")

pip list | grep torch
torch 1.13.1
torcheval 0.0.5
torcheval-nightly 2022.12.20
torchtnt 0.0.4
torchvision 0.14.1

I’m not familiar with the Mac builds, but based on the error message it seems the torchvision.io backend has trouble loading expected symbols from the corresponding dylib so you might want to create an issue here.

Thanks!
Above was with the python interpreter…
Now tried it on Jupyter and got the following:

read_image(“images/grizzly.jpg”)


RuntimeError Traceback (most recent call last)
File ~/mambaforge/lib/python3.9/site-packages/torch/_ops.py:198, in _OpNamespace.getattr(self, op_name)
197 try:
→ 198 op, overload_names = torch._C._jit_get_operation(qualified_op_name)
199 except RuntimeError as e:
200 # Turn this into AttributeError so getattr(obj, key, default)
201 # works (this is called by TorchScript with origin)

RuntimeError: No such operator image::read_file

The above exception was the direct cause of the following exception:

AttributeError Traceback (most recent call last)
Cell In [20], line 1
----> 1 read_image(“images/grizzly.jpg”)

File ~/mambaforge/lib/python3.9/site-packages/torchvision/io/image.py:253, in read_image(path, mode)
251 if not torch.jit.is_scripting() and not torch.jit.is_tracing():
252 _log_api_usage_once(read_image)
→ 253 data = read_file(path)
254 return decode_image(data, mode)

File ~/mambaforge/lib/python3.9/site-packages/torchvision/io/image.py:47, in read_file(path)
45 if not torch.jit.is_scripting() and not torch.jit.is_tracing():
46 _log_api_usage_once(read_file)
—> 47 data = torch.ops.image.read_file(path)
48 return data

File ~/mambaforge/lib/python3.9/site-packages/torch/_ops.py:202, in _OpNamespace.getattr(self, op_name)
198 op, overload_names = torch._C._jit_get_operation(qualified_op_name)
199 except RuntimeError as e:
200 # Turn this into AttributeError so getattr(obj, key, default)
201 # works (this is called by TorchScript with origin)
→ 202 raise AttributeError(f"‘_OpNamespace’ object has no attribute ‘{op_name}’") from e
204 # let the script frontend know that op is identical to the builtin op
205 # with qualified_op_name
206 torch.jit._builtins._register_builtin(op, qualified_op_name)

AttributeError: ‘_OpNamespace’ object has no attribute ‘read_file’

Both errors point to the lack of the torchvision.io.read_image method on Mac and I don’t know if this is expected or not. If I’m not mistaken, the io namespace depends on libpng and/or libjpeg, which might be missing on your system, not packaged into the Mac pip wheels (but maybe into the conda binaries), or just not supported. Again, take this with a grain of salt as I’ve never used Mac and don’t know its supoport when it comes to the binary builds.