Nodes/Anymatix/Anymatix SAM2 Loader
ComfyUI Node

Anymatix SAM2 Loader

Load a SAM2 model from a URL — and you'll still need kijai's pack installed

By Anymatix·Created about a year ago·Updated 2 days ago· 0
Anymatix SAM2 Loader
    • sam2_model
    sam2_name
    segmentor
    device
    precision

    SAM2 is the segmentation workhorse behind most targeted ComfyUI masking: click an object and it returns a clean mask, ready to feed an inpainting or detailing pass. If you're building SAM2 workflows on stock ComfyUI you normally load the model through kijai's ComfyUI-segment-anything-2 pack. AnymatixSAM2Loader is the Anymatix version of that load step - same underlying machinery, but the model file is addressed by URL so it can be fetched on demand - and it's adapted from DownloadAndLoadSAM2Model in that very pack (Apache 2.0, acknowledged in the README).

    One thing to get straight immediately: this node doesn't replace kijai's pack, it depends on it. The load actually happens by importing load_model.py out of a ComfyUI-segment-anything-2 folder sitting next to this pack in custom_nodes. If that folder isn't there, the node raises at run time (not import time - so the rest of the Anymatix pack keeps working) with a message telling you exactly what to install. And the model's config YAMLs come from that same sibling pack's sam2_configs directory. So the mental model is: this pack fetches and owns the weights, kijai's pack supplies the code that knows how to run them.

    How the loading works

    Feed it a path to a SAM2 checkpoint, pick a segmentor mode, a device, and a precision, and you get a SAM2MODEL out - wire it into the sibling pack's SAM2 sampling/segmentation nodes (SAM2Segmentation and friends), the ones that take your points or masks and return object masks.

    • segmentor - single_image, video, or automaskgenerator. This is the type of SAM2 model you're building: single-image interactive segmentation, video tracking with memory, or the automatic mask generator that proposes masks with no prompting at all. Match it to what your workflow does.
    • device - cuda, cpu, mps. Honest caveat from the code: fp16/bf16 precision is rejected outright on CPU, so if you're CPU-only you're on fp32.
    • precision - fp16, bf16, fp32. The fp16/bf16 path has a wrinkle for SAM 2.1 weights: the loader silently looks for a -fp16 suffixed variant of the model file (e.g. sam2.1_hiera_l-fp16.safetensors) when you ask for reduced precision, since that's how the SAM2.1 weights were distributed. If it can't find that file, that's your error - the plain 2.1 checkpoint needs its fp16 sibling for the fast path.

    Version mapping is handled internally (2.0 vs 2.1 configs resolve to the right YAML), so sam2_name + the four choices are genuinely all you set. The checkpoint file itself is expected under the SAM2 model folder after a fetcher node has downloaded it - the loader checks it exists and tells you if the fetcher hasn't run yet.

    Install

    Two packs, not one. First, kijai's:

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

    Then the Anymatix pack via Manager (search "anymatix-comfy-nodes") or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Anymatix/anymatix-comfy-nodes
    

    Restart ComfyUI after both. You don't need the Anymatix desktop app - the pack's published so its workflows run on stock ComfyUI.

    Where this fits in your workflow

    SAM2 sits at the front of the automation loop the KB's masking essay describes: mask from SAM → feed an inpainting or detailing pass → paste back. If you already have a mask you like, this node is arguably overkill - you don't need SAM to re-mask an existing mask (and if you feed one in via the MaskToSAMcoord sibling, mind the polarity note on that node). Reach for SAM2 when you want the interactive refinement: a rough click or box in, and a clean object mask out, which is exactly what promptable segmentation is for.

    CategoryAnymatix

    Inputs (4)

    NameTypeDefaultDescription
    sam2_nameSTRING
    segmentorCOMBO3 options: single_image, video, automaskgenerator
    deviceCOMBO3 options: cuda, cpu, mps
    precisionCOMBO3 options: fp16, bf16, fp32

    Outputs (1)

    NameTypeDescription
    sam2_modelSAM2MODEL