Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion sam3/train/data/sam3_image_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
import torch
import torch.utils.data
import torchvision
from decord import cpu, VideoReader
from iopath.common.file_io import g_pathmgr

# Lazy import of decord to avoid conflicts with OpenCV
# Decord will only be imported when actually needed in _load_images
# This prevents decord from loading when just importing sam3, which would
# cause cv2.imshow() to segfault due to library conflicts

from PIL import Image as PILImage
from PIL.Image import DecompressionBombError

Expand Down Expand Up @@ -202,6 +206,14 @@ def _load_images(
try:
if ".mp4" in path and path[-4:] == ".mp4":
# Going to load a video frame
# Lazy import decord only when needed to avoid conflicts with OpenCV
try:
from decord import cpu, VideoReader
except ImportError:
raise ImportError(
"decord is required for video loading but is not installed. "
"Install it with: pip install decord or pip install -e '.[notebooks]'"
)
video_path, frame = path.split("@")
video = VideoReader(video_path, ctx=cpu(0))
# Convert to PIL image
Expand Down