Metadata-Version: 2.1
Name: face-parsing
Version: 0.1
Summary: This repo is used to generate semantic segmentation for face image
Home-page: https://github.com/sword4869/face_parsing
Author: sword4869
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: configargparse
Requires-Dist: opencv-contrib-python
Requires-Dist: numpy
Requires-Dist: pillow
Requires-Dist: tqdm
Requires-Dist: torch
Requires-Dist: torchvision

 [README_ZH.md](README_ZH.md)  [README.md](README.md) 

# Description

This repo is used to generate semantic segmentation for face image.

# Output
```
├── pretrain
│   └── 79999_iter.pth      # ckpt
├── test_img            # input
│   ├── 00000.jpg
│   └── 116_ori.png
└── test_res                # output
    ├── merge_00000.png             # merge masks
    ├── merge_116_ori.png
    ├── weighted_00000.png          # weighted original
    ├── weighted_116_ori.png
    ├── parsing_00000.png           # classification result, each pixel value is [0, 18]
    ├── parsing_116_ori.png
    └── masks                       # masks for each part
        ├── 00000
        │   ├── background.png
        │   ├── eye_g.png
        │   ├── hair.png
        │   ├── hat.png
        └── 116_ori
            ├── background.png
            ├── ear_r.png
            ├── eye_g.png
            ├── hair.png
```
```python
pip install -e .

# Inside the `face_parsing` directory
$ face_parsing

# Outside the `face_parsing` directory
$ face_parsing --ckpt 79999_iter.pth --res_path test_res --img_path test_img
```
The generating script is `segment.py`. It will output the segmentaion images to the specific folder(`test_res` by default).

`masks`: only show recognized part.

color1 from face-parsing.PyTorch code,

color2 from `CelebAMask-HQ` colors in `CelebAMask-HQ/face_parsing/Data_preprocessing/g_color.py`

| Index |    Name    |    Color1     |    Color2     |
| :---: | :--------: | :-----------: | :-----------: |
|   0   | background |   255, 0, 0   |    0, 0, 0    |
|   1   |    skin    |  255, 85, 0   |   204, 0, 0   |
|   2   |    nose    |  255, 170, 0  |  76, 153, 0   |
|   3   |   eye_g    |  255, 0, 85   |  204, 204, 0  |
|   4   |   l_eye    |  255, 0, 170  |  51, 51, 255  |
|   5   |   r_eye    |   0, 255, 0   |  204, 0, 204  |
|   6   |   l_brow   |  85, 255, 0   |  0, 255, 255  |
|   7   |   r_brow   |  170, 255, 0  | 255, 204, 204 |
|   8   |   l_ear    |  0, 255, 85   |  102, 51, 0   |
|   9   |   r_ear    |  0, 255, 170  |   255, 0, 0   |
|  10   |   mouth    |   0, 0, 255   |  102, 204, 0  |
|  11   |   u_lip    |  85, 0, 255   |  255, 255, 0  |
|  12   |   l_lip    |  170, 0, 255  |   0, 0, 153   |
|  13   |    hair    |  0, 85, 255   |   0, 0, 204   |
|  14   |    hat     |  0, 170, 255  | 255, 51, 153  |
|  15   |   ear_r    |  255, 255, 0  |  0, 204, 204  |
|  16   |   neck_l   | 255, 255, 85  |   0, 51, 0    |
|  17   |    neck    | 255, 255, 170 | 255, 153, 51  |
|  18   |   cloth    |  255, 0, 255  |   0, 204, 0   |

![image-20240702214442271](https://cdn.jsdelivr.net/gh/sword4869/pic1@main/images/202407022144311.png)

![image-20240702214108718](https://cdn.jsdelivr.net/gh/sword4869/pic1@main/images/202407022141752.png)

![image-20240702214100671](https://cdn.jsdelivr.net/gh/sword4869/pic1@main/images/202407022141703.png)

# Reference

> folk from https://github.com/zllrunning/face-parsing.PyTorch, https://github.com/dw-dengwei/face-seg

1. [Code: BiSeNet](https://github.com/CoinCheung/BiSeNet)
2. [Paper: BiSeNetV1](https://arxiv.org/abs/1808.00897)
3. [Paper: BiSeNetV2](https://arxiv.org/abs/2004.02147)
