Gemini Segmentation
Describe an object, get a mask
- image
- mask
Most mask-generation in ComfyUI is visual: you draw on a canvas, or you run a local segmentation model (BiRefNet, SAM, GroundingDINO) that finds objects. Gemini Segmentation flips the approach - you ask for the mask in words. Tell it "the car," "all people," "the red mug," and it returns a Comfy MASK isolating exactly that. For text-driven masking, that's a genuinely different workflow than anything local.
Where this shines: editing pipelines where your mask is defined by semantics, not pixels. Mask the person in a photo to keep them unchanged while you regenerate the background. Mask "all the chairs" for a furniture swap. It slots straight into inpainting, outpainting, or any mask-driven node.
One honesty note up front: this node isn't in the pack's code that's been around longest - it's documented in the README's node guide, and the shipped source I checked predates it. If your install doesn't show it, update the pack via Manager. The inputs below come from the pack's published node schema.
How it works
The node sends your image and segment_prompt to a Gemini model and asks for a segmentation mask of the described object back. The default model is gemini-robotics-er-1.5-preview - Google's embedded-reasoning robotics model, which is exactly the kind of model tuned for grounding objects in images and returning spatial output - with fallback options down through the Gemini 2.x lineup. The returned mask is converted to a Comfy MASK tensor, which means it plugs into every mask-aware node you already have.
The inputs that matter
- image - the photo or render to segment.
- segment_prompt - the words that pick your object. Default "all objects," but the useful calls are specific: "the car in the background," "every person," "the cup on the table." Precision in the prompt is precision in the mask.
- model - defaults to the robotics model (best for grounding);
gemini-2.5-flash/-proif you hit quota or want a different behavior. The lite models are cheaper but sloppier on hard segmentations. - temperature (default 0) - leave at 0. Segmentation is deterministic work; warmth buys you nothing.
- thinking / thinking_budget (optional) - for tricky prompts ("the person in the red jacket, not the one in blue"), a little thinking budget helps the model get the reference right.
- seed / api_key - key in the field or
.env(GEMINI_API_KEY).
The output
mask - a MASK tensor. Straight into a mask-draw/composite, inpaint, or edit node.
Installing it
Pack install, same as its siblings:
cd ComfyUI/custom_nodes
git clone https://github.com/Aryan185/ComfyUI-ExternalAPI-Helpers.git
cd ComfyUI-ExternalAPI-Helpers
pip install -r requirements.txt
Restart ComfyUI; find "Gemini Segmentation" under image/generation. Needs google-genai. Gemini key from aistudio.google.com - in the field or via GEMINI_API_KEY in .env.
Where people get burned
Vague prompts give vague masks - "the car" when there are three cars in frame returns something Gemini decides is the car, and it may be the wrong one. Be specific; that's the entire skill. Also, the robotics ER model is a preview and quota-capped; if you hit rate limits, drop to gemini-2.5-flash and it still works fine for most objects. And masks from an LLM are rarely pixel-perfect at the edges - expect to dilate or clean them up for tight compositing work. For rough semantic masking that would take you a minute of careful clicking, it's a huge time-saver.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| segment_prompt | STRING | all objects | — |
| model | STRING | gemini-2.5-flash | — |
| temperature | FLOAT | 0.00–2 | — |
| thinking | BOOLEAN | true | — |
| seed | INT | 69-1–2147483646 | — |
| api_key | STRING | — | |
| thinking_budgetopt | INT | 0-1–24576 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |