Nodes/ComfyUI_Florence2SAM2/RdancerFlorence2SAM2GenerateMask
ComfyUI Node

RdancerFlorence2SAM2GenerateMask

Florence-2 + SAM2 in one self-contained node

By rdancer·Created 2 years ago·Updated about a year ago· 43
RdancerFlorence2SAM2GenerateMask
  • image
  • annotated_image
  • mask
  • masked_image
â—„sam2_modelsam2_hiera_small.ptâ–º
◄device▾►
â—„promptsubjectâ–º
â—„keep_model_loadedfalseâ–º

You type "person, hat, dog" into a box, and this node hands you a pixel-perfect mask of exactly those things - no clicking, no painting, no GroundingDINO, no separate model loaders. That's the whole pitch of RdancerFlorence2SAM2GenerateMask: the two-stage Florence-2 → SAM2 pipeline, the combo behind half the "easy inpainting" workflows people share, collapsed into one node that manages its own models.

If you've seen the community trick where you point a vision model at an image, name an object, and feed the resulting mask into an inpaint model, this is that trick as a drop-in part. The 2026 version of "you don't have to paint masks anymore" usually involves wiring Qwen or Florence to a SAM and to Flux Fill by hand; this pack does the Florence + SAM2 half of it for you, and the mask it produces plugs straight into whatever inpaint or detailer you're already using.

How it works

Two models, one behind the other, exactly like SkalskiP's original Florence-SAM HuggingFace space this pack is built on:

  1. Florence-2 (Microsoft's vision-language model) runs <OPEN_VOCABULARY_DETECTION> on your prompt. Type multiple objects as a comma-separated list - "person, hat, dog" - and each one becomes a detection query. Florence is the same model people use for auto-captioning LoRA datasets, and it's genuinely good at "find the thing I named," not just "describe the scene."
  2. SAM2 (Meta's Segment Anything 2) takes each bounding box Florence returns and carves out a tight object mask. The masks for all your detected objects get merged into a single mask.

The supervision library draws the pretty debug picture: colored masks, boxes, and labels on your original image.

Both models are lazy-loaded and cached - the node doesn't touch them until you run it, so your startup time doesn't suffer. Florence-2-base auto-downloads from HuggingFace on first use (~0.6GB into your HF cache). SAM2 does not auto-download; see below.

The inputs and outputs that matter

You only ever touch four fields. prompt (default "subject") is the star - comma-separated object names. sam2_model picks the checkpoint, sam2_hiera_small.pt by default; small is the sensible middle ground, tiny if you're on CPU, base_plus/large if you want crisper edges and have VRAM to burn. device is cuda or cpu. keep_model_loaded (optional, default off) leaves the models on the GPU between runs - worth it if you're looping this node in a batch, since reloading SAM2 every run adds a couple of seconds.

Three outputs:

  • mask (MASK) - the merged binary mask. This is the one you actually build your workflow around.
  • masked_image (IMAGE) - your image with everything outside the mask blacked out.
  • annotated_image (IMAGE) - the debug view with boxes, labels, and colored masks drawn on.

Feed mask into InpaintModelConditioning, a detailer like FaceDetailer, or a compositing node, and you're done.

Installing it

ComfyUI Manager: search "ComfyUI_Florence2SAM2" and hit install. Or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/rdancer/ComfyUI_Florence2SAM2
cd ComfyUI_Florence2SAM2
pip install -r requirements.txt

Then restart ComfyUI. The node sits in the 💃rDancer category.

Two things the README glosses over. First, requirements.txt pulls the SAM2 code from git+https://github.com/rdancer/samv2.git - the author's own fork, which exists because vanilla SAM2 crashes on Windows and this fork fixes it. Installing from a personal fork is a modest supply-chain decision worth knowing about, but the fix is the point. Second, you must drop a SAM2 checkpoint into ComfyUI/models/sam2/ (create the folder). Grab sam2_hiera_small.pt from Meta's SAM2 release; if it's missing, the node fails with a "checkpoint file does not exist" error that's easy to misread as a dependency problem.

Where people get burned

  • Missing SAM2 checkpoint - the #1 failure, and the README doesn't mention it. Check ComfyUI/models/sam2/sam2_hiera_small.pt first, always.
  • "No objects of class X found" - Florence just didn't see it. Try rewording the prompt ("the red car" instead of "car"), or split one compound prompt into separate runs. If nothing matches, the mask comes back empty and your masked image is pure black.
  • Models never leave - keep_model_loaded off still only offloads to RAM, not deletes. There's no unload button in this pack; if you want the memory back, restart ComfyUI.

The author tests pixel-exactness with a pytest harness (python test.py test/*_source.png "products"), which is more rigor than most of the custom-node ecosystem bothers with. For a single-purpose node, this one is unusually tidy - you just have to know the checkpoint gotcha.

Category💃rDancer

Inputs (5)

NameTypeDefaultDescription
sam2_modelCOMBOsam2_hiera_small.pt4 options: sam2_hiera_base_plus.pt, sam2_hiera_large.pt, sam2_hiera_small.pt, sam2_hiera_tiny.pt
deviceCOMBO2 options: cuda, cpu
imageIMAGE—
promptSTRINGsubject—
keep_model_loadedoptBOOLEANfalse—

Outputs (3)

NameTypeDescription
annotated_imageIMAGE—
maskMASK—
masked_imageIMAGE—