AttributeError: 'ImportError' object has no attribute 'open' for torchvision.io.VideoReader(video_path, "video")
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 17.9k
- Forks
- 7.3k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 13
Description
🐛 Describe the bug
I know the issue is me not having PyAv installed, but I think the error message is wrong:
reader = torchvision.io.VideoReader(video_path, "video")
Raises:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[10], line 1
----> 1 reader = torchvision.io.VideoReader(video_path, "video")
File ~/miniconda3/envs/thesis/lib/python3.10/site-packages/torchvision/io/video_reader.py:171, in VideoReader.__init__(self, src, stream, num_threads, path)
168 self._c.init_from_memory(src, stream, num_threads)
170 elif self.backend == "pyav":
--> 171 self.container = av.open(src, metadata_errors="ignore")
172 # TODO: load metadata
173 stream_type = stream.split(":")[0]
AttributeError: 'ImportError' object has no attribute 'open'
But
torchvision.io.read_video(video_path)
Raises:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Cell In[12], line 1
----> 1 torchvision.io.read_video(video_path)
File ~/miniconda3/envs/thesis/lib/python3.10/site-packages/torchvision/io/video.py:277, in read_video(filename, start_pts, end_pts, pts_unit, output_format)
275 vframes, aframes, info = _video_opt._read_video(filename, start_pts, end_pts, pts_unit)
276 else:
--> 277 _check_av_available()
279 if end_pts is None:
280 end_pts = float("inf")
File ~/miniconda3/envs/thesis/lib/python3.10/site-packages/torchvision/io/video.py:41, in _check_av_available()
39 def _check_av_available() -> None:
40 if isinstance(av, Exception):
---> 41 raise av
[... skipping hidden 1 frame]
Cell In[12], line 1
----> 1 torchvision.io.read_video(video_path)
File ~/miniconda3/envs/thesis/lib/python3.10/site-packages/torchvision/io/video.py:277, in read_video(filename, start_pts, end_pts, pts_unit, output_format)
275 vframes, aframes, info = _video_opt._read_video(filename, start_pts, end_pts, pts_unit)
276 else:
...
ImportError: PyAV is not installed, and is necessary for the video operations in torchvision.
See https://github.com/mikeboers/PyAV#installation for instructions on how to
install PyAV on your system.
And I think this is the correct error message.
I suppose the VideoReader is missing a _check_av_available() call, before trying to call something on av.
Versions
PyTorch version: 2.0.0.dev20230111
Is debug build: False
CUDA used to build PyTorch: 11.7
ROCM used to build PyTorch: N/A
OS: Ubuntu 22.04.1 LTS (x86_64)
GCC version: (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.35
Python version: 3.10.8 (main, Nov 24 2022, 14:13:03) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.15.0-58-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 11.8.89
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce GTX 1650 SUPER
Nvidia driver version: 520.61.05
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
Versions of relevant libraries:
[pip3] numpy==1.23.5
[pip3] pytorch-lightning==1.7.7
[pip3] torch==2.0.0.dev20230111
[pip3] torchaudio==2.0.0.dev20230111
[pip3] torchinfo==1.7.1
[pip3] torchmetrics==0.10.0
[pip3] torchvision==0.15.0.dev20230111
[conda] blas 1.0 mkl
[conda] mkl 2021.4.0 h06a4308_640
[conda] mkl-service 2.4.0 py310h7f8727e_0
[conda] mkl_fft 1.3.1 py310hd6ae3a3_0
[conda] mkl_random 1.2.2 py310h00e6091_0
[conda] numpy 1.23.5 py310hd5efca6_0
[conda] numpy-base 1.23.5 py310h8e6c178_0
[conda] pytorch 2.0.0.dev20230111 py3.10_cuda11.7_cudnn8.5.0_0 pytorch-nightly
[conda] pytorch-cuda 11.7 h67b0de4_2 pytorch-nightly
[conda] pytorch-lightning 1.7.7 pyhd8ed1ab_0 conda-forge
[conda] pytorch-mutex 1.0 cuda pytorch-nightly
[conda] torchaudio 2.0.0.dev20230111 py310_cu117 pytorch-nightly
[conda] torchinfo 1.7.1 pyhd8ed1ab_0 conda-forge
[conda] torchmetrics 0.10.0 pyhd8ed1ab_0 conda-forge
[conda] torchtriton 2.0.0+0d7e753227 py310 pytorch-nightly
[conda] torchvision 0.15.0.dev20230111 py310_cu117 pytorch-nightly
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading torchvision/io/video_reader.py around VideoReader.init and compare its PyAV handling with _check_av_available() in torchvision/io/video.py. The issue is done when calling VideoReader without PyAV produces the same informative ImportError as read_video instead of an AttributeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- computer-vision
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100