SEGS Count
How many segments did the detector actually find?
- segs
- count
If you've ever hooked a detector (BBOX, SAM, a YOLO) into an Impact Pack detailer and watched it find "0 faces" on an image you can clearly see faces in, you already understand why counting segments is a real feature and not a toy. XJSegsCount takes a SEGS stream and returns the number of valid segments in it as a plain INT. One input, one output, and it's the kind of node that quietly becomes load-bearing in automation.
The useful detail is in that word valid. SEGS is Impact Pack's data format: a ((height, width), [SEG, ...]) tuple where each SEG carries a cropped mask, confidence, a crop region, and a label. Not every SEG in the list is actually usable - some have empty masks, some have degenerate bounding boxes where x1 >= x2. SEGS Count filters those out before counting, so the number you get is "how many segments are actually worth doing something with," not a raw list length. That distinction matters a lot in a loop: if you're iterating over segments and indexing them, you want the count that matches the indexes a Pick node will accept.
The whole interface:
segs- the SEGS input, straight from any detector or from Detailer (SEGS).- Output:
count, an INT.
Where you'll actually use it: gate logic. Wire the count into a comparison or a Switch and you can branch a workflow - "if fewer than one face was found, skip the detail pass" is the classic, because running a detail pass on an empty or wrong detection is how you get a workflow that silently wastes a generation. It's also useful for logging and debugging: after a Filter By Label or a Refine node changes how many segments survive, SEGS Count tells you exactly what changed. And in a loop that processes segments one at a time, it gives you the upper bound you need.
Install is the shared pack story:
cd ComfyUI/custom_nodes
git clone https://github.com/alexjx/ComfyUI-XJNodes
Restart ComfyUI, find it under XJNodes/segs, or use ComfyUI Manager and search "ComfyUI-XJNodes". No models, no pip extras - requirements.txt is empty. The one real dependency is conceptual: SEGS comes from Impact Pack, so this node only does anything if you're already running the pack that produces SEGS.
Honest take: this is a small personal-use pack with near-zero community footprint, and SEGS Count is a utility you'll stop noticing after it saves you once. But that one time a detector returns 38 segments on a photo you thought had 2 subjects, you'll be glad it exists.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| segs | SEGS | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| count | INT | — |