Skip to content

Unable to read PNG image into tensor #6374

@ipoeyke

Description

@ipoeyke

🐛 Describe the bug

Hi, I'm trying to read a PNG image into a PyTorch tensor using torchvision.io.read_image. Simplified code as follows:

import os
from torchvision.io import read_image, ImageReadMode
img_path = os.path.join("sample-images", "test.png")
img = read_image(img_path, ImageReadMode.RGB)

I observe the following error:

Input In [6], in <cell line: 2>()
      1 img_path = os.path.join("sample-images", "test.png")
----> 2 img = read_image(img_path, ImageReadMode.RGB)

File ~/opt/miniconda3/envs/dl-torch/lib/python3.9/site-packages/torchvision/io/image.py:245, in read_image(path, mode)
    243 if not torch.jit.is_scripting() and not torch.jit.is_tracing():
    244     _log_api_usage_once(read_image)
--> 245 data = read_file(path)
    246 return decode_image(data, mode)

File ~/opt/miniconda3/envs/dl-torch/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 ~/opt/miniconda3/envs/dl-torch/lib/python3.9/site-packages/torch/_ops.py:143, in OpOverloadPacket.__call__(self, *args, **kwargs)
    138 def __call__(self, *args, **kwargs):
    139     # overloading __call__ to ensure torch.ops.foo.bar()
    140     # is still callable from JIT
    141     # We save the function ptr as the `op` attribute on
    142     # OpOverloadPacket to access it here.
--> 143     return self._op(*args, **kwargs or {})

RuntimeError: isString()INTERNAL ASSERT FAILED at "/Users/malfet/miniconda3/envs/whl-py39-torch-1.11.0/lib/python3.9/site-packages/torch/include/ATen/core/ivalue_inl.h":2088, please report a bug to PyTorch. Expected String but got Blob

The error occurs regardless of the value of the ImageReadMode arg. Another observation is that read_image works with no issues on an Intel i5 laptop, but when bringing the code over to an Apple Silicon (M2) machine, the error occurs every time. Not sure what is happening, I'm a novice at PyTorch.

Thank you!

Versions

PyTorch version: 1.12.0
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: macOS 12.5 (arm64)
GCC version: Could not collect
Clang version: 13.1.6 (clang-1316.0.21.2.5)
CMake version: Could not collect
Libc version: N/A

Python version: 3.9.12 (main, Jun 1 2022, 06:34:44) [Clang 12.0.0 ] (64-bit runtime)
Python platform: macOS-12.5-arm64-arm-64bit
Is CUDA available: False
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] numpy==1.23.1
[pip3] torch==1.12.0
[pip3] torchvision==0.12.0
[conda] numpy 1.23.1 pypi_0 pypi
[conda] torch 1.12.0 pypi_0 pypi
[conda] torchvision 0.12.0 pypi_0 pypi

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions