[Reporting Bug] Expected String but got Blob

German_Goldszmidt: <blockquote>
<blockquote>
<blockquote>
<p>from <a href="http://torchvision.io" rel="noopener nofollow ugc">torchvision.io</a> import read_image<br>
im = read_image(“nbs/images/grizzly.jpg”)<br>
Traceback (most recent call last):<br>
File “”, line 1, in <br>
File “/Users/germangoldszmidt/mambaforge/lib/python3.9/site-packages/torchvision/io/image.py”, line 245, in read_image<br>
data = read_file(path)<br>
File “/Users/germangoldszmidt/mambaforge/lib/python3.9/site-packages/torchvision/io/image.py”, line 47, in read_file<br>
data = torch.ops.image.read_file(path)<br>
File “/Users/germangoldszmidt/mambaforge/lib/python3.9/site-packages/torch/_ops.py”, line 143, in <strong>call</strong><br>
return self._op(*args, **kwargs or {})<br>
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<br>
import torch<br>
torch.<strong>version</strong><br>
‘1.12.1’</p>
</blockquote>
</blockquote>
</blockquote>

ptrblck: <p>I cannot reproduce the error using <code>torchvision==0.14.1+cu117</code> and can properly load a random image:</p>
<pre><code class="lang-python">&gt;&gt;&gt; from torchvision.io import read_image
&gt;&gt;&gt; im = read_image("fake.jpeg")
&gt;&gt;&gt; im
tensor([[[200, 202, 207,  ..., 210, 205, 197],
         [208, 207, 209,  ..., 210, 208, 205],
         [213, 210, 208,  ..., 208, 211, 212],
         ...,
</code></pre>

German_Goldszmidt: <p>Thanks <a class="mention" href="/u/ptrblck">@ptrblck</a> .</p>
<p>I was running torchvision==0.12.0.<br>
Now upgraded to torchvision==0.14.1 and got the following error:</p>
<blockquote>
<blockquote>
<blockquote>
<p>from <a href="http://torchvision.io" rel="noopener nofollow ugc">torchvision.io</a> import read_image<br>
/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<br>
Referenced from:  /Users/germangoldszmidt/mambaforge/lib/python3.9/site-packages/torchvision/image.so<br>
Expected in:     &lt;2323D885-BE27-397B-B74E-2A78902E48D2&gt; /Users/germangoldszmidt/mambaforge/lib/python3.9/site-packages/torch/lib/libtorch_cpu.dylib<br>
warn(f"Failed to load image Python extension: {e}")</p>
</blockquote>
</blockquote>
</blockquote>
<p>pip list | grep torch<br>
torch                         1.13.1<br>
torcheval                     0.0.5<br>
torcheval-nightly             2022.12.20<br>
torchtnt                      0.0.4<br>
torchvision                   0.14.1</p>

ptrblck: <p>I’m not familiar with the Mac builds, but based on the error message it seems the <code>torchvision.io</code> backend has trouble loading expected symbols from the corresponding <code>dylib</code> so you might want to create an issue <a href="https://github.com/pytorch/vision/issues">here</a>.</p>

German_Goldszmidt: <p>Thanks!<br>
Above was with the python interpreter…<br>
Now tried it on Jupyter and got the following:</p>
<p>read_image(“images/grizzly.jpg”)</p>
<hr>
<p>RuntimeError                              Traceback (most recent call last)<br>
File ~/mambaforge/lib/python3.9/site-packages/torch/_ops.py:198, in _OpNamespace.<strong>getattr</strong>(self, op_name)<br>
197 try:<br>
 → 198     op, overload_names = torch._C._jit_get_operation(qualified_op_name)<br>
199 except RuntimeError as e:<br>
200     # Turn this into AttributeError so getattr(obj, key, default)<br>
201     # works (this is called by TorchScript with <strong>origin</strong>)</p>
<p>RuntimeError: No such operator image::read_file</p>
<p>The above exception was the direct cause of the following exception:</p>
<p>AttributeError                            Traceback (most recent call last)<br>
Cell In [20], line 1<br>
----&gt; 1 read_image(“images/grizzly.jpg”)</p>
<p>File ~/mambaforge/lib/python3.9/site-packages/torchvision/io/image.py:253, in read_image(path, mode)<br>
251 if not torch.jit.is_scripting() and not torch.jit.is_tracing():<br>
252     _log_api_usage_once(read_image)<br>
 → 253 data = read_file(path)<br>
254 return decode_image(data, mode)</p>
<p>File ~/mambaforge/lib/python3.9/site-packages/torchvision/io/image.py:47, in read_file(path)<br>
45 if not torch.jit.is_scripting() and not torch.jit.is_tracing():<br>
46     _log_api_usage_once(read_file)<br>
—&gt; 47 data = torch.ops.image.read_file(path)<br>
48 return data</p>
<p>File ~/mambaforge/lib/python3.9/site-packages/torch/_ops.py:202, in _OpNamespace.<strong>getattr</strong>(self, op_name)<br>
198     op, overload_names = torch._C._jit_get_operation(qualified_op_name)<br>
199 except RuntimeError as e:<br>
200     # Turn this into AttributeError so getattr(obj, key, default)<br>
201     # works (this is called by TorchScript with <strong>origin</strong>)<br>
 → 202     raise AttributeError(f"‘_OpNamespace’ object has no attribute ‘{op_name}’") from e<br>
204 # let the script frontend know that op is identical to the builtin op<br>
205 # with qualified_op_name<br>
206 torch.jit._builtins._register_builtin(op, qualified_op_name)</p>
<p>AttributeError: ‘_OpNamespace’ object has no attribute ‘read_file’</p>

ptrblck: <p>Both errors point to the lack of the <code>torchvision.io.read_image</code> method on Mac and I don’t know if this is expected or not. If I’m not mistaken, the <code>io</code> namespace depends on <code>libpng</code> and/or <code>libjpeg</code>, 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.</p>