ComfyUI Node

Smart Face Crop

Face-crop a whole dataset with zero downloads and zero heavy deps

By anstashhh·Created about a month ago·Updated about a month ago· 2
Smart Face Crop
  • image
  • IMAGE
  • status_log
io_modesingle_image
modeside_face_crop
target_size1024
pad_colorwhite
file_typejpg
input_folderpath/to/input/folder
output_folderpath/to/output/folder

Smart Face Crop is a one-node pack with one job: take images, find the face in each, and hand you back a clean square crop at a fixed resolution - or pad the image to a square if that's what you want instead. That's the classic dataset-prep move for a character LoRA or a reface workflow, where you want uniform, face-centered training crops rather than whatever aspect ratio your source photos happen to be. The whole pitch is spelled out in the README: no onnxruntime, no insightface, no model download. It's OpenCV alone, so it runs on any CPU box and it's 100% offline.

Let me be straight about one thing first: this is a tiny, essentially unknown pack - zero Google impressions, no community threads worth citing. It's not a miracle tool. But it does one narrow thing cleanly, and for a beginner who just wants square face crops without babysitting a heavy detection stack, that's genuinely useful.

How it works (the honest version)

Here's where the README is a little economical with the truth. It calls this "YuNet-based," and the repo even ships a models/face_detection_yunet_2023mar.onnx file. The code never loads it. The actual detector is OpenCV's bundled Haar cascade - haarcascade_frontalface_default.xml, a detector family that's been kicking around since the mid-2000s - loaded straight out of the opencv-python package. So "zero dependencies" is true, more true than the README means, since the detector comes inside the package itself.

That matters because Haar is old-school. It's fast and free, but it misses angled, small, or partially occluded faces far more often than modern RetinaFace or YuNet detectors would. The README's "flawless" is doing heavy lifting. When a face is found, the node centers a crop on it and resizes to target_size. When none is found it doesn't error - it falls back to a plain center crop and logs 0 faces found. Center crop applied. to status_log. You get a result either way, just a less useful one in the miss case.

The inputs that matter

  • mode - the four behaviors. side_face_crop (default) takes the largest square that fits the source and centers it on the detected face. zoom_face_crop is tighter - roughly 1.75x the face bounding box, the "crown to chin" close-up. extract_multiple_faces finds every face and outputs each as its own square. pad_to_square skips detection entirely and pads to a square with white or black borders instead.
  • target_size (INT, default 1024, range 64–8192, step 64) - the output resolution, always square. 1024 is the natural default for SDXL-era training; drop to 512 for SD 1.5 sets.
  • io_mode - single_image wires in an IMAGE tensor; batch_folder points at an input and output folder and processes every .jpg/.jpeg/.png/.webp in the top level.
  • pad_color and file_type only matter in specific modes (pad_to_square and batch mode respectively).

The outputs

IMAGE is your stacked crop tensor(s), always exactly target_size×target_size - wire it to SaveImage for one file per frame. status_log is a STRING with what happened: face counts, a done line in batch mode, or an error message. Errors come back as strings here rather than raising, so if you get a black image plus a status message, read the log.

One real gotcha: in single_image mode the node loops over every frame of the batch input, and extract_multiple_faces multiplies that - three faces in one photo means three outputs. That's intended, but it surprises people who assumed 1-in-1-out.

Installing

Via ComfyUI Manager, search "Smart Face Crop." Or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/anstashhh/ComfyUI-Smart-Face-Crop
cd ComfyUI-Smart-Face-Crop
pip install -r requirements.txt

Then restart ComfyUI. The only requirement is opencv-python, which nearly every ComfyUI install already has as a transitive dependency - so in practice it often works with no pip step at all. No model files needed; the bundled .onnx is dead weight.

The realistic complaint, if you do real dataset work at scale, is accuracy: Haar will silently give you center crops on profile shots, so spot-check your batch via status_log. But as a zero-download, one-node square-crop utility, this is exactly the tool it claims to be.

Categoryimage/transform

Inputs (8)

NameTypeDefaultDescription
io_modeCOMBOsingle_image2 options: single_image, batch_folder
modeCOMBOside_face_crop4 options: side_face_crop, pad_to_square, zoom_face_crop, extract_multiple_faces
target_sizeINT102464–8192
pad_colorCOMBOwhite2 options: white, black
file_typeCOMBOjpg2 options: jpg, png
input_folderSTRINGpath/to/input/folder
output_folderSTRINGpath/to/output/folder
imageoptIMAGE

Outputs (2)

NameTypeDescription
IMAGEIMAGE
status_logSTRING