-
Notifications
You must be signed in to change notification settings - Fork 7k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Torchvision import leads to OpenCV imshow freeze #5940
Comments
I don#t know why it is not listed there, but OpenCV is also installed in the venv. I checked the path and the version is not from the system. Version: import cv2
cv2.__version__
4.5.5 |
In case anyone is interested, here is the poetry lock file of the venv:
description = "Python package for providing Mozilla's CA Bundle."
category = "main"
optional = false
python-versions = "*"
[[package]] [package.extras] [[package]] [[package]] [package.dependencies] [package.extras] [[package]] [[package]] [package.dependencies] [[package]] [package.extras] [[package]] [[package]] [package.dependencies] [[package]] [package.extras] [[package]] [package.extras] [[package]] [package.dependencies] [package.extras] [[package]] [package.dependencies] [package.extras] [package.source] [[package]] [[package]] [[package]] [package.dependencies] [package.extras] [[package]] [package.extras] [[package]] [[package]] [package.dependencies] [[package]] [[package]] [package.dependencies] [package.extras] [[package]] [package.dependencies] [package.extras] [[package]] [[package]] [package.extras] [[package]] [package.dependencies] [metadata] [metadata.files] |
Displaying an image before the import leads to them being displayed also after the import. |
Thanks for the report. I can't reproduce in a clean $ conda create -n tv-5940 -y python=3.8
$ conda activate tv-5940
$ pip install torch torchvision opencv-python
$ python main.py Does the error persist? |
I did come across the $ python3 -m venv testenv
$ . testenv/bin/activate
(testenv) $ pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113
Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/cu113
Requirement already satisfied: torch in ./lib/python3.8/site-packages (1.11.0+cu113)
Requirement already satisfied: torchvision in ./lib/python3.8/site-packages (0.12.0+cu113)
Requirement already satisfied: torchaudio in ./lib/python3.8/site-packages (0.11.0+cu113)
Requirement already satisfied: typing-extensions in ./lib/python3.8/site-packages (from torch) (4.2.0)
Requirement already satisfied: pillow!=8.3.*,>=5.3.0 in ./lib/python3.8/site-packages (from torchvision) (9.1.0)
Requirement already satisfied: numpy in ./lib/python3.8/site-packages (from torchvision) (1.22.3)
Requirement already satisfied: requests in ./lib/python3.8/site-packages (from torchvision) (2.27.1)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in ./lib/python3.8/site-packages (from requests->torchvision) (1.26.9)
Requirement already satisfied: charset-normalizer~=2.0.0; python_version >= "3" in ./lib/python3.8/site-packages (from requests->torchvision) (2.0.12)
Requirement already satisfied: idna<4,>=2.5; python_version >= "3" in ./lib/python3.8/site-packages (from requests->torchvision) (3.3)
Requirement already satisfied: certifi>=2017.4.17 in ./lib/python3.8/site-packages (from requests->torchvision) (2021.10.8)
(testenv) $ # or the CPU version: pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu
(testenv) $ # or the nightly CUDA version: pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cu113
(testenv) $ pip3 install opencv-contrib-python
Requirement already satisfied: opencv-contrib-python in ./lib/python3.8/site-packages (4.5.5.64)
Requirement already satisfied: numpy>=1.14.5; python_version >= "3.7" in ./lib/python3.8/site-packages (from opencv-contrib-python) (1.22.3) In this environment the above script reported by @Flova runs fine. Now when installing pytorchvideo (testenv) $ pip install pytorchvideo
Requirement already satisfied: pytorchvideo in ./lib/python3.8/site-packages (0.1.5)
Requirement already satisfied: networkx in ./lib/python3.8/site-packages (from pytorchvideo) (2.8)
Requirement already satisfied: fvcore in ./lib/python3.8/site-packages (from pytorchvideo) (0.1.5.post20220504)
Requirement already satisfied: av in ./lib/python3.8/site-packages (from pytorchvideo) (9.2.0)
Requirement already satisfied: iopath in ./lib/python3.8/site-packages (from pytorchvideo) (0.1.9)
Requirement already satisfied: parameterized in ./lib/python3.8/site-packages (from pytorchvideo) (0.8.1)
Requirement already satisfied: termcolor>=1.1 in ./lib/python3.8/site-packages (from fvcore->pytorchvideo) (1.1.0)
Requirement already satisfied: numpy in ./lib/python3.8/site-packages (from fvcore->pytorchvideo) (1.22.3)
Requirement already satisfied: tqdm in ./lib/python3.8/site-packages (from fvcore->pytorchvideo) (4.64.0)
Requirement already satisfied: tabulate in ./lib/python3.8/site-packages (from fvcore->pytorchvideo) (0.8.9)
Requirement already satisfied: yacs>=0.1.6 in ./lib/python3.8/site-packages (from fvcore->pytorchvideo) (0.1.8)
Requirement already satisfied: Pillow in ./lib/python3.8/site-packages (from fvcore->pytorchvideo) (9.1.0)
Requirement already satisfied: pyyaml>=5.1 in ./lib/python3.8/site-packages (from fvcore->pytorchvideo) (6.0)
Requirement already satisfied: portalocker in ./lib/python3.8/site-packages (from iopath->pytorchvideo) (2.4.0) The same script gets stuck by hogging a single core of the CPU 100% and not even accepting When uninstalling pytorchvideo, the Tested it with torch nightly as well. Same behaviour. |
Thanks for the extra information @juhan! I can reproduce the error now by also installing $ conda create -n tv-5940 -y python=3.8
$ conda activate tv-5940
$ pip install torch torchvision opencv-python pytorchvideo
$ python main.py |
Can you try to import torch
import torchvision ? IIRC |
Can narrow it down to $ conda create -n tv-5940 -y python=3.8
$ conda activate tv-5940
$ pip install torchvision opencv-python av
$ python main.py The error goes away for |
The problem is unrelated to # main.py
import numpy as np
import cv2
import av
cv2.imshow("debug", np.zeros((128,128,3), dtype=np.uint8))
cv2.waitKey(1) $ conda create -n tv-5940 -y python=3.8
$ conda activate tv-5940
$ pip install numpy opencv-python av
$ python main.py The reason you are seeing this is that as a side effect of vision/torchvision/__init__.py Line 6 in 6274080
vision/torchvision/io/__init__.py Line 35 in 6274080
vision/torchvision/io/video.py Line 17 in 6274080
This should be reported to respective projects. Given that |
So you suggest that I should open an issue for the repo of |
I would start by reporting to |
Okay. I thought, about |
You can of course also report to them so they can decide for themselves. They don't hard-depend on |
I'm not sure this issue is going anywhere, OpenCV and AV both vendor a bunch of libraries, notably FFmpeg and some X11 libraries. I suspect there is a conflict somewhere, and I don't really see how two unrelated projects are going to coordinate. |
@jlaine I'm fine with that result. We established that this is not on us and since we don't officially depend or support If someone wants both libraries at the same time, they should probably use a |
Sure, let's at least try to understand which library is clashing, we may be able to work around this with some SONAME mangling. |
Thank you very much! Saved my day! |
what a pesky bug, saved my day |
🐛 Describe the bug
Showing an image using OpenCV leads to the program getting stuck (100% CPU) without showing the image if torchvision is imported.
Expected result: The image is displayed and the program finishes.
Versions
PyTorch version: 1.11.0+cu102
Is debug build: False
CUDA used to build PyTorch: 10.2
ROCM used to build PyTorch: N/A
OS: Ubuntu 20.04.4 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Clang version: Could not collect
CMake version: version 3.16.3
Libc version: glibc-2.31
Python version: 3.8.10 (default, Mar 15 2022, 12:22:08) [GCC 9.4.0] (64-bit runtime)
Python platform: Linux-5.13.0-37-generic-x86_64-with-glibc2.29
Is CUDA available: True
CUDA runtime version: Could not collect
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 2080 Ti
Nvidia driver version: 470.103.01
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.22.3
[pip3] pytorchvideo==0.1.5
[pip3] torch==1.11.0
[pip3] torch-summary==1.4.5
[pip3] torchvision==0.12.0
[conda] Could not collect
The text was updated successfully, but these errors were encountered: