From 86ed77094094e5cabb16b0414ec60c5ba9ce0a0f Mon Sep 17 00:00:00 2001 From: Yunseok Jang Date: Mon, 16 Mar 2026 15:38:39 -0700 Subject: [PATCH] Make decord import lazy and add image-only inference build target Summary: Move the top-level `from decord import cpu, VideoReader` in sam3_image_dataset.py to a lazy import inside the .mp4 video loading block. This avoids import errors for consumers that only need image inference and don't have decord installed. Also add a new `sam3_inference_image_only` BUCK target that excludes decord from pypi_deps for downstream projects that only need image inference. Reviewed By: haithamkhedr Differential Revision: D96809398 fbshipit-source-id: 67c5f0be965d8420b244ff4c45d849314352d3cc --- sam3/train/data/sam3_image_dataset.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sam3/train/data/sam3_image_dataset.py b/sam3/train/data/sam3_image_dataset.py index c956d7b..28e7425 100644 --- a/sam3/train/data/sam3_image_dataset.py +++ b/sam3/train/data/sam3_image_dataset.py @@ -17,7 +17,6 @@ from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union import torch import torch.utils.data import torchvision -from decord import cpu, VideoReader from iopath.common.file_io import g_pathmgr from PIL import Image as PILImage from PIL.Image import DecompressionBombError @@ -202,6 +201,8 @@ class CustomCocoDetectionAPI(VisionDataset): try: if ".mp4" in path and path[-4:] == ".mp4": # Going to load a video frame + from decord import cpu, VideoReader + video_path, frame = path.split("@") video = VideoReader(video_path, ctx=cpu(0)) # Convert to PIL image