facebookresearch / facebookresearch/sam2
decord usage for reading from mp4 causes segfaults
- Dominant language
- Jupyter Notebook
- Stars
- 19.9k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
I'm getting segfaults when `decord` is used in certain ways.
I installed sam2 fully with CUDA, and saw no errors when building the _C extension.
package versions:
```
torch 2.5.1
torchaudio 2.5.1
torchvision 0.20.1
imageio-ffmpeg 0.5.1
eva-decord 0.6.1
```
Driver & Cuda:
```
Driver Version: 560.35.03
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Thu_Mar_28_02:18:24_PDT_2024
Cuda compilation tools, release 12.4, V12.4.131
Build cuda_12.4.r12.4/compiler.34097967_0
```
OS: Ubuntu 22.04
Here is my test code to reproduce the issue.
```
def decord_error():
checkpoint="checkpoints/sam2.1_hiera_large.pt"
model_cfg = "configs/sam2.1/sam2.1_hiera_l.yaml"
device='cuda'
# segfault!
import decord
from sam2.build_sam import build_sam2_video_predictor
predictor = build_sam2_video_predictor(model_cfg, checkpoint, device=device)
def decord_ok():
checkpoint="checkpoints/sam2.1_hiera_large.pt"
model_cfg = "configs/sam2.1/sam2.1_hiera_l.yaml"
device='cuda'
from sam2.build_sam import build_sam2_video_predictor
import decord
predictor = build_sam2_video_predictor(model_cfg, checkpoint, device=device)
def from_mp4_error():
import numpy as np
checkpoint="checkpoints/sam2.1_hiera_large.pt"
model_cfg = "configs/sam2.1/sam2.1_hiera_l.yaml"
device='cuda'
# putting import decord here causes an error
from sam2.build_sam import build_sam2_video_predictor
predictor = build_sam2_video_predictor(model_cfg, checkpoint, device=device)
inference_state = predictor.init_state(video_path="./demo/data/gallery/01_dog.mp4")
_, out_obj_ids, out_mask_logits = predictor.add_new_points_or_box(
inference_state=inference_state,
frame_idx=0,
obj_id=1,
points=np.array([[50, 50]]),
labels=np.array([1], np.int32),
)
video_segments = {} # video_segments contains the per-frame segmentation results
for out_frame_idx, out_obj_ids, out_mask_logits in predictor.propagate_in_video(
inference_state, reverse=False
):
video_segments[out_frame_idx] = {
out_obj_id: (out_mask_logits[i] > 0.0).cpu().numpy()
for i, out_obj_id in enumerate(out_obj_ids)
}
def from_jpgs_ok():
import numpy as np
checkpoint="checkpoints/sam2.1_hiera_large.pt"
model_cfg = "configs/sam2.1/sam2.1_hiera_l.yaml"
device='cuda'
# putting import decord here causes an error
from sam2.build_sam import build_sam2_video_predictor
predictor = build_sam2_video_predictor(model_cfg, checkpoint, device=device)
# loading form jpg works fine.
# To generate the jpgs, in demo/data/gallery I ran ffmpeg -i 01_dog.mp4 -q:v 2 %05d.jpg
inference_state = predictor.init_state(video_path="./demo/data/gallery/")
_, out_obj_ids, out_mask_logits = predictor.add_new_points_or_box(
inference_state=inference_state,
frame_idx=0,
obj_id=1,
points=np.array([[50, 50]]),
labels=np.array([1], np.int32),
)
video_segments = {} # video_segments contains the per-frame segmentation results
for out_frame_idx, out_obj_ids, out_mask_logits in predictor.propagate_in_video(
inference_state, reverse=False
):
video_segments[out_frame_idx] = {
out_obj_id: (out_mask_logits[i] > 0.0).cpu().numpy()
for i, out_obj_id in enumerate(out_obj_ids)
}
if __name__ == "__main__":
# decord_error()
# decord_ok()
from_mp4_error()
# from_jpgs_ok()
```
Is this a configuration/version issue on my end? Or is there a mistake in how I'm trying to use `decord`? I think all the above examples _should_ work.
Contributor guide
Assessment
This issue has not been assessed yet.