The first step of the project is to detect a face region of the input image and normalize the images for future processing. We have adopted OpenCV DNN Facedetector. And based on the detection result the original image will be normalized as (512,512) size.
The next step is to segment the image into several parts such as background, body, hat, and hair region. By used BiseNet architecture and Pytorch Framework we have built the segmentation model.
You can download face-parsing pre-trained model and save it in models
, rename it as 'segmentation.pth'.
Based on the segmented result, we have prepared the tripmap image for image matting. By used VGG16 architecture and Pytorch Framework we have built the matting model.
You can download matting pre-trained model and save it in models
, rename it as 'matting.pth'.
You have to prepare the images for testing, and copy them into the “images” folder. The result file will be saved in the “result” folder.
# evaluate using CPU
python test.py
Original Image | Segmented and Alpha Image | Composition Image |
---|---|---|