Nodes/MatAnyone2 Video Matting/MatAnyone2 SAM Loader
ComfyUI Node

MatAnyone2 SAM Loader

The SAM Loader That Lets You Skip the Editor Entirely

By dreamrec·Created 6 months ago·Updated 6 months ago· 3
MatAnyone2 SAM Loader
    • sam_model
    sam_model_typevit_h
    checkpoint_path
    deviceauto

    The interactive editor in this pack is great, but not everything wants a human clicking. If you're doing batch matting - same subject position across hundreds of clips, a fixed point in a drone shot, automated pipelines - you want the scripted path. That's what MatAnyoneSAMLoader exists for: it loads a Segment Anything model and hands it to MatAnyone2 SAM Refine, letting you build masks entirely in-node from explicit coordinates.

    Think of it as the same SAM brain the editor uses, minus the point-and-click interface. Same family of checkpoints (ViT-H/B/L from Meta's Segment Anything, vendored in the pack), same results - you're just telling it where to look with numbers instead of clicks.

    How it works

    The loader mirrors its sibling MatAnyone Model Loader almost exactly. Three inputs: sam_model_type (vit_h default, vit_l, or vit_b), checkpoint_path (blank = auto-download to ComfyUI/models/sams/), and device (auto/cuda/mps/cpu). One output: sam_model (MATANYONE_SAM), which only plugs into SAM Refine.

    Mechanically: blank path triggers a download from Meta's official dl.fbaipublicfiles.com URLs (the same sam_vit_h_4b8939.pth every SAM integration uses), the model registers from the vendored segment-anything snapshot via sam_model_registry, and it's cached in memory keyed by variant/path/device - so a second queue doesn't re-read a 2.5 GB file from disk. device on auto asks ComfyUI's model management and falls back cuda → mps → cpu.

    Picking a variant

    • vit_h - the default, and the obvious choice on a 12 GB+ card. Best edges, heaviest.
    • vit_l - middle ground nobody really needs unless H is too big.
    • vit_b - the one to reach for on a tight card. Noticeably lighter, still fine for a first-frame mask because the heavy propagation happens later in the Matte node.

    Install

    It's the pack, not a separate thing: ComfyUI Manager search "MatAnyone2", or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/dreamrec/MatAnyone2_ComfyUI.git
    cd MatAnyone2_ComfyUI
    python -m pip install -r requirements.txt
    python install.py
    

    Restart, and SAM weights download on first use.

    Gotchas

    The README's troubleshooting mostly applies here by extension. The classic one: if you're already keeping SAM checkpoints somewhere, pass an explicit checkpoint_path instead of letting it re-download into models/sams/. And if your auto-download lands in the wrong place because of an older ComfyUI layout, an explicit path sidesteps the whole question.

    One thing worth knowing: this node loads original SAM, not SAM 2. That's intentional - SAM2's hard mattes are exactly the thing MatAnyone exists to beat, so for a first-frame mask, original SAM's finer edges are the better starting point, and the pack's vendored snapshot guarantees the API matches.

    CategoryMatAnyone2/SAM

    Inputs (3)

    NameTypeDefaultDescription
    sam_model_typeCOMBOvit_h3 options: vit_h, vit_l, vit_b
    checkpoint_pathSTRING
    deviceCOMBOauto4 options: auto, cuda, mps, cpu

    Outputs (1)

    NameTypeDescription
    sam_modelMATANYONE_SAM