YOLOE-26 Select Best Instance
Pick the single best mask out of the pile, automatically
- instance_masks
- best_mask
- best_instance_metadata_json
- selected_mask_index
Your prompt found twelve people. You want to inpaint one. Select Best Instance is the node that decides which one, automatically, so you don't have to eyeball the batch and hand-pick an index. It takes the per-instance masks from YOLOE-26 Instance Masks, applies a selection strategy, and returns exactly one mask plus the metadata for the one that won.
This is a small node with a narrow job, and that's its whole appeal: when your workflow needs "the best X" rather than "all the X's," you get it without writing a single line of comparison logic.
How it works
It parses the metadata JSON from Instance Masks, which maps each mask in the batch to its detection record - confidence, area, class, and position. Then it sorts the candidates by your chosen selection_mode:
highest_confidence(default) - takes the most confident detection. Best for "fix the clearest face" type jobs.largest_area- takes the biggest mask. Best for "grab the main subject" when the biggest thing is the thing you want.confidence_then_area- confidence first, area as tiebreaker. The compromise mode when the confident picks are too small.
The outputs are best_mask (a single MASK), best_instance_metadata_json (the winning detection's record), and selected_mask_index (where it sat in the input batch, handy for debugging or logging).
The gotchas that will actually bite you
First, this node is a strict consumer of Instance Masks metadata - it expects a specific JSON shape (an images list, each with a detections list carrying output_mask_index). Wire it directly to the instance_metadata_json output of YOLOE-26 Instance Masks and you're safe; feed it arbitrary JSON and it'll error with a message about missing fields. Don't hand it the metadata_json from Detection Metadata and expect it to work.
Second, with a batch of input images the selection is global across the whole batch, not per image. The author's note is explicit: twelve people across three images is still one winner for the entire batch. If you need a best-per-image result, process images one at a time.
Third, if nothing was detected, the node returns a zero mask rather than crashing - which is graceful, but wire it knowing that an all-black mask might come out. Check the selected_mask_index or the metadata if a workflow downstream seems to be doing nothing.
Installing it
It ships in the Rinne414/ComfyUI-YOLOE26 pack. Install through ComfyUI Manager (search YOLOE-26) or:
cd ComfyUI/custom_nodes
git clone https://github.com/Rinne414/ComfyUI-YOLOE26.git
pip install -r ComfyUI-YOLOE26/requirements.txt
Restart ComfyUI. Like Refine Mask, this node never runs inference itself - the detection happened upstream - so no model or MobileCLIP download is triggered here.
Where you'd use it
The canonical chain is Load Model → Instance Masks → Select Best Instance → inpainting, and the classic use is a single detail pass: detect all the faces, take the highest-confidence one, and refine just that. Use largest_area when you want to work on the dominant subject of an image. It's one of those nodes you don't miss until you need it, and then it saves you an afternoon of index-poking.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| instance_masks | MASK | — | |
| instance_metadata_json | STRING | Metadata JSON produced by YOLOE-26 Instance Masks. | |
| selection_modeopt | COMBO | highest_confidence | Strategy used when selecting the best instance. With batched input images the best instance is chosen across the entire batch, not per image. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| best_mask | MASK | — |
| best_instance_metadata_json | STRING | — |
| selected_mask_index | INT | — |