图像分割-联合❤️🔥心宝专用
SAM + GroundingDINO in one node
- image
- image
- mask_union
- mask_list
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(defaultsubject) - 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, thesam_hq_vit_*variants, andmobile_sam(39MB). The SAM KB panel's guidance applies: bigger = better masks, more VRAM.sam_vit_his the quality default;mobile_samis there for CPU or when you just need a rough mask fast.grounding_dino_model-GroundingDINO_SwinT_OGC(694MB) orSwinB(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-cudaorcpu. 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.
Inputs (15)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| sam_model | COMBO | 7 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_model | COMBO | 2 options: GroundingDINO_SwinT_OGC (694MB), GroundingDINO_SwinB (938MB) | |
| threshold | FLOAT | 0.300–1 | — |
| detail_method | COMBO | 4 options: VITMatte, VITMatte(local), PyMatting, GuidedFilter | |
| detail_erode | INT | 61–255 | — |
| detail_dilate | INT | 61–255 | — |
| black_point | FLOAT | 0.150.01–0.98 | — |
| white_point | FLOAT | 0.990.02–0.99 | — |
| process_detail | BOOLEAN | true | — |
| prompt | STRING | subject | — |
| device | COMBO | 2 options: cuda, cpu | |
| max_megapixels | FLOAT | 2.01–999 | — |
| cache_model | BOOLEAN | false | — |
| use_global_model | BOOLEAN | true | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask_union | MASK | — |
| mask_list | MASK | — |