diff --git a/README.md b/README.md index 669242df..bc3b00df 100644 --- a/README.md +++ b/README.md @@ -88,13 +88,15 @@ pip install -e . 4. **Install additional dependencies for example notebooks or development:** ```bash -# For running example notebooks +# For running example notebooks (includes einops, decord, pycocotools, triton) pip install -e ".[notebooks]" # For development pip install -e ".[train,dev]" ``` +**Note:** Recent fixes include lazy loading of decord to prevent cv2.imshow() segfaults and updated notebook dependencies. + ## Getting Started ⚠️ Before using SAM 3, please request access to the checkpoints on the SAM 3 diff --git a/pyproject.toml b/pyproject.toml index 9df1b678..0078ecdf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,6 +64,8 @@ notebooks = [ "einops", "scikit-image", "scikit-learn", + "triton; sys_platform != 'win32'", + "triton-windows; sys_platform == 'win32'", ] train = [ "hydra-core", diff --git a/sam3/train/data/sam3_image_dataset.py b/sam3/train/data/sam3_image_dataset.py index 97efb1d1..7d4c8a98 100644 --- a/sam3/train/data/sam3_image_dataset.py +++ b/sam3/train/data/sam3_image_dataset.py @@ -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 @@ -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