Ported weights and clean inference codebase for MODNet: Real-Time Trimap-Free Portrait Matting via Objective Decomposition (AAAI 2022). Provides both PyTorch and ONNX Runtime inference for images, videos, and webcam feeds.
Tip
The models and functionality in this repository are integrated into UniFace — an all-in-one face analysis toolkit.
| Input | Matte | Green Screen | RGBA |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
pip install -r requirements.txtpython main.py --source image.jpg --model weights/modnet_photographic.pt --output results/python main.py --source image.jpg --model weights/modnet_photographic.pt --background bg.jpg --output results/python main.py --source video.mp4 --model weights/modnet_photographic.pt --background bg.jpg --output out.mp4python main.py --source 0 --model weights/modnet_webcam.ptNo PyTorch dependency -- only onnxruntime and opencv-python.
python onnx_inference.py --source image.jpg --model weights/modnet_photographic.onnx --output results/
python onnx_inference.py --source video.mp4 --model weights/modnet_photographic.onnx --background bg.jpg --output out.mp4
python onnx_inference.py --source 0 --model weights/modnet_webcam.onnxpython -m utils.export_onnx --weights weights/modnet_photographic.pt --output weights/modnet_photographic.onnx
python -m utils.export_onnx --weights weights/modnet_webcam.pt --output weights/modnet_webcam.onnx --simplifyWeights ported from the official repository. Model weights are licensed under Apache 2.0 by the original authors.
| Model | Size | Download |
|---|---|---|
| MODNet Photographic | 25 MB | PyTorch | ONNX |
| MODNet Webcam | 25 MB | PyTorch | ONNX |
Based on MODNet by Zhanghan Ke















