Face Segmentation

January 19, 2026 · View on GitHub

Python License Downloads

Tip

The models and functionality in this repository are integrated into UniFace — an all-in-one face analysis library. PyPI Version GitHub Stars License

Face segmentation using XSeg model from DeepFaceLab with UniFace for face detection and alignment. Automatically detects faces and generates pixel-accurate segmentation masks.

Face Segmentation Result

Installation

pip install -r requirements.txt

Download Weights

Download the pre-trained XSeg ONNX model:

ModelSizeDownload
XSeg70 MBxseg.onnx

Place the downloaded model in the weights/ directory.

Usage

python main.py --model weights/xseg.onnx --image assets/einstien.png

Options:

ArgumentDefaultDescription
--modelrequiredPath to XSeg ONNX model
--imageassets/einstien.pngInput image path
--outputNoneOutput image path
--blur0Gaussian blur sigma for mask smoothing
--align-size256Face 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

License

GNU General Public License v3.0