Nodes/ComfyUI-Transformers/Mask Generation
ComfyUI Node

Mask Generation

Automatic Mask Generation

By kadirnar·Created 3 years ago·Updated 7 months ago· 25
Mask Generation
  • image
  • overlay_image
  • masks_json
model_namefacebook/sam-vit-base
points_per_batch64

Mask Generation runs Segment Anything on your image and returns every object mask it can find. This is the "what am I looking at, object-wise" node: no prompt, no categories, no boxes - SAM just proposes segmentation masks for everything it thinks is a discrete thing, which makes it great for isolating subjects, generating inpainting masks, or feeding a downstream pipeline that needs to know where objects are.

The default model is facebook/sam-vit-base - the smallest general SAM checkpoint - and the node wraps the mask-generation pipeline from Hugging Face. It loads the model from the Hub, runs it on the first frame of your image, and does two things with the result: it paints the top ten masks onto a copy of the image as a color overlay, and it returns the per-mask confidence scores as JSON.

The inputs that matter

  • image - the IMAGE tensor to segment.
  • model_name - Hub model ID as a string, default facebook/sam-vit-base.
  • points_per_batch - internal batching for SAM's point prompting, default 64, range 1–256. Lower it if you're running low on VRAM; leave it alone otherwise.

Two outputs: overlay_image (an IMAGE - your original with up to ten colored masks blended on top) and masks_json (a STRING with per-mask index and score). Notice what's missing: you don't get the raw masks themselves, just the overlay. If your workflow needs an actual mask to feed into an inpaint or crop, you're working from the overlay or the JSON, not from clean per-object mask tensors.

How to install it

Same pack as all of ComfyUI-Transformers - ComfyUI Manager (search "ComfyUI-Transformers") or:

cd ComfyUI/custom_nodes
git clone https://github.com/kadirnar/ComfyUI-Transformers

Restart ComfyUI. requirements.txt covers the stack, and SAM ViT-base is roughly 375MB on first download.

Where people get burned

This is one of the pack's more honest "thin wrapper" moments. SAM does automatic mask generation well, but the node's output shape limits what you can actually do with it - you get a visual overlay plus scores, not clean masks you can route into an inpaint node. If your real goal is subject isolation or background removal, the ecosystem's dedicated tooling (BiRefNet-based removers, rembg-style nodes) will serve you far better - that's the community consensus on the "what should I reach for" question. Where this node does shine is quick visual inspection: seeing how many objects SAM finds and how confident it is, all inside the graph, before you invest in a heavier mask pipeline.

CategoryTransformers/MaskGeneration

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
model_nameSTRINGfacebook/sam-vit-base
points_per_batchINT641–256

Outputs (2)

NameTypeDescription
overlay_imageIMAGE
masks_jsonSTRING