Face Segmentation
January 19, 2026 · View on GitHub
Tip
The models and functionality in this repository are integrated into UniFace — an all-in-one face analysis library.
Face segmentation using XSeg model from DeepFaceLab with UniFace for face detection and alignment. Automatically detects faces and generates pixel-accurate segmentation masks.
Installation
pip install -r requirements.txt
Download Weights
Download the pre-trained XSeg ONNX model:
| Model | Size | Download |
|---|---|---|
| XSeg | 70 MB | xseg.onnx |
Place the downloaded model in the weights/ directory.
Usage
python main.py --model weights/xseg.onnx --image assets/einstien.png
Options:
| Argument | Default | Description |
|---|---|---|
--model | required | Path to XSeg ONNX model |
--image | assets/einstien.png | Input image path |
--output | None | Output image path |
--blur | 0 | Gaussian blur sigma for mask smoothing |
--align-size | 256 | Face alignment size |
Outputs
The script generates:
*_xseg_result.png- Image with mask overlay*_xseg_mask.png- Binary segmentation mask*_xseg_comparison.png- Side-by-side comparison*_aligned_crop.png- Aligned face crop
References
- UniFace - Face detection and alignment
- XSeg ONNX Model - Face Segmentation model used in DeepFaceLab