Nodes/ComfyUI-segment-anything-2/(Down)Load SAM2Model
ComfyUI Node Runs on cloud

(Down)Load SAM2Model

The loader that feeds every SAM2 node

By kijai·Created 2 years ago·Updated 10 months ago· 1,210
(Down)Load SAM2Model
    • sam2_model
    model
    segmentor
    device
    precisionfp16

    This is the "load the thing" node for kijai's SAM2 pack, and every other node in the pack starts here. Segment Anything 2 is Meta's universal segmentation model - point at an object, or hand it a box, and it hands back a precise mask. SAM2 is the successor to the original SAM: more accurate, and, the big one, it does video - it can track an object across frames instead of re-guessing every frame. This node grabs the weights and gives you a sam2_model to plug into whichever segmentor you're using.

    The (Down)Load in the name is literal: on first run it downloads the checkpoint you picked, so the model dropdown is populated before you've manually fetched anything. Pick a model, pick a mode, wire it forward. That's the whole job.

    The mechanism, and the one setting people get wrong

    SAM2 comes in a family of sizes built on Meta's Hiera backbone, and the loader exposes all of them: sam2_hiera_tiny, small, base_plus, and large, plus the sam2.1 refresh of each. Tiny is fast and light and honestly fine for clean, obvious subjects; large is slower and sharper on fiddly edges. The 2.1 weights are the newer revision - reach for those unless you've got a reason not to.

    The setting that actually trips people is segmentor. It has three choices - single_image, video, automaskgenerator - and it has to match the node you're feeding downstream. This isn't cosmetic: the loader builds a different predictor object for each mode.

    • single_image → feeds Sam2Segmentation (mask one image from points or boxes)
    • video → feeds Sam2VideoSegmentationAddPoints + Sam2VideoSegmentation (track across frames)
    • automaskgenerator → feeds Sam2AutoSegmentation (segment everything, no prompts)

    Wire a video model into the single-image node and it'll error or behave weird. If something in the pack is throwing a type or attribute error right out of the gate, this is the first thing to check.

    Inputs and outputs that matter

    Four required inputs, and you'll only think about two:

    • model - which SAM2 checkpoint. Start with sam2.1_hiera_base_plus; it's the sensible middle. Downloads on first use.
    • segmentor - the mode, per above. Match it to your downstream node.
    • device (cuda / cpu / mps) and precision (fp16 default, bf16, fp32) - leave these. cuda + fp16 is what you want on any NVIDIA card. fp16 is plenty accurate here; there's no reason to burn VRAM on fp32 for a segmentation mask.

    Output is a single sam2_model (type SAM2MODEL) - the handle every SAM2 node in this pack expects as its first input.

    How to install it

    Easiest path is ComfyUI Manager: open the Manager, search ComfyUI-segment-anything-2, install, restart. Or clone it yourself:

    cd ComfyUI/custom_nodes
    git clone https://github.com/kijai/ComfyUI-segment-anything-2
    

    Then restart ComfyUI. The model weights land automatically the first time you run the node (into ComfyUI/models/sam2), so budget a minute of download on that first execution - large is a couple gigs, tiny much less. If you're on ComfyICU it's already in the shared image, so you skip both the install and the wait.

    Common issues

    • Wrong segmentor for the node you're feeding. The number-one gotcha. video mode won't drive the single-image node and vice versa. Set the mode to match your workflow before you debug anything else.
    • First run hangs "downloading." It's not frozen, it's pulling weights. Watch the console. If it fails, it's usually a network hiccup or a HuggingFace reach problem - re-run.
    • Slow, or OOM on a big video. SAM2's video mode holds state across frames, so VRAM climbs with clip length. Drop to a smaller Hiera variant (small or tiny) or shorten the clip before you blame the loader.

    Once you've got a sam2_model out of here, the interesting work happens downstream - masking for inpainting, regional prompting, compositing, or object tracking in video. This node just makes sure the model's loaded in the right mode for whatever that is.

    CategorySAM2

    Inputs (4)

    NameTypeDefaultDescription
    modelCOMBO8 options: sam2_hiera_base_plus.safetensors, sam2_hiera_large.safetensors, sam2_hiera_small.safetensors, sam2_hiera_tiny.safetensors, sam2.1_hiera_base_plus.safetensors, sam2.1_hiera_large.safetensors, +2
    segmentorCOMBO3 options: single_image, video, automaskgenerator
    deviceCOMBO3 options: cuda, cpu, mps
    precisionCOMBOfp163 options: fp16, bf16, fp32

    Outputs (1)

    NameTypeDescription
    sam2_modelSAM2MODEL