vision: Torchvision import leads to OpenCV imshow freeze

πŸ› Describe the bug

Showing an image using OpenCV leads to the program getting stuck (100% CPU) without showing the image if torchvision is imported.

import numpy as np
import cv2

import torchvision
cv2.imshow("debug", np.zeros((128,128,3), dtype=np.uint8))   # Frezzes at this line if torchvision is imported
cv2.waitKey(1)

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

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 4
  • Comments: 17 (1 by maintainers)

Most upvoted comments

Can narrow it down to PyAV:

$ 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 av<9 cc @bjuncek. Since pytorchvideo does not require a specific version you can use this as a quick workaround.

Sure, let’s at least try to understand which library is clashing, we may be able to work around this with some SONAME mangling.

Can you try to import torch before importing torchvision:

import torch
import torchvision

?

IIRC import torch does some magic symbol resolution which might be needed here?

Thanks for the extra information @juhan! I can reproduce the error now by also installing pytorchvideo:

$ conda create -n tv-5940 -y python=3.8
$ conda activate tv-5940
$ pip install torch torchvision opencv-python pytorchvideo
$ python main.py

Okay. I thought, about pytorchvideo so they maybe pin the dependency to av <9 but av itself seems definitely the most important to me.