Nodes/ComfyUI_pixel_snapping/Face Hand Crop (YOLO)
ComfyUI Node

Face Hand Crop (YOLO)

Stop hand-drawing crop boxes around every face

By flywhale-666·Created 8 months ago·Updated 7 months ago· 58
Face Hand Crop (YOLO)
  • image
  • mask
  • cropped_image
  • face_mask
  • crop_mask_full
  • crop_info
  • face_count
model_path
max_faces3
start_face1
padding_ratio1.5
maskpadding_ratio1.5
face_position0.50
enable_resizefalse
target_width512
target_height512
padding_mode
size_multiple16

If you've ever had to draw a crop box around a face in a batch of fifty images, you know exactly why this node exists. Face Hand Crop (YOLO) looks at your image, finds the faces (or hands), and crops the one you actually want - with padding, optional resizing to a fixed size, and a mask you can reuse downstream. It's the "detect" and "crop" steps of an automated detailer, minus the re-render loop, and it plugs straight into the crop → process → restore chain this pack is built around.

It's one of five nodes in ComfyUI_pixel_snapping, and the only one with a real model dependency: it runs Ultralytics YOLOv8 for detection. The heavy lifting - finding the face - is done by a .pt model you supply, and the node takes care of cropping around the detection box with sensible padding.

How it works

The node runs a YOLO model over your image (confidence threshold 0.25), sorts the detections by bounding-box area from largest to smallest, and picks which one to crop. max_faces caps how many detections are considered and start_face selects which of them, 1-indexed - so start_face: 1 grabs the biggest face, start_face: 2 the second-biggest, and it wraps around if you ask for more than were found. padding_ratio (default 1.5) expands the crop around the detected box, and face_position (0 to 1) places the face vertically in the frame - 0 pins it near the top, 0.5 centers it, 1 drops it low.

The crop itself then goes through the same resize machinery as the pack's other crop node: enable_resize with a target width/height, padding_mode for black/white/none when the aspect doesn't match, and size_multiple rounding. Detection results are cached per model, so repeat runs don't re-load the weights.

The inputs that matter

  • model_path - a dropdown listing every .pt in ComfyUI/models/yolo. Drop in a face model (like face_yolov8m.pt, the README's example, or the community-standard face_yolov8n/s) or a hand model (e.g. hand_yolov8n/s) and pick it here.
  • max_faces and start_face - "how many to consider" and "which one to crop."
  • padding_ratio - how much context around the detection to include in the crop.
  • face_position - where the face sits inside the crop. Important when you're cropping for a fixed-aspect model.
  • mask (optional) - if you feed a mask, the face_mask and crop_mask_full outputs get limited to it, so you can exclude hair or background you don't want counted.

Outputs

  • cropped_image - the crop, ready for your processing step.
  • face_mask - a mask of the detected face region in the crop's coordinates. Note it's a rectangular box (sized by maskpadding_ratio), not a polygon - bbox masks show edges more easily if you use them as detail masks.
  • crop_mask_full - the same region in the original image's coordinates.
  • crop_info - feeds Powerful Mask Restore, same contract as the other crop node.
  • face_count - how many detections actually matched, which is handy for routing.

Install and gotchas

Install with the pack: ComfyUI Manager (search "Pixel Snapping") or:

cd ComfyUI/custom_nodes
git clone https://github.com/flywhale-666/ComfyUI_pixel_snapping
cd ComfyUI_pixel_snapping
pip install -r requirements.txt

Then restart. Two gotchas are worth knowing up front:

  • It requires CUDA. The code hard-aborts if no GPU is available - this node will not run CPU-only. Check your ComfyUI is running on an NVIDIA GPU before you build a workflow around it.
  • You must supply a model. The dropdown scans ComfyUI/models/yolo for .pt files; if the folder is empty you get a fallback label and the node errors with "Model not found" when it runs. Drop your .pt in there and pick it.

Also worth knowing: the ultralytics dependency is AGPL-3.0 licensed and carries real supply-chain history (a poisoned Ultralytics release in December 2024 shipped a cryptominer to ComfyUI users via a detailing node). Pin a known-good ultralytics version and be a bit careful about blind updates. If that gives you pause, for the face-only case Google's MediaPipe is the license-clean alternative - but it can't produce this node's hand detections, so the trade-off is yours.

Categoryimage/transform

Inputs (13)

NameTypeDefaultDescription
imageIMAGE
model_pathCOMBO1 options: face_yolov8m.pt
max_facesINT31–100
start_faceINT11–100
padding_ratioFLOAT1.50.5–10
maskpadding_ratioFLOAT1.50.5–10
face_positionFLOAT0.500–1
enable_resizeBOOLEANfalse
target_widthINT5120–16384
target_heightINT5120–16384
padding_modeCOMBO3 options: black, white, none
size_multipleINT161–999
maskoptMASK

Outputs (5)

NameTypeDescription
cropped_imageIMAGE
face_maskMASK
crop_mask_fullMASK
crop_infoCROP_INFO
face_countINT