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
This commit is contained in:
committed by
meta-codesync[bot]
parent
f6e51f5950
commit
86ed770940
@@ -17,7 +17,6 @@ from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union
|
|||||||
import torch
|
import torch
|
||||||
import torch.utils.data
|
import torch.utils.data
|
||||||
import torchvision
|
import torchvision
|
||||||
from decord import cpu, VideoReader
|
|
||||||
from iopath.common.file_io import g_pathmgr
|
from iopath.common.file_io import g_pathmgr
|
||||||
from PIL import Image as PILImage
|
from PIL import Image as PILImage
|
||||||
from PIL.Image import DecompressionBombError
|
from PIL.Image import DecompressionBombError
|
||||||
@@ -202,6 +201,8 @@ class CustomCocoDetectionAPI(VisionDataset):
|
|||||||
try:
|
try:
|
||||||
if ".mp4" in path and path[-4:] == ".mp4":
|
if ".mp4" in path and path[-4:] == ".mp4":
|
||||||
# Going to load a video frame
|
# Going to load a video frame
|
||||||
|
from decord import cpu, VideoReader
|
||||||
|
|
||||||
video_path, frame = path.split("@")
|
video_path, frame = path.split("@")
|
||||||
video = VideoReader(video_path, ctx=cpu(0))
|
video = VideoReader(video_path, ctx=cpu(0))
|
||||||
# Convert to PIL image
|
# Convert to PIL image
|
||||||
|
|||||||
Reference in New Issue
Block a user