Tip
The models in this repository are integrated into UniFace, an all-in-one face analysis toolkit.
PyTorch and ONNX Runtime inference for the PaddleSeg portrait matting models (PP-Matting paper). Works on images, videos and webcam feeds.
Mattes predicted by ppmatting_v2.onnx. Photos from UniFace's demo set.
PyTorch checkpoints and the ONNX exports built from them. Download via bash download.sh or from Releases.
| Model | Backbone | Params | SAD | PyTorch | ONNX |
|---|---|---|---|---|---|
| PP-MattingV2 | STDC1 | 8.95M | 40.59 | pt | onnx |
| PP-Matting | HRNet-W18 | 24.5M | 31.56 | pt | onnx |
The weights are PaddleSeg's released human_512 weights converted to PyTorch, and the ONNX files reproduce PaddleSeg's published scores. PP-MattingV2 is the fast one, PP-Matting the accurate one (SAD on PPM-AIM-195, lower is better). Both take an RGB image in [-1, 1] with sides that are multiples of 32 and return an alpha matte in [0, 1]; the scripts handle the resizing.
pip install -r requirements.txt
bash download.sh # Download model weights# PyTorch
python main.py --source assets/inputs/src_img1.jpg --output results/
python main.py --source video.mp4 --model ppmatting_v1 --background bg.jpg --output out.mp4
python main.py --source 0
# ONNX Runtime
python onnx_inference.py --source assets/inputs/src_img1.jpg --weights weights/ppmatting_v2.onnx --output results/
python onnx_inference.py --source video.mp4 --weights weights/ppmatting_v1.onnx --background bg.jpg --output out.mp4
python onnx_inference.py --source 0 --weights weights/ppmatting_v2.onnxAn image gives the matte, a green-screen composite and an RGBA cutout. A video or webcam feed is composited over --background, or over green.
import cv2
from model import PPMattingONNX
model = PPMattingONNX('weights/ppmatting_v2.onnx')
alpha = model.predict(cv2.imread('assets/inputs/src_img1.jpg')) # (H, W) float32 in [0, 1]onnx_export.py converts a .pt checkpoint to ONNX with dynamic batch, height and width.
python onnx_export.py --model ppmatting_v2 --simplify
python onnx_export.py --model ppmatting_v1 --simplify- PaddleSeg Matting, the original implementation and weights.
- UniFace, face analysis toolkit that ships these models.


