Home

Awesome

Fast Portrait Segmentation

Portrait Segmentation is a common front-end task for many application as proprocessing process. This project provide a simple portrait segmentation api for developer to "plugin and play". This project is base on MNN inference engine.

This project is for the function of dynamic background in online-course application.

The solution model based on SINET, which is a extreme light-weight model for portrait segmentation.

Another solution is base on Depth Map Prediction from single image, which should get more stable result. The solution is in developing and will come out soon.

Requirement

This project is developed on VS2019 and only test on Windows. We now provide CMAKELIST to support multi-platform by cmake.

The project can run the realtime segmentation on relatively low-level cpu (i3-4300U with 4GB memory) with only around 30%-40% cpu usage.

Demo

Python demo and C++ demo is given in the project. The python demo is in folder pyFaceSeg. C++ demo is FaceSeg.exe or FaceSeg on different system

Python Demo

Python demo is the intermediate outcome from developing C++ demo. Start from pytorch model (origin SINet), the weight should be convert to onnx first, then use convert tools (mnnconvert.py) given by mnn to convert the model to mnn format.<br>

File list

Run python demo

pip install -r requirements
python cam_seg.py 

C++ Demo

The minimal requirement file for runing demo is given in folder /x64/Run.

Build demo on Windows

An executable file FaceSeg.exe and a dll file FaceSegDll.dll can be found in x64/Release/.

Build demo on Linux

 cd /path/to/project
 mkdir build
 cd build
 cmake -DMNN_INCLUDE_DIRS=/path/to/MNN/inc -DMNN_LIBRARY_DIRS=/path/to/MNN.so
 make -j2

Run demo

For Windows, copy FaceSeg.exe and FaceSegDll.dll in x64/Run. Then open the powershell and run by script

cd path/to/project/Release/Run
./FaceSeg.exe --help

For Linux, copy FaceSeg.exe and FaceSegDll.dll in x64/Run. Then open Termial and run

cd path/to/project/Release/Run
./FaceSeg --help

The help information will show on control panel:

./FaceSeg.exe $thread $blur_r $private_level
thread: [1-4] the number of thread used when do infer
blur_r: [2i+1] radius of blur kernel, 7-15 will get proper result
private_level: [0-4]: level of privacy

Demo example

demo

DLL

The all-in-one dll file is FaceSegDll.dll. Read the head file model.h and process.h for detail.