r/comfyui • u/AIPnely • 6d ago
Workflow Included I built a single-node face swapper for ComfyUI around the AlphaFace 256 model and wanted to share it.
I built a face swapper for ComfyUI around AlphaFace 256. You give it a source image and a target image, and one node returns the swapped image and a mask you can use for compositing.
The feature I wanted most was a better blend around hair, ears, and anything crossing the face. I also tested it against ReActor to see what the better mask costs in speed.
What the node does
- Runs on ONNX Runtime. You don’t need to install ReActor, FaceFusion, or InsightFace.
- Supports CUDA, TensorRT, and CPU. If the provider you select fails to load, the node raises an error so you know which provider failed.
- Combines semantic and occlusion masks to preserve the target’s hair, ears, clothing, and objects in front of the face.
- Offers optional GPEN 512 restoration applied only to the swapped face.
- Processes batches, keeps the target resolution, and works headless through the ComfyUI API.
- Includes a model download script that verifies checksums.
Speed on an RTX 5090
I tested 1.6 MP images with one face per frame, in batches of 20.
| Setup | Images/sec |
|---|---|
| AlphaFace, box mask, TensorRT | 13.0 |
| AlphaFace, box mask, CUDA | 12.3 |
| ReActor, inswapper_128, no restoration | 10.8 |
| AlphaFace, semantic mask, TensorRT | 10.1 |
| AlphaFace, semantic mask, CUDA | 8.0 |
| ReActor, hyperswap_256, no restoration | 7.9 |
| AlphaFace, semantic mask + GPEN 512, TensorRT | 6.0 |
| AlphaFace, semantic mask + GPEN 512, CUDA | 4.7 |
| ReActor, inswapper_128 + GPEN 512 | 2.7 |
| ReActor, hyperswap_256 + GPEN 512 | 2.5 |
With the semantic mask and no restoration, AlphaFace was in the same ballpark as ReActor. With GPEN enabled, AlphaFace processed 4.7–6.0 images/sec versus 2.5–2.7 for the two ReActor setups.
TensorRT helped most with the semantic mask, giving me about 26–28% more throughput than CUDA after a one-time engine build of a few minutes. With the box mask, the gain was about 6%. VRAM use was around 5–6 GB at the default settings.
What looked good
- Full-profile and over-the-shoulder shots held up well in my tests. Edges stayed clean, and I didn’t see ghosting.
- The semantic mask made the biggest visible difference around collars, ears, and hairlines, where a box blend tended to bleed into the target.
- GPEN at 0.5 sharpened eyes, brows, and lips with little visible change to identity.
Where it struggled
- AlphaFace is native 256 px, so large faces looked soft without restoration.
- In my test, ArcFace identity similarity was 0.65 for AlphaFace and 0.78 for inswapper. At those face sizes, inswapper also looked blocky without restoration.
- Steep looking-down shots sometimes misplaced the mouth. Low angles generally held up, but extreme ones could leave a smear along the jaw.
- If the node can’t find a face in a frame, it raises an error. That’s worth knowing if you’re processing a batch.
The quality test covered four hard-angle portraits and two source faces on one machine, so these are first impressions.
Install
Run these commands from the directory containing your ComfyUI folder:
git clone https://github.com/freddiehdxd/ComfyUI-AlphaFace ComfyUI/custom_nodes/ComfyUI-AlphaFace
python ComfyUI/custom_nodes/ComfyUI-AlphaFace/download_models.pyRestart ComfyUI and look under the AlphaFace node category.
Licensing and credits
The node code is MIT-licensed. The model weights have separate terms, and several are listed as non-commercial, including the AlphaFace swapper, the ArcFace identity model, and GPEN. Those restrictions apply if you’re considering using this setup in a paid product. Please only swap faces of people who have agreed to it.
Credit to Yu et al. for AlphaFace and to FaceFusion for publishing the ONNX models this node uses.
I’ve only tested on Windows with an RTX 5090. If you try it on Linux, another GPU, or a card with less VRAM, I’d love to hear which provider you used and what speed and VRAM usage you saw.
2
u/MyOtherSide1984 5d ago
New to comfy and all this, and looking forward to giving this a shot, but holy hell...a 5090 can process images per second!? My 3060 12gb is doing minutes per image 🤣
1
u/lilud2210 5d ago
How does the occlusion mask hold up when the source face has significant beard or jawline hair that partially overlaps the target's collar, does the semantic pass actually separate those layers cleanly, or does it bleed at the boundary?
1
u/ramonartist 5d ago
So no comparison images?