Nodes/◧ AP ClipSEG Mask Light/◧ AP CLIPSeg Text Mask
ComfyUI Node

◧ AP CLIPSeg Text Mask

Describe it, get a mask — text-prompted segmentation with zero extra models

By adampolczynski·Created 5 months ago·Updated 5 months ago· 1
◧ AP CLIPSeg Text Mask
  • image
  • mask
promptface
threshold0.40
smooth_radius4
soft_masktrue
invertfalse
modelclipseg_rd64
mask_dilate0
mask_blur0
deviceauto
unload_after_runfalse

The fastest way to get a mask in ComfyUI is to just type what you want masked. face, sky, person - drop an image into ◧ AP CLIPSeg Text Mask, type a word, and out comes a float mask you can wire straight into an inpaint or compositing setup. No bounding box, no point clicks, no second detector model to install. That's the whole pitch, and for one-off masks it's the right trade.

CLIPSeg is worth context before you lean on it. It's the 2022 text-prompt segmentation model from Lüddecke & Ecker, and it's still quietly everywhere: OneTrainer uses it to bulk-generate training masks, and it shows up across the masking ecosystem as the cheap option. The heavyweight route in this space is GroundingDINO for the box plus SAM/SAM3 for the pixel mask - precise, but it's two more models and a chattier workflow. CLIPSeg does the whole job with one model and one prompt field, at the cost of blobbier edges. That trade is exactly what this node is.

How it works

Under the hood it's transformers' CLIPSegForImageSegmentation. On first run the model auto-downloads to the HuggingFace cache - clipseg_rd64 (default, ~350 MB, better quality) or clipseg_rd16 (~100 MB, faster). After that it stays cached in GPU/CPU memory, so subsequent frames don't reload. Each prompt becomes a sigmoid heatmap, and the threshold turns that heatmap into a mask.

Two details make it genuinely nice. First, separate prompts with | to average heatmaps: face | head | eyes blends all three into one mask - handy when no single word nails the region. Second, the smooth/soft pipeline: smooth_radius runs a blur before thresholding, and soft_mask decides whether you get a feathered heatmap or a hard binary mask. There's no numpy involved - all I/O goes through torch and PIL, which is the pack's other selling point: numpy 2.x safe.

The inputs that matter

  • prompt (default face) - the region to mask. | separates multiple prompts.
  • threshold (default 0.40, 0.01–0.99) - lower gives a bigger, looser mask; higher tightens it. This is the knob you'll spend the most time on.
  • soft_mask - True feathers the edges, False gives a crisp binary mask.
  • mask_dilate / mask_blur - expand the mask or soften the final edges, so you can skip extra cleanup nodes.
  • unload_after_run (optional) - frees the model from VRAM after each execution; flip it on if you're not using this every frame.

Output is a single mask (MASK, float32 [B, H, W] in [0, 1]). Wire it into a masked-inpainting setup (Set Latent Noisy Mask → KSampler) or into AP Mask Trim / any mask compositor.

Installing

Via ComfyUI Manager, search "AP ClipSEG Light" and hit install. Or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/adampolczynski/ComfyUI_AP_ClipSEG_Light

Then restart ComfyUI. Dependencies are just transformers, torchvision>=0.15 and Pillow - nothing exotic, and the ~350 MB model download happens automatically on your first run.

Where people get burned

First run is slow. That's the model download, not a hang. Give it a minute.

CLIPSeg masks are fuzzy. It's a semantic segmenter, not a contour chaser - heatmaps come out blobby, and community reports on r/StableDiffusion about inconsistent masks for specific clothing items are CLIPSeg being CLIPSeg, not a bug. Don't fight it for surgical cuts; dial threshold and smooth_radius, and if you need a precise object silhouette, that's a SAM3/GroundingDINO job.

The TensorFlow crash that isn't one. transformers >= 4.50 lazily imports TensorFlow even when you only use CLIPSeg, and old TF builds blow up on numpy 2.x. This pack stubs that import before transformers ever loads, so it just works. If you've seen TF errors from other nodes, that's the fix you're benefiting from here.

One quirk worth knowing: the node always re-runs when you touch a setting (its IS_CHANGED never caches), so tweaking the prompt or threshold re-evaluates immediately. That's the behavior you want from a mask tool. Keep a low rd16 on hand if you're iterating a lot - it's a third of the size and the quality gap is usually acceptable for masking.

CategoryAP ClipSEG Light

Inputs (11)

NameTypeDefaultDescription
imageIMAGE
promptSTRINGfaceText description of the region to mask. Use '|' to separate multiple prompts.
thresholdFLOAT0.400.01–0.99Sigmoid heatmap threshold. Lower → larger mask, higher → tighter mask.
smooth_radiusINT40–32Gaussian blur radius applied to the heatmap before thresholding.
soft_maskBOOLEANtrueTrue = output the smoothed sigmoid heatmap (soft/feathered edges). False = hard binary mask at the threshold value.
invertBOOLEANfalseInvert the output mask.
modelCOMBOclipseg_rd64CLIPSeg variant. rd64 = better quality, rd16 = faster.
mask_dilateINT00–64Dilate (expand) the final mask by this many pixels. 0 = off.
mask_blurINT00–64Gaussian blur applied to the final mask. 0 = off.
deviceCOMBOautoCompute device. 'auto' uses CUDA when available.
unload_after_runoptBOOLEANfalseUnload the model from memory after each run to free VRAM.

Outputs (1)

NameTypeDescription
maskMASK