ComfyUI Node Runs on cloud

Batch CLIPSeg

Text-prompt masks across a whole batch

By kijai·Created 3 years ago·Updated 5 days ago· 3,141
Batch CLIPSeg
  • images
  • opt_model
  • prev_mask
  • Mask
  • Image
text
threshold0.500
binary_masktrue
combine_maskfalse
use_cudatrue
blur_sigma0.0
image_bg_level0.50
invertfalse

Type a word, get a mask of it. Batch CLIPSeg runs CLIPSeg - an open-vocabulary segmentation model - over an image or a whole batch of frames and hands you a mask of whatever you named in the text box. "hair", "shirt", "sky", "the dog": no clicking, no bounding boxes, just a prompt. The "batch" part is the reason it's in kijai's pack rather than one of the older single-image CLIPSeg nodes - it'll mask the same thing across every frame of a video, which is exactly what you want before an inpaint or a relight pass on a clip.

How it works, and where it sits

CLIPSeg is small, old, and cheap. It won't give you the razor edges of SAM 2 or the box-then-segment precision of a Florence2 pipeline - the KB's background-removal rundown treats those as the sharp modern tools - but CLIPSeg needs zero interaction and runs fast over a batch, which is its whole appeal. Reach for it when you want a good-enough mask of a named thing across many frames and precision isn't life-or-death. Reach for SAM/Florence when the edge quality actually matters.

The inputs that matter

  • images - the image or batch to segment.
  • text - what to mask, in plain words. This is the whole interface; be specific.
  • threshold - how confident a pixel must be to make the mask (default 0.5). Higher = tighter, less area; lower = more generous.
  • binary_mask - on gives a hard black/white mask; off gives a soft grayscale one you can feather with.
  • blur_sigma (optional) - feathers the mask edge.
  • invert (optional) - flips it, for when you want everything except the named thing.
  • combine_mask (optional) - merges a batch of masks into one.

Optional opt_model lets you pass a pre-loaded CLIPSeg model (so it isn't reloaded each run), and prev_mask lets you accumulate onto an existing mask. Outputs are the Mask and a masked Image preview.

Installing it

ComfyUI Manager → search KJNodes for ComfyUI → install → restart. Manual: cd ComfyUI/custom_nodes && git clone https://github.com/kijai/ComfyUI-KJNodes, then pip install -r ComfyUI-KJNodes/requirements.txt, and restart. The CLIPSeg weights are small and download automatically the first time the node runs, so the first execution needs internet and will pause briefly while it fetches them.

Where people get burned

  • Expecting SAM-quality edges. CLIPSeg is coarse by nature. If the mask is blobby or leaks, that's the model, not your settings - tighten threshold, add a little blur_sigma to hide ragged edges, or step up to a SAM/Florence workflow.
  • First-run stall / no internet. The auto-download needs a connection; an air-gapped box will fail on first use. Pre-fetch the model or pass one via opt_model.
  • Vague prompts. "person" catches everything person-ish; "red jacket" is far more selective. The text is doing real work - treat it like a prompt.
CategoryKJNodes/masking

Inputs (11)

NameTypeDefaultDescription
imagesIMAGE
textSTRING
thresholdFLOAT0.5000–10
binary_maskBOOLEANtrue
combine_maskBOOLEANfalse
use_cudaBOOLEANtrue
blur_sigmaoptFLOAT0.00–100
opt_modeloptCLIPSEGMODEL
prev_maskoptMASK
image_bg_leveloptFLOAT0.500–1
invertoptBOOLEANfalse

Outputs (2)

NameTypeDescription
MaskMASK
ImageIMAGE