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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import torchvision , opencv cannot be imshow #7305

Closed
azuredsky opened this issue Feb 20, 2023 · 3 comments
Closed

import torchvision , opencv cannot be imshow #7305

azuredsky opened this issue Feb 20, 2023 · 3 comments

Comments

@azuredsky
Copy link

azuredsky commented Feb 20, 2023

🐛 Describe the bug

when import torchvision, the opencv cannot imshow, but when no import torchvision, imshow successed

import numpy as np
import cv2
import torch
import torchvision

if __name__ == '__main__':
        cap = cv2.VideoCapture(-1)
        assert cap.isOpened(), 'Cannot capture source'

        while cap.isOpened():

            ret, frame = cap.read()

            frame = cv2.flip(frame,1)
            cv2.imshow('mycreame',frame)
            if ( cv2.waitKey(30)  == 27 ):
                break
        cv2.destroyAllWindows()

Versions

Versions of relevant libraries:
[pip3] numpy==1.21.6
[pip3] torch==1.13.1
[pip3] torchaudio==0.13.1
[pip3] torchvision==0.14.1
[conda] blas 1.0 mkl http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
[conda] cpuonly 2.0 0 pytorch
[conda] mkl 2021.4.0 h06a4308_640 http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
[conda] mkl-service 2.4.0 py37h7f8727e_0 http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
[conda] mkl_fft 1.3.1 py37hd3c417c_0 http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
[conda] mkl_random 1.2.2 py37h51133e4_0 http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
[conda] numpy 1.21.6 pypi_0 pypi
[conda] numpy-base 1.21.5 py37ha15fc14_3 http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
[conda] pytorch 1.13.1 py3.7_cpu_0 pytorch
[conda] pytorch-mutex 1.0 cpu pytorch
[conda] torchaudio 0.13.1 py37_cpu pytorch
[conda] torchvision 0.14.1 py37_cpu pytorch

[pip3] opencv-python 4.6.0.66

@azuredsky azuredsky changed the title import torchvision , camera cannot be opened import torchvision , opencv cannot be imshow Feb 20, 2023
@ajithvcoder
Copy link

if you have pytorchvideo uninstall it and check , there is an issue already here #5940

@azuredsky
Copy link
Author

azuredsky commented Feb 22, 2023

I have not installed pytorchvideo, but I uninstall av ,then opencv will show success, I guess may the _video_backend of the torchvision ,av cause the hung

@albanD albanD transferred this issue from pytorch/pytorch Feb 22, 2023
@pmeier
Copy link
Collaborator

pmeier commented Feb 27, 2023

@azuredsky as @ajithvallabai correctly points out, #5940 deals with this exact issue. It seems opencv and av installed from PyPI cannot coexist in the same environment. As shown in #5940 (comment), the only part that torchvision plays in that is the fact that we try to import av. Thus, I'm closing this as not actionable. If you need both libraries at the same time, I suggest you use a conda environment for virtualization and ensuring that both libraries use the same ffmpeg binary.

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

No branches or pull requests

3 participants