Nodes/ComfyUI-yolov5-face/Yolov5 Face Detect
ComfyUI Node

Yolov5 Face Detect

No API key, no drama — but know what it's actually for

By JiSenHua·Created about a year ago·Updated 3 months ago· 3
Yolov5 Face Detect
  • image
  • marked_image
  • face_crop
weights_nameyolov5s-face.pt
expand_ratio1.0
offset_x0.00
offset_y0.00

Yolov5 Face Detect is a small, honest face-finder: it looks at your image, picks one face, draws a green box around it, and hands you a square 512×512 crop of just that face. No API key, no external service, nothing running in the cloud - the detection happens locally with a YOLOv5-face model. If your workflow needs a clean face crop to feed into an IPAdapter face-fidelity pass, a face swap, or an InstantID reference, this is one of the least fussy ways to get one.

Just be clear-eyed about the scope, because the name oversells it slightly. This is a detector and cropper, not a detailer. The classic "detect → crop → re-render → paste back" loop that fixes mangled faces (the whole FaceDetailer thing in the Impact Pack) is not what this node does - it stops after the crop. If you want the loop, you want Impact Pack. If you just need the crop, read on.

How it works

Under the hood it's the deepcam-cn/yolov5-face fork of YOLOv5. The node loads whatever .pt you point it at, letterboxes your image to 640×640, runs the model, and applies non-max suppression at 0.25 confidence. Then comes the part people don't expect: instead of returning every face, it scores each detection on how centered and reasonably sized it is (roughly 70% centering, 30% size) and keeps only the best one. A crowd photo gives you exactly one box and one crop - the most camera-facing face. For most people feeding an IPAdapter reference that's actually what you want; just don't come back wondering why only one person got cropped.

The crop itself is a square centered on the face, sized to max(face width, face height) × expand_ratio, then resized to 512×512. It keeps whatever background was in that square, so you're getting a face + surroundings region, not a tight mask.

The inputs that matter

Five inputs, and you'll actually touch three of them:

  • image - your IMAGE tensor, straight from Load Image.
  • weights_name - dropdown of .pt/.pth files in ComfyUI/models/yolov5. Defaults to yolov5s-face.pt, which is the sensible pick; n is smaller/faster, m/l more accurate.
  • expand_ratio (1–3, default 1) - how much room around the face. 1.0 is exactly the detection box, which crops tight and can clip hair and chin. I default to ~1.5–2.0 for more context, which plays much better if the crop feeds a re-render or an identity pass.
  • offset_x / offset_y (−1 to 1, relative to face size) - nudges the crop center off the geometric center, useful when the detection box sits a bit low and keeps clipping the chin.

Outputs and what to wire them into

Two IMAGE outputs: marked_image (your original with a green box on the chosen face) and face_crop (the 512×512 square). The crop is the useful one - wire it into an IPAdapter or InstantID image input, a face-swap reference, or an img2img denoise pass. marked_image is mostly for eyeballing that it found the right face.

Installing it

Clone it in, install the requirements, restart. That's the whole install:

cd ComfyUI/custom_nodes
git clone https://github.com/JiSenHua/ComfyUI-yolov5-face
cd ComfyUI-yolov5-face
pip install -r requirements.txt

ComfyUI Manager can do the clone part if you search "yolov5-face". Note that requirements.txt is the full YOLOv5 stack - torch, torchvision, opencv, numpy, ultralytics>=8.2.64 and friends - so on a fresh install it's not trivially light. Worth knowing the YOLO/Ultralytics path is AGPL-3.0 licensed, which matters if you're shipping anything, and that the Ultralytics ecosystem had a supply-chain scare in late 2024 - pin your versions if you're cautious.

The models do not auto-download. Nothing fetches weights for you. Grab yolov5s-face.pt (or any of yolov5n-0.5, yolov5n, yolov5m, yolov5l) from the deepcam-cn/yolov5-face repo and drop it into ComfyUI/models/yolov5/ (create the folder - the node makes it if missing).

Where people get burned

  • "model not found" on first run - the dropdown always shows yolov5s-face.pt even before you've placed the file; selecting it without the weight sitting in models/yolov5 raises a FileNotFoundError. Install the model first, then select it.
  • A black 512×512 crop - that's the "no face found" sentinel: the node returns a black image for face_crop and your original, unboxed, for marked_image. Profile or extreme angles on small faces will do this.
  • The 512×512 fixed size - the crop is always resized to 512, so if you need the face at original resolution you'll have to upscale it yourself. Fine for a reference input; not great as a deliverable.
CategoryComfyUI-yolov5-face

Inputs (5)

NameTypeDefaultDescription
imageIMAGEInput image to detect faces from.
weights_nameCOMBOyolov5s-face.ptSelect the YOLOv5 face detection model to use.
expand_ratioFLOAT1.01–3Expansion ratio for face cropping. 1.0 = original face box, 2.0 = double the size.
offset_xFLOAT0.00-1–1Horizontal offset for face cropping. Positive = right, negative = left. Range is relative to face size.
offset_yFLOAT0.00-1–1Vertical offset for face cropping. Positive = down, negative = up. Range is relative to face size.

Outputs (2)

NameTypeDescription
marked_imageIMAGE
face_cropIMAGE