2021-02-21 20:48:35 +08:00
2021-02-21 23:11:46 +08:00
## I. CPP-Align
2021-02-21 22:31:44 +08:00
-
2021-02-21 20:48:35 +08:00
2021-02-21 23:11:46 +08:00
## II. Face Mask Renderer
2021-02-21 21:09:07 +08:00
We provide a simple tool to add masks on face images automatically.
2021-02-21 22:31:44 +08:00
We can use this tool to do data augmentation while training our face recognition models.
2021-02-21 21:09:07 +08:00
| Face Image | OP | Mask Image | Out |
| ------- | ------ | --------- | ----------- |
2021-06-20 00:06:19 +08:00
| <img src="https://github.com/deepinsight/insightface/blob/master/python-package/insightface/data/images/Tom_Hanks_54745.png" alt="face" height="112" /> | +F | <img src="https://github.com/nttstar/insightface-resources/blob/master/images/mask1.jpg" alt="mask" height="112" /> | <img src="https://github.com/nttstar/insightface-resources/blob/master/images/mask_out1.jpg?raw=true" alt="mask" height="112" /> |
| <img src="https://github.com/deepinsight/insightface/blob/master/python-package/insightface/data/images/Tom_Hanks_54745.png" alt="face" height="112" /> | +F | <img src="https://github.com/nttstar/insightface-resources/blob/master/images/black-mask.png" alt="mask" height="112" /> | <img src="https://github.com/nttstar/insightface-resources/blob/master/images/mask_out3.jpg?raw=true" alt="mask" height="112" /> |
| <img src="https://github.com/deepinsight/insightface/blob/master/python-package/insightface/data/images/Tom_Hanks_54745.png" alt="face" height="112" /> | +H | <img src="https://github.com/nttstar/insightface-resources/blob/master/images/mask2.jpg?raw=true" alt="mask" height="112" /> | <img src="https://github.com/nttstar/insightface-resources/blob/master/images/mask_out2h.jpg?raw=true" alt="mask" height="112" /> |
2021-02-21 21:09:07 +08:00
**F** means FULL while **H ** means HALF.
2021-02-21 22:31:44 +08:00
2021-06-18 19:18:38 +08:00
### Prepare
2021-02-21 22:31:44 +08:00
2021-06-18 19:18:38 +08:00
- insightface package library
2021-02-21 22:31:44 +08:00
2021-06-18 19:18:38 +08:00
``pip install -U insightface` `
- insightface model pack
``bash> insightface-cli model.download antelope` `
2021-02-21 22:31:44 +08:00
- BFM models
2021-06-18 19:18:38 +08:00
Please follow the tutorial of [https://github.com/YadiraF/face3d/tree/master/examples/Data/BFM ](https://github.com/YadiraF/face3d/tree/master/examples/Data/BFM ) to generate `BFM.mat` and `BFM_UV.mat` . Put them into the insightface model pack directory, such as ``~/.insightface/models/antelope/` `
2021-02-21 22:31:44 +08:00
2021-02-21 23:11:46 +08:00
- mask images
2021-06-18 19:18:38 +08:00
some mask images are included in insightface package, such as 'mask\_blue', 'mask\_white', 'mask\_black' and 'mask\_green'.
2021-02-21 23:11:46 +08:00
2021-02-21 22:31:44 +08:00
### Add Mask to Face Image
2021-02-21 23:11:46 +08:00
Please refer to `make_renderer.py` for detail example.
2021-02-21 22:31:44 +08:00
(1) init renderer:
```
2021-06-18 19:18:38 +08:00
import insightface
2021-06-18 19:23:03 +08:00
from insightface.app import MaskRenderer
2021-06-18 19:18:38 +08:00
tool = MaskRenderer()
tool.prepare(ctx_id=0, det_size=(128,128)) #use gpu
2021-02-21 22:31:44 +08:00
```
(2) load face and mask images
```
2021-06-20 00:06:19 +08:00
from insightface.data import get_image as ins_get_image
image = ins_get_image('Tom_Hanks_54745')
2021-06-18 19:18:38 +08:00
mask_image = "mask_blue"
2021-02-21 22:31:44 +08:00
```
(3) build necessary params for face image, this can be done in offline.
```
params = tool.build_params(image)
```
2021-02-21 23:11:46 +08:00
(4) do mask render, it costs about `10ms` on 224x224 UV size, CPU single thread.
2021-02-21 22:31:44 +08:00
```
mask_out = tool.render_mask(image, mask_image, params)
```
(5) do half mask render.
```
mask_half_out = tool.render_mask(image, mask_image, params, positions=[0.1, 0.5, 0.9, 0.7])
```