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
5 changes: 5 additions & 0 deletions monailabel/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ class Settings(BaseSettings):
strtobool(os.environ.get("MONAI_LABEL_USE_ITK_FOR_DICOM_SEG", "True"))
)

# Skip SAM/SAM2 model download and initialization at server/app startup.
# Useful when running apps with their own interactive models (e.g. DeepEdit)
# where the generic SAM overhead (VRAM + startup latency) is not wanted.
MONAI_LABEL_SKIP_SAM: bool = bool(strtobool(os.environ.get("MONAI_LABEL_SKIP_SAM", "False")))

model_config = SettingsConfigDict(
env_file=".env",
case_sensitive=True,
Expand Down
6 changes: 6 additions & 0 deletions monailabel/sam2/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from monai.utils import optional_import

from monailabel.config import settings


def is_sam2_module_available():
# Global opt-out: skip SAM entirely (no download, no init) when set,
# e.g. MONAI_LABEL_SKIP_SAM=True, instead of per-app `-c sam2 false`.
if settings.MONAI_LABEL_SKIP_SAM:
return False
try:
_, flag = optional_import("sam2")
return flag
Expand Down