Nodes/comfyui-SegGPT/SegGPT Node
ComfyUI Node

SegGPT Node

Teach a segmentation model with one painted example, not a fine-tune

By nicehero·Created 2 years ago·Updated 2 years ago· 6
SegGPT Node
  • images
  • prompt
  • promptMask
  • MASKS
  • PREVIEW

This node does something most mask tools can't: you show it one example - an image plus a mask you painted on it - and it hunts down that same thing in every other image you feed it. No text prompt, no ControlNet, no fine-tune. It's the ComfyUI wrapper around BAAI's SegGPT, the "segment everything in context" model from 2023, and it's a genuinely clever little trick that the ecosystem quietly forgot.

Why would you reach for it in 2026, when BiRefNet gives you a one-click cutout and SAM does anything you can click? Because those find the salient object or what you point at. SegGPT finds this specific thing: this exact logo, this particular flower species, this one person's jacket, consistently, across a whole batch of images. That's the in-context bit - the model never saw your class in training, and it doesn't need to. One painted example is the whole curriculum.

How it works

SegGPT is a ViT-Large transformer trained to treat segmentation as an in-context task. The mechanism (which you can read right in the pack's seggpt_engine.py) is blunt but effective: your example image and your target image get stacked vertically, your example mask and a blank target stack below them, and the model predicts the mask for the target half. Pixels in the prompt tell it what an instance of "the thing" looks like; pixels in the target tell it what a mask over that thing looks like. One shot, done.

Two things the source code makes very clear before you trust it on big jobs. First, everything is resized to 448×448 internally - the input, the example, the mask - and the output is scaled back to your original size with nearest-neighbor interpolation. Expect chunky, blocky mask edges on anything larger than that. Second, the model is loaded from disk on every single run (prepare_model() inside doSegGPT, then del model at the end). There's no caching, so each execution re-reads a ~1.2GB ViT-Large checkpoint before it does a single thing. A 5-image batch is five separate inferences plus a model load each time.

The inputs and outputs that matter

All three inputs are required, and all are IMAGE tensors:

  • images - the image or batch you want segmented.
  • prompt - your example image showing the thing to find.
  • promptMask - the mask you painted over the example. This is where you spend your effort; the better it hugs the object, the better the model generalizes.

Outputs are two IMAGE tensors: MASKS (the raw segmentation, recolored per object) and PREVIEW (the mask blended at 50% over the original, so you can eyeball whether it worked).

The trap: both are plain images, not ComfyUI MASK type, and the mask comes out colored rather than binary. If you want to feed a real alpha or an inpaint workflow, you'll be routing this through something that extracts a channel and thresholds it first. It'll never feel as clean as a native mask node.

Installing it

ComfyUI Manager handles it - search "comfyui-SegGPT". The manual route is standard, but note the model is not auto-downloaded; you must fetch it into the node folder yourself:

cd ComfyUI/custom_nodes
git clone https://github.com/nicehero/comfyui-SegGPT
cd comfyui-SegGPT
wget https://huggingface.co/BAAI/SegGPT/resolve/main/seggpt_vit_large.pth
pip install -r requirements.txt

Restart ComfyUI and the node appears as "SegGPT Node". Watch the dependency line: the pack pins timm==0.6.7, fvcore, and fairscale - all old, and that hard timm pin is the thing most likely to clash with a newer pack in your install. If something else breaks after adding this, start there.

The honest verdict

For "find this exact thing across a batch, no training," it's a small miracle. For anything BiRefNet or SAM already does better - backgrounds, portraits, obvious salient objects - don't bother; those are faster, sharper, and one-click. SegGPT is the one you reach for when the mask you need is specific and the modern one-shot tools shrug. The 448px ceiling and per-run model load are real friction, but for a niche batch-masking job, nothing else in the box does it.

Its silence is telling: the model itself has basically dropped out of the discourse - four stray mentions on Reddit since 2024, none of them about using it. That's not a bug; it's a niche finding its size.

CategorySegGPT

Inputs (3)

NameTypeDefaultDescription
imagesIMAGE
promptIMAGE
promptMaskIMAGE

Outputs (2)

NameTypeDescription
MASKSIMAGE
PREVIEWIMAGE