ComfyUI Node

YOLO Detection

Find objects and get masks you can actually route into the graph

By gasdyueer·Created 12 months ago·Updated 11 months ago· 0
YOLO Detection
  • image
  • PLOTTED_IMAGE
  • SINGLE_COMBINED_MASK
  • ALL_INDIVIDUAL_MASKS
  • DETECTIONS_JSON
model_name
confidence_threshold0.50
filter_single_mask_by_class_id0
use_class_name_for_single_maskfalse
class_name_for_single_mask
smooth_masksfalse
smooth_sigma1.0
force_output_masktrue

Most detection nodes in ComfyUI hand you a box and make you figure out the rest. This one, "YOLO Detection" (class YoloDetectionAndSegmentation), is the opposite: you drop in an image, pick a YOLOv8 model, and get back the annotated preview, a single combined mask, every individual instance mask, and a JSON dump of what it found - all in one pass, all running locally. No API calls, no keys, no cloud round-trip. The name is a lie in the good direction: it's actually two jobs (detection and segmentation) in one node.

Why reach for it over the usual suspects? YOLO is the same class-based detection engine that powers ADetailer and Impact Pack's FaceDetailer, but those tools are built for one narrow loop - detect a face, crop, inpaint. This node is generic: it turns objects (person, car, dog, whatever the model knows) into masks you can feed anywhere. Blur out bystanders, mask a subject for inpainting, restrict a regional pass to "everything that isn't a person." Because it's class-driven, you don't prompt it the way you do SAM - you just ask for class person and get every person in frame. Fast and predictable, at the cost of only knowing what the model was trained on.

How it works

Under the hood it's straightforward Ultralytics. The node loads a .pt file from your YOLO_MODEL folder, runs model(image, conf=...), then handles the bookkeeping: converts BGR to RGB, resizes segmentation masks to your input size with bilinear interpolation, and builds a per-object JSON with class id, class name, confidence, box coordinates, and whether a mask exists.

Two behaviors worth knowing. First, the force_output_mask toggle (default on): if you're running a plain detection model with no segmentation support, it generates masks from the bounding boxes instead of returning nothing. Handy, but you're getting rectangles, not silhouettes - grab a -seg model if you want actual shapes. Second, the smooth_masks option runs a scipy Gaussian filter over the masks and re-thresholds them, which softens the harsh pixel edges YOLO segmentation tends to leave behind.

The inputs that matter

Most inputs are defaults you'll never touch. The ones you will:

  • confidence_threshold (default 0.5) - how sure the model has to be before it reports a hit. Getting empty masks? Drop this to 0.2–0.3. Too many false positives? Raise it.
  • filter_single_mask_by_class_id + use_class_name_for_single_mask + class_name_for_single_mask - this trio controls the combined mask output. Use the name filter and type person, or flip the toggle off and set the class id directly. Matching is case-insensitive, and the name must be a class the model knows (COCO names like person, car, dog).
  • force_output_mask - leave it on unless you're deliberately testing whether a model produces real segmentation masks.

The outputs

Four of them: PLOTTED_IMAGE (the input with boxes and labels drawn on), SINGLE_COMBINED_MASK (everything from one class merged into one mask), ALL_INDIVIDUAL_MASKS (every instance as its own mask), and DETECTIONS_JSON (the metadata). The natural wiring: feed SINGLE_COMBINED_MASK into the pack's sibling node, Mask Process, to blur or mosaic what was detected - or pipe it into any inpaint workflow. The JSON is for debugging and scripting more than for a typical generation graph.

Installing it

Install the whole pack once - both nodes ship together. Easiest is ComfyUI Manager: search "ComfyUI YOLO Mask Process". Or by hand:

cd ComfyUI/custom_nodes
git clone https://github.com/gasdyueer/comfyui-yolo-mask-process.git
cd comfyui-yolo-mask-process
pip install -r requirements.txt

Then put the weights where the node looks for them, ComfyUI/models/YOLO_MODEL/:

mkdir -p ComfyUI/models/YOLO_MODEL
wget https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n-seg.pt -O ComfyUI/models/YOLO_MODEL/yolov8n-seg.pt
wget https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8s-seg.pt -O ComfyUI/models/YOLO_MODEL/yolov8s-seg.pt

yolov8n-seg is fast and fine to start with; yolov8s-seg is the balanced pick. The heavy dependency is ultralytics, which pulls in torch and torchvision - ComfyUI already has those, so the install is usually painless. Note the README asks for Python 3.11+.

The two things people get burned by

Licensing and supply chain, not the node itself. Ultralytics (code and YOLO weights) is AGPL-3.0, which matters if you're building a hosted or commercial service on top of it - that clause reaches anyone serving over a network. And in December 2024 a compromised Ultralytics release shipped a cryptominer; the same dependency powers Impact Pack, which is how it reached ComfyUI users. For a hobbyist running local workflows this is background noise, but if you pin dependencies for anything you ship, pin a known-good ultralytics version and don't let it float.

The model decides what you get. A plain yolov8n.pt cannot produce real segmentation masks - force_output_mask saves you from an empty output, but the masks will be boxes. And if detections come back empty, it's almost always the confidence threshold or an object the model wasn't trained on, not a bug. Check DETECTIONS_JSON to see what's actually being found before you go hunting for problems.

Categoryyolo-mask-process

Inputs (9)

NameTypeDefaultDescription
imageIMAGE
model_nameCOMBO0 options:
confidence_thresholdFLOAT0.500–1
filter_single_mask_by_class_idINT0
use_class_name_for_single_maskBOOLEANfalse
class_name_for_single_maskSTRING
smooth_masksBOOLEANfalse
smooth_sigmaFLOAT1.00–10
force_output_maskBOOLEANtrue

Outputs (4)

NameTypeDescription
PLOTTED_IMAGEIMAGE
SINGLE_COMBINED_MASKMASK
ALL_INDIVIDUAL_MASKSMASK
DETECTIONS_JSONJSON