LayerMask: Load SegmentAnything Models(Advance)
Load SegmentAnything Models — the shared loader behind SegmentAnythingUltra V3
- sam_models
This node exists purely to fix a waste-of-VRAM problem in the original SegmentAnythingUltra design. In V2, every instance of the segmentation node has its own sam_model and grounding_dino_model dropdowns and loads its own copies - fine with one node, wasteful with three. This loader pulls that model-loading step out on its own, so you load SAM and Grounding DINO exactly once and feed the result into as many LayerMask: SegmentAnythingUltra V3 nodes as you need.
There are only two inputs, and they're the same two model choices V2 has baked in: sam_model picks your Segment Anything checkpoint - seven options ranging from the tiny 39MB mobile_sam up through the 2.5GB sam_vit_h, with sam_hq_* variants in between trading some speed for sharper mask boundaries. grounding_dino_model picks the text-to-box detector, either the lighter GroundingDINO_SwinT_OGC (694MB) or the larger, more accurate GroundingDINO_SwinB (938MB). Bigger models in both categories generally mean better detection and mask quality at the cost of load time and VRAM - mobile_sam plus SwinT_OGC is the fast/light combo, sam_vit_h plus SwinB is the quality-first combo. The single output, sam_models, is a bundled handle carrying both loaded models, which plugs directly into V3's sam_models input.
Install the pack through ComfyUI Manager (search "ComfyUI Layer Style Advance") or git clone https://github.com/chflame163/ComfyUI_LayerStyle_Advance into custom_nodes/, restart, run the requirements installer. Model files: SAM checkpoints go in ComfyUI/models/sams, Grounding DINO's config and weights go in ComfyUI/models/grounding-dino. The one piece people consistently miss is that Grounding DINO's text tokenizer depends on bert-base-uncased - five specific files (config.json, model.safetensors, tokenizer_config.json, tokenizer.json, vocab.txt) need to sit in ComfyUI/models/bert-base-uncased. Everything's bundled together on chflame163's HuggingFace repo if you want to grab it all at once instead of hunting separate sources.
Since this node is pure model loading, there's not much unique to it beyond what breaks the segmentation pipeline generally. The one that bites people hardest: bert-base-uncased gets fetched live from Hugging Face if it's not already cached locally, which means on any offline, sandboxed, or firewalled deployment you'll hit a couldn't connect to huggingface.co error the moment Grounding DINO tries to build its tokenizer - even with the SAM and DINO checkpoints already sitting on disk correctly. Pre-downloading those five files sidesteps it entirely, and it's worth doing proactively if you're deploying this pack anywhere without guaranteed internet access at runtime. If the node simply won't import, check for the general pack-wide dependency issues first - a bad opencv-contrib-python version or an old transformers install cause more "broken node" reports across this pack than anything specific to SAM itself, and repair_dependency.bat in the plugin folder resolves most of them automatically.
Sizing this correctly up front saves a re-download later: pick your sam_model and grounding_dino_model based on what you'll actually be masking, not the biggest option by default. If you're segmenting clean, simple subjects, mobile_sam with GroundingDINO_SwinT_OGC loads fast and is genuinely good enough - the bigger checkpoints earn their VRAM cost on cluttered scenes or small/ambiguous objects where the detector needs more capacity to get the box right in the first place. Since every V3 node downstream shares whatever you load here, it's worth treating this as a one-time decision per workflow rather than something to fiddle with per-run.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| sam_model | COMBO | 7 options: sam_vit_h (2.56GB), sam_vit_l (1.25GB), sam_vit_b (375MB), sam_hq_vit_h (2.57GB), sam_hq_vit_l (1.25GB), sam_hq_vit_b (379MB), +1 | |
| grounding_dino_model | COMBO | 2 options: GroundingDINO_SwinT_OGC (694MB), GroundingDINO_SwinB (938MB) |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| sam_models | LS_SAM_MODELS | — |