dmlc / decord

An efficient video loader for deep learning with smart shuffling that's super easy to digest
Apache License 2.0
1.89k stars 161 forks source link

Segmentation fault when using torch together with decord #324

Open xiaosu-zhu opened 2 weeks ago

xiaosu-zhu commented 2 weeks ago

EDIT: The root cause of Segmentation fault is from torch, not cv2, please see the correction below.

I have installed opencv-python-headless and decord together. The version info is listed below.

opencv-python-headless 4.10.0.84
decord 0.6.0

I try to import two libs in a python script:

import cv2
import decord

OR 

import decord
import cv2

No matter which order I import two libs, both of them lead to Segmentation fault (core dumped) crash, without any other logs.

JonathanLi19 commented 2 weeks ago

Same problem here

xiaosu-zhu commented 2 weeks ago

Correction

I have made a several test and found the core problem is from torch cuda. You could try several snippets below:

  1. 
    import torch
    from decord import VideoReader

vr = VideoReader(video_path) a = torch.tensor([3], device='cuda')


Segmentation fault (core dumped)


2. ❌
```python
import torch
from decord import VideoReader

a = torch.tensor([3], device='cuda')
vr = VideoReader(video_path)

---
Segmentation fault (core dumped)
  1. 
    import torch
    a = torch.tensor([3], device='cuda')

from decord import VideoReader

vr = VideoReader(video_path)


NORMAL



I found when creating a cuda tensor DIRECTLY AFTER torch import and then import the decord, all things will be fine.

If you import decord ahead and create any cuda tensor, a Segmentation fault will immediately throw out.