Nodes/face_mosaic/Torch(MTCNN) 图像人脸马赛克
ComfyUI Node

Torch(MTCNN) 图像人脸马赛克

Better detection, tiny footprint

By yzzky·Created 12 months ago·Updated 12 months ago· 0
Torch(MTCNN) 图像人脸马赛克
  • image
  • IMAGE
◄mosaic_size20►
◄mosaic_type▾►
◄use_gputrue►

If you've got a still image with faces at awkward angles and the pack's plain Haar-based image node keeps missing half of them, this is the upgrade that doesn't drag in the whole deep-learning face-swap stack. It's MTCNN - the three-stage CNN cascade - running through PyTorch, applied to a single image. In the menu: Torch(MTCNN) 图像人脸马赛克 under YZZ_Face_Mosaic/Torch.

How it works

The node builds an MTCNN detector from facenet_pytorch (with keep_all=True so it returns every face, not just the strongest one), picks CUDA if use_gpu is on and available, converts your IMAGE tensor to an OpenCV array, and runs detection once. Every box gets pixelate, blur, or black_box. Result comes back as a standard IMAGE tensor - same shape as what went in - ready for Preview Image, Save Image, or anything downstream. No files, no waiting.

Inputs and output

  • image - any IMAGE tensor.
  • use_gpu - on by default; only actually uses CUDA when present. For a single frame this toggle barely matters.
  • mosaic_size - block size (pixelate) or blur strength.
  • mosaic_type - the usual pixelate / blur / black_box.

Output is a single IMAGE. That's the whole node - it's genuinely simple.

Installing it - the part that trips people

MTCNN ships via facenet-pytorch, which the pack's requirements.txt does not include. The failure mode is a quiet one: run the node without it and the console logs "facenet-pytorch 未安装", the detector returns nothing, and your image comes back with no mosaic and no error dialog. Install it and restart:

pip install facenet-pytorch

The pack itself comes via ComfyUI Manager (yzz_face_mosaic) or git clone https://github.com/yzzky/yzz_face_mosaic into custom_nodes + pip install -r requirements.txt.

Where it bites

MTCNN handles angles and lighting that Haar can't, but heavily rotated faces and truly tiny faces in crowds still escape it - eyeball the output before you trust it for anything compliance-related. And it's slower per image than the CPU node, though still under a second or two on most hardware. One more thing: this node mosaics everyone it finds. When you need to pick out one person from a crowd, the pack's Selective nodes do that; when you need the best raw detection, the InsightFace GPU node wins. This one is the practical default for a single awkward image.

CategoryYZZ_Face_Mosaic/Torch

Inputs (4)

NameTypeDefaultDescription
imageIMAGE—
mosaic_sizeINT205–100—
mosaic_typeCOMBO3 options: pixelate, blur, black_box
use_gpuBOOLEANtrue—

Outputs (1)

NameTypeDescription
IMAGEIMAGE—