ComfyUI Node

YOLOv8 Object Detection

Give it an image, get back every object as its own cropped image

By mangobyed·Created about a year ago·Updated about a year ago· 1
YOLOv8 Object Detection
  • image
  • detected_objects
  • object_count
  • class_names
  • detection_info
model_nameyolov8n.pt
confidence_threshold0.25
iou_threshold0.45
padding10
custom_model_path
max_size512
preserve_aspect_ratiotrue
exclude_persontrue
exclude_animalsfalse
exclude_vehiclesfalse
min_confidence0.30

You know the annoying part of a workflow where you need the mug, every face, or each car in a street shot turned into its own separate image? That's this node. Feed it a picture, and it runs a YOLOv8 detector and hands you back a batch of cropped objects - one image per detection - plus a count, the class names, and per-box confidence. It's the extraction half of the detect-crop-refine loop that Impact Pack's FaceDetailer and A1111's ADetailer made famous, except it stops after the crop. No re-diffusion, no mask cleanup, just "here are your objects."

It's also the only node in the pack, which is worth knowing: the repo is MIT-licensed and ships exactly one class, YOLOv8ObjectDetectionNode, hiding under the category image/object_detection.

How it works

Under the hood it's the Ultralytics library doing the real work. The node converts your ComfyUI tensor to a PIL image, runs a YOLOv8 model (auto-downloading yolov8n.pt from Ultralytics on first use - no manual model hunting), filters the boxes by your confidence and IoU thresholds, crops each one with a few pixels of padding, and concatenates the results into a single batch tensor.

Three quirks from the source are worth knowing before you get confused by output.

It only looks at the first frame. tensor_to_pil takes image[0], so if you feed it a batch of ten photos it processes the first and ignores the rest. Single image in, batch of crops out.

There are two confidence knobs and the effective one is the max. confidence_threshold defaults to 0.25, but min_confidence defaults to 0.3, and the code uses max(confidence_threshold, min_confidence). So lowering confidence_threshold below 0.3 does nothing until you also drop min_confidence. This trips up more people than it should.

People are excluded by default. exclude_person is True out of the box, which means a portrait shot returns zero detections the first time you run it. Flip that off unless you're deliberately hunting for objects around people.

The inputs that matter

  • model_name - yolov8n.pt (nano, fast) through yolov8x.pt (extra-large, slow, best). Nano is fine for most workflows; grab s or m if you're doing detailed crops.
  • confidence_threshold - lower it (with min_confidence) to catch more objects and more false positives.
  • padding - extra pixels around each crop, so you don't clip the edges of objects. 10 is a decent default.
  • exclude_person / exclude_animals / exclude_vehicles - toggle COCO class families off. Handy for "find everything except the people" data cleanup.
  • custom_model_path - point it at a fine-tuned YOLOv8 .pt if you trained one.

Outputs: detected_objects (an IMAGE batch - wire this to SaveImage, a preview, or an upscaler), plus object_count (INT), class_names (comma-separated STRING), and detection_info (per-object STRING like "Object 1: car (conf: 0.871)") for logging or text display.

Install

ComfyUI Manager can find it under the pack title "ComfyUI YOLOv8 Object Detection Node." Manual, which is what the README leads with:

cd ComfyUI/custom_nodes
git clone https://github.com/mangobyed/ComfyUI_Detection_List.git
cd ComfyUI_Detection_List
pip install -r requirements.txt   # or run install.sh / install.bat

Then restart ComfyUI. The heavy dependency is ultralytics (plus torch/torchvision/OpenCV), which installs a lot of packages on its own. One licensing note from the KB, since it bites people later: Ultralytics is AGPL-3.0 and it covers the YOLO weights, not just the code - so if you're building a commercial product around YOLO crops, that's a real consideration even though this pack itself is MIT.

Troubleshooting

  • Nothing detected on people - that's exclude_person (see above). Everyone hits this once.
  • "Sizes of tensors must match" - this was the pack's original bug, since fixed with shape standardization. If you still see it, the TROUBLESHOOTING.md says restart ComfyUI completely and git pull origin main; the fix logs "Successfully created batch tensor" to the console.
  • No detections at all - lower confidence_threshold and min_confidence; the two-knob max is almost always the culprit.
  • Black bars on your crops - crops are letterboxed to a uniform size (padded to max_size, 512 by default, with preserve_aspect_ratio on). Fine for saving and upscaling, but if you feed them into inpainting the black padding can leak into the mask. Bump max_size or disable aspect preservation.
  • Keep Ultralytics updated. A December 2024 supply-chain incident where a compromised Ultralytics pip release shipped a cryptominer reached ComfyUI through packs that depend on it (Impact Pack documented it), so pip install -U ultralytics is a good habit.

It's a small, quiet node with essentially no community footprint. But if your job is "extract every object from an image," it does exactly that with almost no setup.

Categoryimage/object_detection

Inputs (12)

NameTypeDefaultDescription
imageIMAGE
model_nameCOMBOyolov8n.pt5 options: yolov8n.pt, yolov8s.pt, yolov8m.pt, yolov8l.pt, yolov8x.pt
confidence_thresholdFLOAT0.250–1
iou_thresholdFLOAT0.450–1
paddingINT100–100
custom_model_pathoptSTRING
max_sizeoptINT512128–1024
preserve_aspect_ratiooptBOOLEANtrue
exclude_personoptBOOLEANtrue
exclude_animalsoptBOOLEANfalse
exclude_vehiclesoptBOOLEANfalse
min_confidenceoptFLOAT0.300.1–0.9

Outputs (4)

NameTypeDescription
detected_objectsIMAGE
object_countINT
class_namesSTRING
detection_infoSTRING