MODNet: Trimap-Free Portrait Matting in Real Time

MODNet is a model for real-time portrait matting with only RGB image input.

News: We create a repository for our new model MODNet-V that focuses on faster and better portrait video matting.
News: The PPM-100 benchmark is released in this repository.

Online Solution (在线方案)

The online solution for portrait matting is coming!

Portrait Image Matting Solution (图片抠像方案)

A Single Model! Only 7M! Process 2K resolution image with a Fast speed on common PCs or Mobiles!

Now you can try our portrait image matting online via this website.

Research Demo

All the models behind the following demos are trained on the datasets mentioned in our paper.

Portrait Image Matting

We provide an online Colab demo for portrait image matting.
It allows you to upload portrait images and predict/visualize/download the alpha mattes.

Portrait Video Matting

We provide two real-time portrait video matting demos based on WebCam. When using the demo, you can move the WebCam around at will.
If you have an Ubuntu system, we recommend you to try the offline demo to get a higher fps. Otherwise, you can access the online Colab demo.
We also provide an offline demo that allows you to process custom videos.


We share some cool applications/extentions of MODNet built by the community.

  • WebGUI for Portrait Image Matting
    You can try this WebGUI (hosted on Gradio) for portrait image matting from your browser without code!

  • Colab Demo of Bokeh (Blur Background)
    You can try this Colab demo (built by @eyaler) to blur the backgroud based on MODNet!

  • ONNX Version of MODNet
    You can convert the pre-trained MODNet to an ONNX model by using this code (provided by @manthan3C273). You can also try this Colab demo for MODNet image matting (ONNX version).

  • TorchScript Version of MODNet
    You can convert the pre-trained MODNet to an TorchScript model by using this code (provided by @yarkable).

  • TensorRT Version of MODNet
    You can access this Github repository to try the TensorRT version of MODNet (provided by @jkjung-avt).

There are some resources about MODNet from the community.


We provide the code of MODNet training iteration, including:

  • Supervised Training: Train MODNet on a labeled matting dataset
  • SOC Adaptation: Adapt a trained MODNet to an unlabeled dataset

In the code comments, we provide examples for using the functions.

PPM Benchmark

The PPM benchmark is released in a separate repository PPM.


All resources in this repository (code, models, demos, etc.) are released under the Creative Commons Attribution NonCommercial ShareAlike 4.0 license.
The license will be changed to allow commercial use after our paper is accepted.



If this work helps your research, please consider to cite:

  author = {Zhanghan Ke and Kaican Li and Yurou Zhou and Qiuhua Wu and Xiangyu Mao and Qiong Yan and Rynson W.H. Lau},
  title = {Is a Green Screen Really Necessary for Real-Time Portrait Matting?},
  year = {2020},


This repository is currently maintained by Zhanghan Ke (@ZHKKKe).
For questions, please contact [email protected].


View Github