Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot import video_reader #2163

Closed
surisdi opened this issue Apr 29, 2020 · 11 comments 路 Fixed by #2183
Closed

Cannot import video_reader #2163

surisdi opened this issue Apr 29, 2020 · 11 comments 路 Fixed by #2183

Comments

@surisdi
Copy link

surisdi commented Apr 29, 2020

馃悰 Bug

I cannot import video_reader (io._HAS_VIDEO_OPT is False).

When torchvision.io is imported, and torchvision/io/_video_opt.py is executed, there is a OSError when the library video_reader is imported. The library is found properly.

Specifically, the OSError is caused in this line: torch.ops.load_library(ext_specs.origin), and it is:

[...]/site-packages/torchvision-0.7.0a0+f9ef235-py3.7-linux-x86_64.egg/torchvision/video_reader.so: undefined symbol: _ZTIN6ffmpeg6StreamE

I installed torchvision from source, and the versions of the libraries are the following:

ffmpeg: 4.2.2
torchvision: 0.7.0a0+f9ef235
torch: 1.5.0

What do you think the problem could be? Thanks!

@mthrok
Copy link
Contributor

mthrok commented Apr 29, 2020

Hi @surisdi

To investigate this, could you provide the followings?

  1. The result of python -m torch.utils.collect_env
  2. Stack trace when you get the error.
  3. Complete minimal example code.

Also, torchvision in master branch is tested against nightly build of Torch. You may want to try that.

@fmassa
Copy link
Member

fmassa commented Apr 30, 2020

Hi,

Just to complement @mthrok questions, are you compiling torchvision in the same machine as the one you are using to run it? My impression is that you might have compiled using one system configuration, but are importing using another. Can you double-check?

@surisdi
Copy link
Author

surisdi commented Apr 30, 2020

Hi,

I installed Torch using the nightly build. I also re-installed all the libraries in the same machine. Now, the problem is slightly different, as it does not detect the "video_reader" package.

The folder structure under [/path/to/environment]/lib/python3.8/site-packages/torchvision contains /csrc/cpu/video_reader/. But this video_reader folder is not detected when checking for _HAS_VIDEO_OPT in torchvision/io/_video_opt.py. This is, the ext_specs variable in video_reader.py is None.

In _video_opt.py, the lib_dir is [/path/to/environment]/lib/python3.8/site-packages/torchvision/io/..

The result of python -m torch.utils.collect_env is the following:

Collecting environment information...
PyTorch version: 1.6.0.dev20200430
Is debug build: No
CUDA used to build PyTorch: 10.2

OS: Ubuntu 18.04.4 LTS
GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
CMake version: version 3.10.2

Python version: 3.8
Is CUDA available: Yes
CUDA runtime version: 10.2.89
GPU models and configuration: 
GPU 0: GeForce RTX 2080 Ti
GPU 1: GeForce RTX 2080 Ti
GPU 2: GeForce RTX 2080 Ti
GPU 3: GeForce RTX 2080 Ti
GPU 4: GeForce RTX 2080 Ti
GPU 5: GeForce RTX 2080 Ti
GPU 6: GeForce RTX 2080 Ti
GPU 7: GeForce RTX 2080 Ti

Nvidia driver version: 440.33.01
cuDNN version: /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn.so.7

Versions of relevant libraries:
[pip3] numpy==1.18.2
[pip3] numpydoc==0.9.2
[conda] blas                      1.0                         mkl  
[conda] cudatoolkit               10.2.89              hfd86e86_1  
[conda] mkl                       2020.0                      166  
[conda] mkl-service               2.3.0            py38he904b0f_0  
[conda] mkl_fft                   1.0.15           py38ha843d7b_0  
[conda] mkl_random                1.1.0            py38h962f231_0  
[conda] numpy                     1.18.1           py38h4f9e942_0  
[conda] numpy-base                1.18.1           py38hde5b4d6_1  
[conda] pytorch                   1.6.0.dev20200430 py3.8_cuda10.2.89_cudnn7.6.5_0    pytorch-nightly
[conda] torchvision               0.7.0a0+f9ef235          pypi_0    pypi

I cannot add a stack trace because there is not an error per se, it is simply that the library is not loaded.

A minimal example code would be (definitely not very useful):

import torchvision

Thanks!

@fmassa
Copy link
Member

fmassa commented May 4, 2020

@surisdi can you install torchvision using conda as well, instead of using pypi? It seems that you installed pytorch using conda while torchvision using pypi, which might have slightly different pytorch / torchvision nightlies.

@surisdi
Copy link
Author

surisdi commented May 4, 2020

Hi @fmassa, I installed torchvision from source (following the instructions here), as suggested in this release. Does installing torchvision using conda install video_reader properly? Thanks!

@fmassa
Copy link
Member

fmassa commented May 4, 2020

@surisdi hi,

oh ok, I misread it from the collect_env results (which showed pypi_0 pypi).
The conda packages for torchvision do not contain the video_reader backend, and as such you indeed need to build from source.

Can you check if video_reader.so is present in /path/to/environment]/lib/python3.8/site-packages/torchvision/? And if yes, what is the error message when trying to do

torch.ops.load_library('/path/to/video_reader.so')

If video_reader.so is not present in the installation folder of torchvision, this means that ffpmeg was not found while compiling torchvision. This is the logic that we use for finding the ffmpeg path

vision/setup.py

Lines 174 to 175 in bd27e94

ffmpeg_exe = distutils.spawn.find_executable('ffmpeg')
has_ffmpeg = ffmpeg_exe is not None

Maybe it might need to be adapted to other systems.

@surisdi
Copy link
Author

surisdi commented May 4, 2020

Hi, the video_reader.so file does not exist under site-packages/torchvision/, but it exists under site-packages/torchvision-0.7.0a0+bd27e94-py3.8-linux-x86_64.egg/torchvision/.

site-packages/torchvision/ is a folder that is created when installing torch. After installing torch, I installed torchvision from source and it created the site-packages/torchvision-0.7.0a0+bd27e94-py3.8-linux-x86_64.egg/ directory.

However, when importing torchvision in python, it imports the site-packages/torchvision/, not the site-packages/torchvision-0.7.0a0+bd27e94-py3.8-linux-x86_64.egg/torchvision. Deleting site-packages/torchvision/ makes python import site-packages/torchvision-0.7.0a0+bd27e94-py3.8-linux-x86_64.egg/torchvision instead.

However, the video_reader is still not loaded properly. The error when executing

torch.ops.load_library('.../site-packages/torchvision-0.7.0a0+bd27e94-py3.8-linux-x86_64.egg/torchvision/video_reader.so')

is

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/path/to/env/lib/python3.8/site-packages/torch/_ops.py", line 105, in load_library
    ctypes.CDLL(path)
  File "/path/to/env/lib/python3.8/ctypes/__init__.py", line 373, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: /path/to/env/lib/python3.8/site-packages/torchvision-0.7.0a0+bd27e94-py3.8-linux-x86_64.egg/torchvision/video_reader.so: undefined symbol: _ZTIN6ffmpeg6StreamE

Thanks,

@fmassa
Copy link
Member

fmassa commented May 5, 2020

Hi,

Thanks again for the message, I managed to reproduce the issue. Looking into it

@fmassa
Copy link
Member

fmassa commented May 5, 2020

@surisdi can you try #2183 and see if it fixes it for you?

We were missing a few files during compilation, and this fixed it for me locally.

@surisdi
Copy link
Author

surisdi commented May 5, 2020

This works great, thanks!

@fmassa
Copy link
Member

fmassa commented May 5, 2020

Awesome, thanks for trying this out! I'll merge the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants