Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ notebooks = [
"einops",
"scikit-image",
"scikit-learn",
"triton; sys_platform != 'win32'",
"triton-windows; sys_platform == 'win32'",
]
train = [
"hydra-core",
Expand Down
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