Nodes/ComfyUI_LayerStyle_Advance/LayerMask: Florence2 Ultra(Advance)
ComfyUI Node Runs on cloud

LayerMask: Florence2 Ultra(Advance)

Text-prompted segmentation with the edge quality of a dedicated matting pass

By chflame163·Created 2 years ago·Updated 4 months ago· 696
LayerMask: Florence2 Ultra(Advance)
  • florence2_model
  • image
  • image
  • mask
taskregion to segmentation
text_inputsubject
detail_method
detail_erode6
detail_dilate6
black_point0.01
white_point0.99
process_detailtrue
device
max_megapixels2.0

Microsoft's Florence-2 is a small vision model that can do a surprising range of tasks from one checkpoint - captioning, detection, OCR, and, what this node cares about, segmentation from a text description. Florence2Ultra takes that and bolts on the edge-refinement pipeline the whole "Ultra" family in LayerStyle Advance shares, so instead of a blocky Florence2 mask you get one with properly resolved hair and fine detail. It's the "describe what you want, get a clean cutout" version of masking - no bounding box, no clicking, no separate detector model.

The catch, and it's a real one: this needs a FLORENCE2 model wired in from an upstream LoadFlorence2Model node. Florence2Ultra itself doesn't load anything.

How it works

Florence-2 supports several task modes, and this node exposes three that matter for masking: region to segmentation, referring expression segmentation, and open vocabulary detection. You pick the task, type what you're after into text_input (default is just "subject"), and Florence2 does the localization. From there the node runs the same edge-detail pass used across BenUltra, SegmentAnythingUltra, EVFSAMUltra and the rest: erode/dilate the rough mask, then refine the boundary with one of several matting-style methods.

That distinction between a plain segmentation mask and a matting pass matters more than it sounds: a segmentation model gives every pixel a hard foreground/background label, which is structurally wrong for hair, fur, or anything semi-transparent. The refinement step here is doing the same job a dedicated matting model does - recovering something closer to fractional edge detail instead of a stair-stepped boundary.

The inputs and outputs that matter

  • florence2_model / image - required. The model comes from LoadFlorence2Model (base, base-ft, large, large-ft, DocVQA, SD3-Captioner, or base-PromptGen are the options there).
  • task (default region to segmentation) and text_input (default "subject") - this is the pair you'll actually touch. Change text_input to whatever you're isolating ("the red jacket", "the dog"); switch task if plain segmentation isn't finding it.
  • detail_method - VITMatte, VITMatte(local), vitmatte-base-composition-1k, PyMatting, or GuidedFilter. VITMatte gives the best edges but needs its own model download; PyMatting/GuidedFilter are dependency-light fallbacks.
  • detail_erode / detail_dilate (both default 6) - shrink/grow the mask boundary before refinement.
  • black_point (0.01) / white_point (0.99) - edge sampling thresholds; tighten these if the refined edge looks muddy.
  • process_detail (default on) - turn off to skip the refinement pass entirely and save time when you don't need pixel-perfect hair.
  • max_megapixels (default 2) - caps the resolution the matting pass runs at. VITMatte especially will eat memory on large images if you don't cap this.

Outputs are image (the cutout) and mask.

Installing it

ComfyUI Manager: search "ComfyUI Layer Style Advance". Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/chflame163/ComfyUI_LayerStyle_Advance.git

then run install_requirements.bat (or the manual pip/whl steps in the README for portable installs) and restart. Florence2 model files download automatically on first use of LoadFlorence2Model, or grab them ahead of time from the linked BaiduNetdisk mirror into ComfyUI/models/florence2. If you use VITMatte as the detail method, that's a separate download too - hustvl/vitmatte-small-composition-1k into ComfyUI/models/vitmatte.

Common issues

"Cannot import name 'VitMatteImageProcessor' from 'transformers'." Your transformers is too old. Update it, or run the plugin's repair_dependency.bat.

Florence2 downloads fail on first run. The auto-download hits huggingface.co directly; if that's unreachable from your network, grab the model manually from the BaiduNetdisk link in the README and place it in ComfyUI/models/florence2 yourself.

Mask misses the subject entirely. Florence2's segmentation is prompt-driven, not magic - vague text_input gets vague results. Be specific, and try switching task between the three segmentation modes before assuming the model failed.

Edges look worse with VITMatte than without. Check max_megapixels isn't forcing a heavy downscale first, and confirm the vitmatte model actually downloaded (the node silently falls back to a cruder method if it can't find local weights, per the README's own naming of a VITMatte(local) variant as the "after first download" option).

Category😺dzNodes/LayerMask

Inputs (12)

NameTypeDefaultDescription
florence2_modelFLORENCE2
imageIMAGE
taskCOMBOregion to segmentation3 options: region to segmentation, referring expression segmentation, open vocabulary detection
text_inputSTRINGsubject
detail_methodCOMBO5 options: VITMatte, VITMatte(local), vitmatte-base-composition-1k, PyMatting, GuidedFilter
detail_erodeINT61–255
detail_dilateINT61–255
black_pointFLOAT0.010.01–0.98
white_pointFLOAT0.990.02–0.99
process_detailBOOLEANtrue
deviceCOMBO2 options: cuda, cpu
max_megapixelsFLOAT2.01–999

Outputs (2)

NameTypeDescription
imageIMAGE
maskMASK