Torch(MTCNN) 图像人脸马赛克
Better detection, tiny footprint
- image
- IMAGE
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.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mosaic_size | INT | 205–100 | — |
| mosaic_type | COMBO | 3 options: pixelate, blur, black_box | |
| use_gpu | BOOLEAN | true | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |