Nodes/ComfyUI Fooocus Nodes/Fooocus samLoaderPipe
ComfyUI Node

Fooocus samLoaderPipe

SAM, the anything-segmenter, as a pipe node

By Seedsa·Created 3 years ago·Updated 2 years ago· 102
Fooocus samLoaderPipe
    • sam_pipe
    model_name
    device_modeAUTO
    sam_detection_hint
    sam_dilation0
    sam_threshold0.93
    sam_bbox_expansion0
    sam_mask_hint_threshold0.70
    sam_mask_hint_use_negative

    Face fixing needs more than a box around the face. A bounding box says "somewhere in here is a face"; a segmentation mask says "this exact blob is the face, edges and all". That precision comes from SAM - Meta's Segment Anything model - and this node is how the pack loads it. Fooocus samLoaderPipe loads SAM into a sam_pipe that the detailing pipeline consumes, with a row of hint settings that decide how SAM interprets what it's given.

    What it does

    It's a loader and configurator in one: it pulls the SAM checkpoint into memory (the model_name dropdown lists your downloaded SAM weights) and sets up how SAM will be prompted during segmentation. The output, sam_pipe (PIPE_LINE), feeds the Fooocus preDetailerFix node, where it provides the fine mask that the fix pass inpainting runs on.

    The settings that matter:

    • model_name - which SAM checkpoint. Populated from your models folder; bigger checkpoints are more accurate and much slower.
    • device_mode - AUTO, Prefer GPU, CPU. AUTO is right; flip to CPU if VRAM is tight and you can live with the slowdown.
    • sam_detection_hint - how SAM is pointed at the target: center-1, horizontal-2, vertical-2, rect-4, diamond-4, mask-area, mask-points, mask-point-bbox, or none. These are the hint patterns (where the "positive" points are dropped inside the region) that tell SAM what to treat as foreground. center-1 is the sensible default for a face; the multi-point options help when the region is ambiguous.
    • sam_dilation - expand or shrink the mask in pixels. Negative erodes (useful when SAM over-masks), positive grows it (when it under-masks).
    • sam_threshold (0.93) - how confident SAM must be for a pixel to count as part of the mask.
    • sam_bbox_expansion - grow the bounding box before masking, if the detector's box is snugger than the actual object.
    • sam_mask_hint_threshold (0.7) and sam_mask_hint_use_negative (False/Small/Outter) - advanced hint tweaks for using the detector's own mask as a SAM hint; leave them unless you're chasing a specific artifact.

    Installing

    Pack install - ComfyUI Manager, search "Fooocus Nodes", or clone the repo. The real requirement is the SAM model itself: it's a separate download that lands in your ComfyUI models folder, and it's the multi-GB piece of the detailing pipeline. First run with the node will be slow while it loads.

    The honest take

    This node exists because SAM genuinely improves the fix: a mask-based inpaint patch feathers into the image far better than a hard rectangle, which is the difference between a clean face rescue and a telltale outline. But SAM is also the slowest part of the pipeline, and on a 6GB card it competes with the main generation for VRAM. If faces are coming out fine with the detector alone, you can often skip the sam_pipe entirely - preDetailerFix's force_inpaint will fall back to the bbox mask. Add SAM when edges look boxy, not by default.

    CategoryFooocus/Fix

    Inputs (8)

    NameTypeDefaultDescription
    model_nameCOMBO0 options:
    device_modeCOMBOAUTO3 options: AUTO, Prefer GPU, CPU
    sam_detection_hintCOMBO9 options: center-1, horizontal-2, vertical-2, rect-4, diamond-4, mask-area, +3
    sam_dilationINT0-512–512
    sam_thresholdFLOAT0.930–1
    sam_bbox_expansionINT00–1000
    sam_mask_hint_thresholdFLOAT0.700–1
    sam_mask_hint_use_negativeCOMBO3 options: False, Small, Outter

    Outputs (1)

    NameTypeDescription
    sam_pipePIPE_LINE