BMAB Segment Anything
ComfyUI Node Guide
- image
- masks
- masks
What it is
BMAB Segment Anything takes a rough mask and turns it into a precise one, using Meta's original Segment Anything Model. In practice that means: something upstream in your BMAB pipeline finds a region - a face, a hand, whatever you've detected - and hands over a coarse bounding-box-shaped mask; this node runs SAM over the image and refines that into a mask that actually follows the object's outline instead of a rectangle. That distinction matters more than it sounds like it should. A tight mask around exactly the region you're inpainting gives you a clean seam; a loose box mask around it gives you a visible edge where the fixed patch meets the original image.
Worth knowing going in: these are the classic 2023-era sam_vit checkpoints, not the newer SAM2 or SAM3 models that have taken over more of the ComfyUI ecosystem lately. That's not necessarily a problem - the original SAM is still a solid, well-understood segmenter - but if you're chasing the latest masking quality, this is the older reliable tool rather than the current state of the art.
Inputs and outputs
Three required inputs: image (what you're segmenting), masks (the rough mask to refine - this is what SAM uses to figure out which region you actually mean), and model, a dropdown of three checkpoints: sam_vit_b_01ec64.pth, sam_vit_l_0b3195.pth, and sam_vit_h_4b8939.pth. That's the standard ViT-B / ViT-L / ViT-H tiering - B is the smallest and fastest, H is the largest, slowest, and generally the most accurate at picking out fine edges. One output: masks, the refined result, ready to feed into whatever inpainting or compositing node comes next.
How to install it
ComfyUI Manager is the easy path - search comfyui_bmab and it'll pull in the pack plus its two required companions, comfyui_controlnet_aux and ComfyUI_IPAdapter_plus. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/portu-sim/comfyui_bmab.git
cd comfyui_bmab
pip install -r requirements.txt
then the same two-step clone-and-install for the dependency repos, then restart. The README doesn't call out a separate SAM checkpoint download step, but in practice these sam_vit_*.pth files are large (the ViT-H one runs well over 2GB) and aren't bundled with the node pack - if the model dropdown is there but generation fails on first use, that's almost certainly a missing checkpoint file, which you'll need to grab from Meta's official Segment Anything release and drop into wherever BMAB is looking for it (typically a models/sams folder, following the convention most SAM-based ComfyUI nodes use).
Common issues
The biggest one is simply picking ViT-H by default and being surprised it's slow. It's genuinely the heaviest of the three - if you're running this inside a batch pipeline or on modest hardware, ViT-B is worth trying first and only stepping up if the mask quality actually needs it.
The other thing to watch: this node refines a mask, it doesn't create one from nothing. If the masks input you're feeding it is badly wrong to begin with - covering the wrong object entirely, or missing it - SAM will happily refine a mask around the wrong thing rather than correct your detection. Garbage in, precisely-shaped garbage out. Check what's actually feeding the masks socket before assuming a bad result is SAM's fault.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| masks | MASK | — | |
| model | COMBO | 3 options: sam_vit_b_01ec64.pth, sam_vit_l_0b3195.pth, sam_vit_h_4b8939.pth |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| masks | MASK | — |