Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MODNet: Trimap-Free Portrait Matting in Real Time

Downloads GitHub Repo stars License

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.
PyPI Version GitHub Stars License

InputMatteGreen ScreenRGBA

Installation

pip install -r requirements.txt

Usage

Image Inference

python main.py --source image.jpg --model weights/modnet_photographic.pt --output results/

Image with Custom Background

python main.py --source image.jpg --model weights/modnet_photographic.pt --background bg.jpg --output results/

Video Inference

python main.py --source video.mp4 --model weights/modnet_photographic.pt --background bg.jpg --output out.mp4

Webcam Inference

python main.py --source 0 --model weights/modnet_webcam.pt

ONNX Inference

No 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.onnx

ONNX Export

python -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 --simplify

Model Weights

Weights 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

Reference

Based on MODNet by Zhanghan Ke

License

Apache License 2.0

About

MODNet: Real-Time Trimap-Free Portrait Matting via Objective Decomposition (AAAI 2022) | ONNX Runtime | PyTorch Inference

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages