Nodes/ComfyUI-Inpaint-CropStitch-NB2/Florence-2 Smart Region Selector (FAL API)
ComfyUI Node

Florence-2 Smart Region Selector (FAL API)

Florence-2 Smart Region Selector — say 'face' or 'glasses', get a mask back

By amortegui84·Created 5 months ago·Updated 3 months ago· 3
Florence-2 Smart Region Selector (FAL API)
  • image
  • mask
  • mask_image
  • info
  • center_x
  • center_y
  • crop_width
  • crop_height
region_typeface
custom_text
selection_modelargest
padding_percent8.0
return_rect_maskfalse
api_key
api_key_env_varFAL_KEY
mask_blur_percent0.0
upload_max_dimension2048
detection_modeauto

This node is how you go from "I want to retouch the face" to a ComfyUI mask without drawing anything. It sends your image to Florence-2 through FAL's API, and you pick a region type - face, glasses, upper_body, lower_body, full_body, or object - and it returns the detected region as a mask, plus the geometry to feed the crop nodes.

The name matters: it's the smart region selector, the front end for the pack's whole crop/stitch architecture. The mask it produces can drive either path - NB2 Smart Region for the Nano Banana flow, or Smart Mask Crop for the GPT Image flow - and its info output carries shape hints that the crop nodes use to pick the right rectangle.

How it works

Florence-2 runs on FAL's servers (not locally), so this node uploads your image and gets back segmentation or a grounding bounding box. The default detection_mode = auto uses a bbox for faces and segmentation elsewhere; if segmentation grabs the wrong thing for a face, switch to grounding_bbox. The returned mask's rectangle metadata is what powers the region defaults: face → 1:1, glasses → 16:9, upper_body/lower_body → 1:1, full_body → 9:16 - those hints ride along in the info output so downstream nodes size themselves.

The inputs that matter

Required is just image and region_type. After that:

  • custom_text - required only when region_type = object; that's where you type "bra", "watch", "wheel", whatever.
  • padding_percent (default 8) - expands the detected bbox, which feeds downstream crop sizing. Faces: 10–18; small objects: 5–12.
  • selection_mode - largest (default, pick the biggest match) or merge_all (union every match into one mask).
  • return_rect_mask - off by default; toggle to get a rectangle mask instead of the raw semantic blob.
  • upload_max_dimension (default 2048) - longest edge before upload. The tooltip's tip is practical: lower it to 1536 or 1024 if FAL closes the connection, which is a real thing that happens with huge source images.
  • api_key / api_key_env_var - FAL key or FAL_KEY env var.

Outputs: mask, mask_image, info, and the geometry ints (center_x, center_y, crop_width, crop_height) that let you build manual crop nodes if you want them.

The flow

NB2Florence2RegionSelector -> mask -> NB2 Smart Region -> NB2 Crop -> Nano Banana 2 -> NB2 Stitch

or for the masked path:

NB2Florence2RegionSelector -> mask -> Smart Mask Crop -> GPT Image Edit -> Smart Mask Stitch

Keys, install, gotchas

This is a FAL node, so it needs a key: paste it in api_key or set FAL_KEY before launching ComfyUI and fully restart. Key resolution order is direct api_key → env var (FAL_KEY by default) → this pack's optional config.ini → a sibling fal-flux-nodes/config.ini if you have that pack. A 401 Unauthorized from storage/auth/token on first run means the key isn't reaching the process - fix that before touching anything else. And note the pack's security reminder: the repo never stores your key, but if you paste it into a node and save the workflow yourself, it can persist in the JSON.

Install the pack once for all nodes:

cd ComfyUI/custom_nodes
git clone https://github.com/amortegui84/comfyui-inpaint-cropstitch-nb2

or search comfyui-inpaint-cropstitch-nb2 in ComfyUI Manager, restart. Want a fully local Florence path instead? The README points to kijai's ComfyUI-Florence2 - then feed its mask into NB2 Smart Region with depad_florence = True (Florence letterboxes internally, which shifts the bbox if you don't correct it).

Categoryinpaint/api

Inputs (11)

NameTypeDefaultDescription
imageIMAGE
region_typeCOMBOface6 options: glasses, face, upper_body, lower_body, full_body, object
custom_textoptSTRING
selection_modeoptCOMBOlargest2 options: largest, merge_all
padding_percentoptFLOAT8.00–100
return_rect_maskoptBOOLEANfalse
api_keyoptSTRING
api_key_env_varoptSTRINGFAL_KEY
mask_blur_percentoptFLOAT0.00–100Soft blur applied to the returned Florence mask.
upload_max_dimensionoptINT2048512–4096Downscale longest image edge before upload. Lower this if FAL closes the connection.
detection_modeoptCOMBOautoUse grounding_bbox for face if segmentation grabs the wrong region.

Outputs (7)

NameTypeDescription
maskMASK
mask_imageIMAGE
infoSTRING
center_xINT
center_yINT
crop_widthINT
crop_heightINT