# Towards Fast, Accurate and Stable 3D Dense Face Alignment
[![License](https://img.shields.io/badge/license-MIT-yellow.svg)](LICENSE)
![GitHub repo size](https://img.shields.io/github/repo-size/cleardusk/3DDFA_V2.svg)
[![CodeFactor](https://www.codefactor.io/repository/github/cleardusk/3ddfa_v2/badge)](https://www.codefactor.io/repository/github/cleardusk/3ddfa_v2)
[![](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1OKciI0ETCpWdRjP-VOGpBulDJojYfgWv)
By [Jianzhu Guo](https://guojianzhu.com), [Xiangyu Zhu](http://www.cbsr.ia.ac.cn/users/xiangyuzhu/), [Yang Yang](http://www.cbsr.ia.ac.cn/users/yyang/main.htm), Fan Yang, [Zhen Lei](http://www.cbsr.ia.ac.cn/users/zlei/) and [Stan Z. Li](https://scholar.google.com/citations?user=Y-nyLGIAAAAJ).
The code repo is owned and maintained by **[Jianzhu Guo](https://guojianzhu.com)**.
<p align="center">
<img src="docs/images/webcam.gif" alt="demo" width="512px">
</p>
**\[Updates\]**
- `2021.1.15`: Borrow the implementation of [Dense-Head-Pose-Estimation](https://github.com/1996scarlet/Dense-Head-Pose-Estimation) for the faster mesh rendering (speedup about 3x, 15ms -> 4ms), see [utils/render_ctypes.py](./utils/render_ctypes.py) for details.
- `2020.10.7`: Add the latency evaluation of the full pipeline in [latency.py](./latency.py), just run by `python3 latency.py --onnx`, see [Latency](#Latency) evaluation for details.
- `2020.10.6`: Add onnxruntime support for FaceBoxes to reduce the face detection latency, just append the `--onnx` action to activate it, see [FaceBoxes_ONNX.py](FaceBoxes/FaceBoxes_ONNX.py) for details.
- `2020.10.2`: **Add onnxruntime support to greatly reduce the 3dmm parameters inference latency**, just append the `--onnx` action when running `demo.py`, see [TDDFA_ONNX.py](./TDDFA_ONNX.py) for details.
- `2020.9.20`: Add features including pose estimation and serializations to .ply and .obj, see `pose`, `ply`, `obj` options in [demo.py](./demo.py).
- `2020.9.19`: Add PNCC (Projected Normalized Coordinate Code), uv texture mapping features, see `pncc`, `uv_tex` options in [demo.py](./demo.py).
## Introduction
This work extends [3DDFA](https://github.com/cleardusk/3DDFA), named **3DDFA_V2**, titled [Towards Fast, Accurate and Stable 3D Dense Face Alignment](https://guojianzhu.com/assets/pdfs/3162.pdf), accepted by [ECCV 2020](https://eccv2020.eu/). The supplementary material is [here](https://guojianzhu.com/assets/pdfs/3162-supp.pdf). The [gif](./docs/images/webcam.gif) above shows a webcam demo of the tracking result, in the scenario of my lab. This repo is the official implementation of 3DDFA_V2.
Compared to [3DDFA](https://github.com/cleardusk/3DDFA), 3DDFA_V2 achieves better performance and stability. Besides, 3DDFA_V2 incorporates the fast face detector [FaceBoxes](https://github.com/zisianw/FaceBoxes.PyTorch) instead of Dlib. A simple 3D render written by c++ and cython is also included. This repo supports the onnxruntime, and the latency of regressing 3DMM parameters using the default backbone is about **1.35ms/image on CPU** with a single image as input. If you are interested in this repo, just try it on this **[google colab](https://colab.research.google.com/drive/1OKciI0ETCpWdRjP-VOGpBulDJojYfgWv)**! Welcome for valuable issues, PRs and discussions 馃槃
<!-- Currently, the pre-trained model, inference code and some utilities are released. -->
## Getting started
### Requirements
See [requirements.txt](./requirements.txt), tested on macOS and Linux platforms. The Windows users may refer to [FQA](#FQA) for building issues. Note that this repo uses Python3. The major dependencies are PyTorch, numpy, opencv-python and onnxruntime, etc. If you run the demos with `--onnx` flag to do acceleration, you may need to install `libomp` first, i.e., `brew install libomp` on macOS.
### Usage
1. Clone this repo
```shell script
git clone https://github.com/cleardusk/3DDFA_V2.git
cd 3DDFA_V2
```
2. Build the cython version of NMS, Sim3DR, and the faster mesh render
<!-- ```shell script
cd FaceBoxes
sh ./build_cpu_nms.sh
cd ..
cd Sim3DR
sh ./build_sim3dr.sh
cd ..
# the faster mesh render
cd utils/asset
gcc -shared -Wall -O3 render.c -o render.so -fPIC
cd ../..
```
or simply build them by -->
```shell script
sh ./build.sh
```
3. Run demos
```shell script
# 1. running on still image, the options include: 2d_sparse, 2d_dense, 3d, depth, pncc, pose, uv_tex, ply, obj
python3 demo.py -f examples/inputs/emma.jpg --onnx # -o [2d_sparse, 2d_dense, 3d, depth, pncc, pose, uv_tex, ply, obj]
# 2. running on videos
python3 demo_video.py -f examples/inputs/videos/214.avi --onnx
# 3. running on videos smoothly by looking ahead by `n_next` frames
python3 demo_video_smooth.py -f examples/inputs/videos/214.avi --onnx
# 4. running on webcam
python3 demo_webcam_smooth.py --onnx
```
The implementation of tracking is simply by alignment. If the head pose > 90掳 or the motion is too fast, the alignment may fail. A threshold is used to trickly check the tracking state, but it is unstable.
You can refer to [demo.ipynb](./demo.ipynb) or [google colab](https://colab.research.google.com/drive/1OKciI0ETCpWdRjP-VOGpBulDJojYfgWv) for the step-by-step tutorial of running on the still image.
For example, running `python3 demo.py -f examples/inputs/emma.jpg -o 3d` will give the result below:
<p align="center">
<img src="docs/images/emma_3d.jpg" alt="demo" width="640px">
</p>
Another example:
<p align="center">
<img src="docs/images/trump_biden_3d.jpg" alt="demo" width="640px">
</p>
Running on a video will give:
<p align="center">
<img src="docs/images/out.gif" alt="demo" width="512px">
</p>
More results or demos to see: [Hathaway](https://guojianzhu.com/assets/videos/hathaway_3ddfa_v2.mp4).
<!-- Obviously, the eyes parts are not good. -->
### Features (up to now)
<table>
<tr>
<th>2D sparse</th>
<th>2D dense</th>
<th>3D</th>
</tr>
<tr>
<td><img src="docs/images/trump_hillary_2d_sparse.jpg" width="360" alt="2d sparse"></td>
<td><img src="docs/images/trump_hillary_2d_dense.jpg" width="360" alt="2d dense"></td>
<td><img src="docs/images/trump_hillary_3d.jpg" width="360" alt="3d"></td>
</tr>
<tr>
<th>Depth</th>
<th>PNCC</th>
<th>UV texture</th>
</tr>
<tr>
<td><img src="docs/images/trump_hillary_depth.jpg" width="360" alt="depth"></td>
<td><img src="docs/images/trump_hillary_pncc.jpg" width="360" alt="pncc"></td>
<td><img src="docs/images/trump_hillary_uv_tex.jpg" width="360" alt="uv_tex"></td>
</tr>
<tr>
<th>Pose</th>
<th>Serialization to .ply</th>
<th>Serialization to .obj</th>
</tr>
<tr>
<td><img src="docs/images/trump_hillary_pose.jpg" width="360" alt="pose"></td>
<td><img src="docs/images/ply.jpg" width="360" alt="ply"></td>
<td><img src="docs/images/obj.jpg" width="360" alt="obj"></td>
</tr>
</table>
### Configs
The default backbone is MobileNet_V1 with input size 120x120 and the default pre-trained weight is `weights/mb1_120x120.pth`, shown in [configs/mb1_120x120.yml](configs/mb1_120x120.yml). This repo provides another config in [configs/mb05_120x120.yml](configs/mb05_120x120.yml), with the widen factor 0.5, being smaller and faster. You can specify the config by `-c` or `--config` option. The released models are shown in the below table. Note that the inference time on CPU in the paper is evaluated using TensorFlow.
| Model | Input | #Params | #Macs | Inference (TF) |
| :-: | :-: | :-: | :-: | :-: |
| MobileNet | 120x120 | 3.27M | 183.5M | ~6.2ms |
| MobileNet x0.5 | 120x120 | 0.85M | 49.5M | ~2.9ms |
**Surprisingly**, the latency of [onnxruntime](https://github.com/microsoft/onnxruntime) is much smaller. The inference time on CPU with different threads is shown below. The results are tested on my MBP (i5-8259U CPU @ 2.30GHz on 13-inch MacBook Pro), with the
没有合适的资源?快使用搜索试试~ 我知道了~
3DDFA-V2.5-opencv-yolov5face
共201个文件
py:72个
pyc:49个
jpg:15个
需积分: 24 0 下载量 139 浏览量
2022-12-25
00:52:09
上传
评论
收藏 84.29MB RAR 举报
温馨提示
3DDFA_V2.5原本人脸检测器是facebox, facebox在脸部超过一半被遮挡时效果较差, 人脸检测器换成yolov5-face,yolov5-face在脸遮挡超过一半时关键点不太准确。 图片处理是imageio,换成opencv。 demo_cam_v5face.py yolov5-face 依赖项: models,加载模型用 yolov5_face,人脸检测器。
资源推荐
资源详情
资源评论
收起资源包目录
3DDFA-V2.5-opencv-yolov5face (201个子文件)
214.avi 17.64MB
render.c 7KB
rasterize_kernel.cpp 18KB
test.cpp 4KB
io.cpp 2KB
Dockerfile 821B
webcam.gif 4.95MB
out.gif 4.88MB
latency.gif 2.45MB
.gitignore 50B
.gitignore 44B
.gitignore 9B
rasterize.h 3KB
io.h 453B
3DDFA_V2.5-main.iml 679B
demo.ipynb 4KB
emma.jpg 741KB
trump_biden_3d.jpg 544KB
emma_3d.jpg 498KB
03.jpg 367KB
ply.jpg 329KB
trump_hillary_2d_dense.jpg 272KB
trump_hillary_2d_sparse.jpg 236KB
obj.jpg 189KB
trump_hillary_pose.jpg 178KB
trump_hillary_3d.jpg 157KB
trump_hillary_pncc.jpg 156KB
trump_hillary_depth.jpg 152KB
trump_hillary.jpg 127KB
JianzhuGuo.jpg 63KB
trump_hillary_uv_tex.jpg 27KB
LICENSE 1KB
BFM_UV.mat 761KB
readme.md 11KB
readme.md 868B
readme.md 678B
readme.md 241B
readme.md 141B
ncc_code.npy 450KB
indices.npy 150KB
bfm_noneck_v3.pkl 23.26MB
tri.pkl 892KB
param_mean_std_62d_120x120.pkl 713B
yolov5n-face.pt 13.66MB
yolov5-blazeface.pt 505KB
mb1_120x120.pth 13.12MB
FaceBoxesProd.pth 3.88MB
mb05_120x120.pth 3.58MB
datasets.py 41KB
face_datasets.py 38KB
general.py 26KB
common.py 19KB
common.py 19KB
plots.py 17KB
yolo.py 16KB
wandb_utils.py 16KB
loss.py 13KB
torch_utils.py 12KB
box_utils.py 10KB
detect_face.py 10KB
cam_opencv_facebox.py 8KB
mobilenet_v3.py 8KB
demo_cam_v5face.py 8KB
metrics.py 8KB
autoanchor.py 7KB
detect_face_api.py 7KB
demo_video_smooth.py 6KB
functions.py 5KB
mobilenet_v1.py 5KB
faceboxes.py 5KB
experimental.py 5KB
TDDFA.py 5KB
google_utils.py 5KB
FaceBoxes_ONNX.py 5KB
faceBoxes.py 5KB
demo.py 5KB
demo_webcam_smooth.py 4KB
resnet.py 4KB
pose.py 4KB
TDDFA_ONNX.py 4KB
serialization.py 4KB
demo_video.py 4KB
demo_video_torch.py 4KB
bfm_onnx.py 3KB
uv.py 3KB
lighting.py 3KB
tddfa_util.py 3KB
latency.py 3KB
render_ctypes.py 2KB
activations.py 2KB
prior_box.py 2KB
functions.py 2KB
build.py 2KB
pncc.py 1KB
nms_wrapper.py 1KB
io.py 1KB
bfm.py 1KB
infer_utils.py 1KB
timer.py 1KB
resume.py 1KB
共 201 条
- 1
- 2
- 3
资源评论
AI视觉网奇
- 粉丝: 7w+
- 资源: 93
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 80632180.jpg
- 李旭国体注入追踪[5.0](1).zip
- semantic.c
- C语言基础-C语言编程基础之Leetcode编程题解之第39题组合总和.zip
- C语言基础-C语言编程基础之Leetcode编程题解之第38题外观数列.zip
- C语言基础-C语言编程基础之Leetcode编程题解之第37题解数独.zip
- C语言基础-C语言编程基础之Leetcode编程题解之第36题有效的数独.zip
- C语言基础-C语言编程基础之Leetcode编程题解之第35题搜索插入位置.zip
- index.wxml
- C语言基础-C语言编程基础之Leetcode编程题解之第33题搜索旋转排序数组.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功