Nodes/Kongshan Nodes/加载 SAM 模型
ComfyUI Node

加载 SAM 模型

Load a SAM or SAM-HQ Model From a Dropdown, Weights Auto-Downloaded

By kongshan4219·Created 3 months ago·Updated 3 months ago· 0
加载 SAM 模型
    • sam_model
    model_name

    SAM - Meta's Segment Anything model - is the masking backbone this ecosystem reaches for when it needs to cut out a specific object rather than everything that's not background. KSSAMModelLoader is the Kongshan pack's front door to it: pick a checkpoint from a dropdown and it loads (and on first use, downloads) the model, handing you a SAM_MODEL that feeds KSSAMSegmentByBoxes or the combined KSGroundedSAMSegment node.

    What you're choosing

    The dropdown lists seven checkpoints, and the sizes are right there in the names:

    • sam_vit_h (2.56GB) - the big original, best edge quality, heaviest.
    • sam_vit_l (1.25GB) - middle ground.
    • sam_vit_b (375MB) - the sensible default for most product work.
    • sam_hq_vit_h / sam_hq_vit_l / sam_hq_vit_b (2.57GB / 1.25GB / 379MB) - SAM-HQ, a community refinement with a higher-quality mask decoder that does better on fine detail like fur and hair.
    • mobile_sam (39MB) - tiny, fast, noticeably weaker edges.

    For product photography you can read the practical guidance straight off the sizes. A phone case or a bottle on a clean background barely stresses SAM - sam_vit_b is enough and it's a third of the disk cost. If you're cutting out lace, fur trim, or anything with a messy silhouette, reach for the HQ variant; the KB's SAM panel calls out that the mask quality gap is exactly where SAM-HQ earns its keep.

    How it loads

    Everything is automatic. The checkpoint URLs live in the node source, files land in ComfyUI/models/sams/ (created if missing), and it downloads on first selection via torch.hub. It loads onto ComfyUI's current torch device, so it respects your --lowvram / --normalvram choices rather than blindly grabbing the GPU. One thing to know: it pulls segment_anything plus transformers and timm from the pack's dependencies - that's the heavy install you're paying for with this pack, and it happens at pack install time, not node time.

    Installing

    With the pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/kongshan4219/ComfyUI-Kongshan-Nodes
    

    restart ComfyUI, then pick a model from the dropdown. The download is on demand, so your first run of the loader takes a while (up to ~2.5GB for vit_h); subsequent runs are instant.

    Gotchas

    • The first load is a multi-GB surprise. 2.56GB for sam_vit_h appears out of nowhere into models/sams/. If disk is tight, sam_vit_b at 375MB is a very reasonable place to start.
    • mobile_sam is a different model family. It's from the MobileSAM project, not the SAM-HQ line, and it's in the list for speed experiments - don't judge SAM by it.
    • The SAM_MODEL output is pack-private. It only plugs into this pack's SAM consumer nodes. If you want SAM in a different pack's detailer, use that pack's loader (e.g. Impact Pack has its own SAM integration). The KB's masking-detection-detailing essay covers why - SAM is the front end of targeted editing, and every pack wires its own.

    This is one of the most ordinary nodes in an unusual pack - a standard model loader with auto-download, done competently. The interesting bit is what it feeds into: GroundingDINO detection boxes become SAM masks, then product crops on white. That's the pipeline; this is just step one.

    CategoryKongshan/Local

    Inputs (1)

    NameTypeDefaultDescription
    model_nameCOMBOSAM 模型版本。vit_h/hq_vit_h 质量更高但显存和下载体积更大;vit_b/mobile_sam 更轻更快但边缘细节可能较弱。

    Outputs (1)

    NameTypeDescription
    sam_modelSAM_MODEL