Nodes/ComfyUI Segment Anything/SAMModelLoader (segment anything plus)
ComfyUI Node

SAMModelLoader (segment anything plus)

The dropdown that decides how good your cutouts are

By un-seen·Created 2 years ago·Updated 2 years ago· 11
SAMModelLoader (segment anything plus)
    • SAM_MODEL
    model_name

    This node is one dropdown, and that dropdown is the whole game: it picks which Segment Anything model you're about to run. Every mask this pack produces starts here, so the choice you make at this node determines whether your cutouts are usable or a fuzzy embarrassment.

    Segment Anything (SAM) is Meta's prompt-able segmentation model - give it a box or a point and it returns a precise pixel mask of whatever is inside. It doesn't care what the object is, which is exactly why it pairs with a text detector like GroundingDINO instead of a fixed-class detector like YOLO. The SAM_MODEL output of this node wires straight into GroundingDinoSAMSegment (segment anything plus), which is the node that actually turns your image into masks. This loader is the "which brain" step; that node is the "do the work" step.

    What you're choosing between

    There are seven checkpoints in the dropdown, and they fall into three camps:

    • The original three - sam_vit_h (2.56GB), sam_vit_l (1.25GB), sam_vit_b (375MB). Bigger = better edges, worse VRAM. vit_b is the sensible default; vit_h is the one to reach for when you're chasing hair and thin structures, and it will eat your GPU.
    • The HQ variants - sam_hq_vit_h/l/b, the same sizes with "high-quality" training. They give noticeably crisper boundaries on small objects. If your subject is small in frame, the HQ vit_b often beats the base vit_h at a fraction of the memory.
    • mobile_sam (39MB) - the "I'm on a laptop" option. It works, it's tiny, and it's clearly worse at fiddly edges. Fine for batch jobs where rough masks are enough.

    How the mechanism works

    When you pick a model and run the graph, the node checks ComfyUI/models/sams/ for the checkpoint and downloads it there if it's missing - no manual download needed if you're patient. It loads the weights through SAM's model registry and parks the model on your torch device, where it stays for the session. Two details matter: don't rename the files, because the code reads the checkpoint's filename to figure out which architecture it is (it also checks for hq in the name to pick the HQ predictor), and the mobile_sam auto-download URL in the pack points at a GitHub blob page rather than a raw file, so if that one fails, fetch mobile_sam.pt yourself and drop it in models/sams/.

    Installing the pack

    Install once for all five nodes in this pack. Via ComfyUI Manager, search "ComfyUI Segment Anything" and hit install. Or the manual way:

    cd ComfyUI/custom_nodes
    git clone https://github.com/un-seen/comfyui_segment_anything_plus
    

    The pack installs segment-anything, timm, addict, and yapf (its install.py does this for you). Then restart ComfyUI. First run is the heavy part: whichever SAM checkpoint you pick downloads automatically, and if that's slow, set HTTP_PROXY and HTTPS_PROXY and rerun.

    Where people get burned

    • VRAM. Loading vit_h (or even vit_l) on an 8GB card alongside a checkpoint is a cramped session. Start with vit_b; upgrade only if the edges actually disappoint you.
    • Disk. If you have both loaders in a workflow, be ready to hold ~2.5GB of SAM weights plus ~700MB of GroundingDINO. That's just the price of the pack.
    • It's not the slow part. SAM is fast; the DINO detector is usually the bottleneck. Don't blame this node for a sluggish run.
    Categorysegment_anything_plus

    Inputs (1)

    NameTypeDefaultDescription
    model_nameCOMBO7 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

    Outputs (1)

    NameTypeDescription
    SAM_MODELSAM_MODEL