Nodes/Banana Gemini Image Generator/图像分割-联合❤️‍🔥心宝专用
ComfyUI Node

图像分割-联合❤️‍🔥心宝专用

SAM + GroundingDINO in one node

By 98624017·Created 9 months ago·Updated 5 months ago· 2
图像分割-联合❤️‍🔥心宝专用
  • image
  • image
  • mask_union
  • mask_list
sam_model
grounding_dino_model
threshold0.30
detail_method
detail_erode6
detail_dilate6
black_point0.15
white_point0.99
process_detailtrue
promptsubject
device
max_megapixels2.0
cache_modelfalse
use_global_modeltrue

This is the pack's segment-anything node: you give it an image and a text prompt like subject or product, and it returns masks of whatever that prompt points at. It's the classic GroundingDINO-plus-SAM text-to-mask pipeline folded into a single node - GroundingDINO finds the object described by the text, SAM turns it into a precise mask. It ships inside the 心宝 Banana pack (bundled from the author's separate segment_nodes_li set), and it's the natural front end for the local-edit chain: generate the mask here, crop with the aligned box node, fix the region in Banana, paste back.

The inputs that matter

  • image - what you're segmenting.
  • prompt (default subject) - the text description GroundingDINO searches for. "subject" is a fine default for "the main thing in this photo"; be more specific ("the red shoe", "the woman in the blue dress") when you want a particular object.
  • sam_model - seven choices: sam_vit_h (2.56GB), sam_vit_l, sam_vit_b, the sam_hq_vit_* variants, and mobile_sam (39MB). The SAM KB panel's guidance applies: bigger = better masks, more VRAM. sam_vit_h is the quality default; mobile_sam is there for CPU or when you just need a rough mask fast.
  • grounding_dino_model - GroundingDINO_SwinT_OGC (694MB) or SwinB (938MB). SwinT is the standard pick; SwinB is slower but finds objects more reliably.
  • threshold (0–1, default 0.3) - GroundingDINO's detection confidence. Below 0.3 you get more false positives; raise it to filter junk detections.
  • device - cuda or cpu. If you're on a GPU with the VRAM, cuda is the only sane choice for the large SAM checkpoints.

Then there's the "detail" group, which refines the mask edges after the base segmentation: detail_method (VITMatte, VITMatte(local), PyMatting, GuidedFilter), detail_erode / detail_dilate (default 6), black_point / white_point, and process_detail (on by default). These are the hair/fur/semi-transparency refiners - the same quality frontier the KB's background-removal doc tracks, applied to the mask rather than to a cutout. VITMatte is the heavyweight option that costs time; GuidedFilter is cheap and fast.

Rounding it out: max_megapixels (default 2) caps the working resolution so big images don't blow up VRAM; cache_model keeps the SAM weights loaded between runs (speeds up repeated runs, costs VRAM); use_global_model (default on) shares one cached model across nodes instead of each node loading its own.

The three outputs

  • image - a visual overlay of the segmentation on the input, so you can eyeball what got selected.
  • mask_union - all detected instances merged into one mask. This is the one you feed to the crop/preprocess chain when you want the whole subject as a single region.
  • mask_list - the same masks kept separate, one per detected instance. Use this when different objects need different downstream treatment.

The model-download reality

The first run downloads the selected checkpoints - SAM vit_h alone is 2.56GB, GroundingDINO SwinT another 694MB. That's not a one-time-then-forgotten cost either; if you switch to a different sam_model later it downloads again. Pick your SAM size, let the first run do its download, and be patient. The requirements (segment-anything, timm, opencv-contrib-python) come from the pack, but nothing auto-downloads at install time - the weights fetch on first use.

Installing

Same pack as everything here:

cd ComfyUI/custom_nodes
git clone https://github.com/98624017/comfyui-banana-li-linux

Restart ComfyUI, then run once to trigger model downloads. On a small GPU, reach for sam_vit_b or mobile_sam and set max_megapixels lower - the 2GB-class SAM models plus GroundingDINO plus a 2-megapixel image is a tight fit on an 8GB card.

Category❤️‍🔥心宝专用/分割

Inputs (15)

NameTypeDefaultDescription
imageIMAGE
sam_modelCOMBO7 options: sam_vit_h (2.56GB), sam_vit_l (1.25GB), sam_vit_b (375MB), sam_hq_vit_h (2.57GB), sam_hq_vit_l (1.25GB), sam_hq_vit_b (379MB), +1
grounding_dino_modelCOMBO2 options: GroundingDINO_SwinT_OGC (694MB), GroundingDINO_SwinB (938MB)
thresholdFLOAT0.300–1
detail_methodCOMBO4 options: VITMatte, VITMatte(local), PyMatting, GuidedFilter
detail_erodeINT61–255
detail_dilateINT61–255
black_pointFLOAT0.150.01–0.98
white_pointFLOAT0.990.02–0.99
process_detailBOOLEANtrue
promptSTRINGsubject
deviceCOMBO2 options: cuda, cpu
max_megapixelsFLOAT2.01–999
cache_modelBOOLEANfalse
use_global_modelBOOLEANtrue

Outputs (3)

NameTypeDescription
imageIMAGE
mask_unionMASK
mask_listMASK