Torchvision import breaks OpenCV code
See original GitHub issueš Bug
When I import torchvisions in an opencv python code, the code crashes with āSegmentation Faultā (in console) or āRestarting kernelā in Spyder / iPython.
To Reproduce
Steps to reproduce the behavior:
- Execute the code, the execution ends
- Execute the code and uncomment the torchvision import, the execution gives āSegmentation faultā
- Changing the order of import (torchvision then cv2) removes the issue for this short code sample but not for my complete code
import cv2
#import torchvision
pth = 'video.mp4'
cap = cv2.VideoCapture(pth)
ret,frame = cap.read()
cv2.imshow('frame',frame)
I also have an environment using Pytorch 1.5, the same code sample works fine under this environment. Thanks for checking if this is a real issue
Environment
PyTorch version: 1.8.0 Is debug build: False CUDA used to build PyTorch: 11.1 ROCM used to build PyTorch: N/A
OS: Ubuntu 20.04.1 LTS (x86_64) GCC version: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 Clang version: Could not collect CMake version: version 3.16.3 Libc version: glibc-2.10
Python version: 3.7 (64-bit runtime) Python platform: Linux-5.4.0-65-generic-x86_64-with-debian-bullseye-sid Is CUDA available: True CUDA runtime version: Could not collect
cuDNN version: Could not collect HIP runtime version: N/A MIOpen runtime version: N/A
Versions of relevant libraries:
[pip3] numpy==1.18.1
[pip3] numpydoc==1.1.0
[pip3] torch==1.8.0
[pip3] torchaudio==0.8.0a0+a751e1d
[pip3] torchfile==0.1.0
[pip3] torchlars==0.1.2
[pip3] torchsummary==1.5.1
[pip3] torchvision==0.9.0
[conda] blas 1.0 mkl
[conda] cudatoolkit 11.1.1 h6406543_8 conda-forge
[conda] ffmpeg 4.3 hf484d3e_0 pytorch
[conda] mkl 2020.2 256
[conda] mkl-service 2.3.0 py37he8ac12f_0
[conda] mkl_fft 1.2.0 py37h23d657b_0
[conda] mkl_random 1.1.1 py37h0573a6f_0
[conda] numpy 1.19.2 py37h54aff64_0
[conda] numpy-base 1.19.2 py37hfa32c7d_0
[conda] numpydoc 1.1.0 pyhd3eb1b0_1
[conda] pytorch 1.8.0 py3.7_cuda11.1_cudnn8.0.5_0 pytorch
[conda] torch 1.7.1 pypi_0 pypi
[conda] torchaudio 0.7.2 pypi_0 pypi
[conda] torchfile 0.1.0 pypi_0 pypi
[conda] torchlars 0.1.2 dev_0 <develop>
[conda] torchvision 0.9.0 py37_cu111 pytorch
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (7 by maintainers)
Have you tried creating a clean environment that uses just conda-forge/defaults and not pip packages? That combination is always guaranteed to generate segfaults
Yeah I saw the multiple versions, not sure if that could be the issue. Iām recreating a new clean environment to check that.
If I do that, pytorch goes from 1.8.1 to 1.8.0 and torchvision also from 0.9.1 to 0.9.0. It installs opencv 4.5.2. And yeah ok, doing that solves the issue, so I guess it was on my side. Sorry for the trouble, itās hard to get from where the bugs come from with these weird behaviors. _
For those with the same issue:
Thanks for the help!
edit: Iāll also look on how to use spyder better, thanks for the tip