Detect Regions (YOLO)
Find the objects in a frame, automatically
- image
- model_path
- model_label
- ui_widget
- region_meta
- region_meta_list
This is the "find things" node of the LF region pipeline. LF_DetectRegions runs a YOLO object detector over your image, finds the objects, and hands you back structured metadata - bounding boxes, labels, confidence - ready to be turned into masks by LF_RegionMask or used to drive targeted editing. It's the automation side of ComfyUI: instead of painting a mask over a face, you let the model find the face, then decide what to do with it.
The workflow shape is detection → mask → edit. Detect the regions with this node, carve the mask with LF_RegionMask, then feed that mask into an inpaint or a regional-prompt setup. It's the same "targeted masking" idea as GroundingDINO+SAM, done with a single lightweight ONNX model.
How it works
Two required inputs: image and model_path - the latter expects an ONNX_YOLO file, ideally picked via the pack's LF_ONNXSelector so you get a dropdown instead of typing paths. Files live under ComfyUI/models/onnx. The node runs the detector through onnxruntime, applies non-maximum suppression, and decides which region to treat as "the selected one."
The knobs that matter:
confidence_threshold(default0.25) - detections below this get discarded. Raise it if you're catching junk; lower it if things you want keep disappearing.iou_threshold(default0.45) - overlap cutoff for NMS, i.e. how aggressively duplicate boxes get merged.max_regions(default5) - cap on regions kept per image.class_filter/class_labels- filter to specific classes by name or ID, and optionally override the label names (useful if your model exports genericclass0labels).preferred_label+selection_strategy- tell the node which region to auto-select. If a box's label matchespreferred_label, it wins; otherwise it falls back toconfidenceorareaselection.select_index- the escape hatch:-1auto-selects, or set a concrete index to pick the Nth region manually.
Outputs
region_meta (the selected region's metadata) and region_meta_list (all detections as a list). Wire these into LF_RegionMask, which turns one of them into an actual MASK. The compare widget gives you a visual overlay of what got detected.
Installing it
lf-nodes installs as a pack:
cd ComfyUI/custom_nodes
git clone https://github.com/lucafoscili/lf-nodes
restart ComfyUI, or ComfyUI Manager → "LF Nodes". The dependency that matters is onnxruntime (in the pack's requirements). The YOLO model itself is not included - export one or download an ONNX detector and drop it in ComfyUI/models/onnx.
Common issues
- Model not found errors - the ONNX file isn't where
model_pathpoints. Use the ONNX selector to guarantee a valid path. - Too many or too few boxes - that's
confidence_thresholddoing its thing. Tune it per image content; 0.25 is a floor, not a law. - Wrong region auto-selected - set
preferred_labelto your target class, or bypass auto-selection entirely withselect_index.
Inputs (12)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | Image tensor or batch to analyse. | |
| model_path | ONNX_PATH | Absolute path to a YOLO ONNX model (use LF_ONNXSelector; files live under ComfyUI/models/onnx). | |
| model_labelopt | ONNX_DETECTOR | Optional label reported in metadata; defaults to the filename. | |
| confidence_thresholdopt | FLOAT | 0.250–1 | Discard detections below this confidence score. |
| iou_thresholdopt | FLOAT | 0.450–1 | Intersection-over-Union threshold for non-maximum suppression. |
| max_regionsopt | INT | 51–100 | Maximum number of regions to keep per image after NMS. |
| class_filteropt | STRING | Optional comma-separated list of class names or IDs to keep. | |
| class_labelsopt | STRING | Optional class label override (comma, newline or JSON). | |
| preferred_labelopt | STRING | First region whose label matches this string will be selected. | |
| selection_strategyopt | COMBO | confidence | Fallback strategy when auto-selecting a region. |
| select_indexopt | INT | -1-1–256 | Manually select the Nth region (after filtering). -1 chooses automatically. |
| ui_widgetopt | LF_COMPARE | [object Object] | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| region_meta | REGION_META | Detected region metadata. |
| region_meta_list | REGION_META | List of all detected region metadata. |