Nodes/ComfyUI-H3-FaceRefine/H3 Face Mask (SAM)
ComfyUI Node

H3 Face Mask (SAM)

The SAM mask node that's usually not worth it

By Carasibana·Created 13 days ago·Updated 13 days ago· 292
H3 Face Mask (SAM)
  • crops
  • sam_model
  • transform
  • masks
  • report
threshold0.93
dilation0
temporal_smooth5

H3 Face Mask (SAM) is the optional upgrade in the ComfyUI-H3-FaceRefine pack that swaps the stitch-back node's rectangle mask for a true face-shaped SAM mask. And here's the honest take up front: the author himself says a rectangle frequently beats it. Try the plain rect workflow first, and only reach for SAM when the seam on a face edge is genuinely bugging you.

The pack exists because MiniMax H3 renders faces as smears when the head is a small fraction of the frame - a property of head-size-in-frame, not resolution, so it persists at 720p and up. You track the face, crop to it so it fills H3's canvas, let H3 re-generate it, and paste the result back. This node is the "paste" half getting fancy.

How it works

It's the same bbox + SAM path that Impact Pack's FaceDetailer uses, adapted per-frame to video. The tracker's transform gives a face rectangle; that box (plus its centre point) seeds a SAM prompt on each stabilised crop, and SAM returns a mask that follows the actual face - jaw, hairline, the lot - instead of an arbitrary box. Then the video-specific bit: the mask stack is averaged across temporal_smooth frames, because per-frame SAM wobbles by a few pixels and an unsmoothed boundary flickers, which is exactly the artefact this whole pipeline exists to avoid. Frames SAM fails on fall back to the plain face rect so you never get a hole.

The one input that trips people up is crops. Wire the tracker's input crops here, never the refined/decoded result. Generation must never feed back into the mask: if H3 nudges the face inward, a mask traced on the output follows the new smaller silhouette and the original face pokes out past it - most visibly the nose on a profile. Mask the input, like FaceDetailer masks the source, and you're covering where the face actually is.

Inputs and outputs

The ones you actually set:

  • crops - the crops output of H3 Face Track + Crop. See above, it matters.
  • sam_model - from Impact Pack's SAMLoader.
  • threshold (0.93) - SAM confidence floor for accepting mask pixels. Leave it.
  • dilation (0) - mask growth. SAM masks are accurate; they rarely need it.
  • temporal_smooth (5) - frames of averaging. 1 disables it and the edge will shimmer.

Outputs are masks (wire to H3 Face Stitch Back's masks input, which overrides paste_region) and a report string telling you how many frames SAM actually segmented.

Installing the extra bits

The node needs Impact Pack installed for SAMLoader (only this node does - the rest of the pack runs fine without it) and a SAM checkpoint in models/sams/, e.g. sam_vit_b_01ec64.pth from Meta's segment-anything repo. The pack itself is one clone:

cd ComfyUI/custom_nodes
git clone https://github.com/Carasibana/ComfyUI-H3-FaceRefine.git

Restart ComfyUI; the nodes land under MiniMax H3/Face Refine. ComfyUI Manager finds it by searching "ComfyUI-H3-FaceRefine" too.

Troubleshooting

  • Painfully slow mask passes. SAMLoader's AUTO device mode leaves the model on CPU until prepare_device() is called - a known trap that makes mask passes 10–50× slower. This pack calls it, so if you hit this, check you're not substituting your own SAM path.
  • Seam shows on the silhouette. SAM traces tightly, so any drift in the refined face lands right on the face edge. A slightly looser rect puts the seam in hair and background where it reads far less.
  • Using SAM masks? Drop feather on H3 Face Stitch Back to 4–8. A rect needs far more; with a tight SAM mask, a big feather just washes the jawline.

Not overhyped, but genuinely optional. Rect masks are the default for a reason - try them first.

CategoryMiniMax H3/Face Refine

Inputs (6)

NameTypeDefaultDescription
cropsIMAGEWire the INPUT crops here - the 'crops' output of H3 Face Track + Crop - NOT the refined/decoded result. This matches FaceDetailer: make_sam_mask() runs on the SOURCE image and the resulting mask is what the enhanced patch is later pasted through. Generation never feeds back into the mask. Masking the generated result instead is actively wrong: if the model nudges the face inward, the mask traces the NEW, smaller silhouette and the ORIGINAL face pokes out past it - most visibly the nose on profile shots. Masking the input covers where the face actually is in the footage being replaced. It is also cheaper: no dependency on the sampler, so SAM need not be resident alongside the video model.
sam_modelSAM_MODEL
transformH3FACEXFORM
thresholdFLOAT0.930–1
dilationINT00–128Mirrors FaceDetailer's sam_dilation default of 0. SAM masks are accurate, so they rarely need growing.
temporal_smoothINT51–31Frames of averaging across the mask stack. 1 disables it and you will likely see the mask edge shimmer.

Outputs (2)

NameTypeDescription
masksMASK
reportSTRING