Nodes/lf-nodes/Detect Regions (YOLO)
ComfyUI Node

Detect Regions (YOLO)

Find the objects in a frame, automatically

By lucafoscili·Created 2 years ago·Updated 7 days ago· 35
Detect Regions (YOLO)
  • image
  • model_path
  • model_label
  • ui_widget
  • region_meta
  • region_meta_list
confidence_threshold0.25
iou_threshold0.45
max_regions5
class_filter
class_labels
preferred_label
selection_strategyconfidence
select_index-1

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 (default 0.25) - detections below this get discarded. Raise it if you're catching junk; lower it if things you want keep disappearing.
  • iou_threshold (default 0.45) - overlap cutoff for NMS, i.e. how aggressively duplicate boxes get merged.
  • max_regions (default 5) - 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 generic class0 labels).
  • preferred_label + selection_strategy - tell the node which region to auto-select. If a box's label matches preferred_label, it wins; otherwise it falls back to confidence or area selection.
  • select_index - the escape hatch: -1 auto-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_path points. Use the ONNX selector to guarantee a valid path.
  • Too many or too few boxes - that's confidence_threshold doing its thing. Tune it per image content; 0.25 is a floor, not a law.
  • Wrong region auto-selected - set preferred_label to your target class, or bypass auto-selection entirely with select_index.
Category✨ LF Nodes/Regions

Inputs (12)

NameTypeDefaultDescription
imageIMAGEImage tensor or batch to analyse.
model_pathONNX_PATHAbsolute path to a YOLO ONNX model (use LF_ONNXSelector; files live under ComfyUI/models/onnx).
model_labeloptONNX_DETECTOROptional label reported in metadata; defaults to the filename.
confidence_thresholdoptFLOAT0.250–1Discard detections below this confidence score.
iou_thresholdoptFLOAT0.450–1Intersection-over-Union threshold for non-maximum suppression.
max_regionsoptINT51–100Maximum number of regions to keep per image after NMS.
class_filteroptSTRINGOptional comma-separated list of class names or IDs to keep.
class_labelsoptSTRINGOptional class label override (comma, newline or JSON).
preferred_labeloptSTRINGFirst region whose label matches this string will be selected.
selection_strategyoptCOMBOconfidenceFallback strategy when auto-selecting a region.
select_indexoptINT-1-1–256Manually select the Nth region (after filtering). -1 chooses automatically.
ui_widgetoptLF_COMPARE[object Object]

Outputs (2)

NameTypeDescription
region_metaREGION_METADetected region metadata.
region_meta_listREGION_METAList of all detected region metadata.