---
title: cv_HRN_head-reconstruction
canonical_url: "https://www.modelscope.cn/models/iic/cv_HRN_head-reconstruction"
md_url: "https://www.modelscope.cn/models/iic/cv_HRN_head-reconstruction.md"
repository: iic/cv_HRN_head-reconstruction
chinese_name: "人头重建模型"
last_updated: 2023-11-28
license: "Apache License 2.0"
model_type:
  - "head reconstruction"
library_name:
  - pytorch
frameworks:
  - pytorch
language:
  - ch
domain:
  - cv
downloads: 1189788
stars: 77
tags:
  - "face reconstruction"
  - Alibaba
  - "head reconstruction"
  - avatar
  - "人脸重建"
  - "三维重建"
---

# cv_HRN_head-reconstruction

> cv_HRN_head-reconstruction - iic 在 ModelScope 开源的模型。人头重建模型以单张人像图作为输入，基于人脸重建模型HRN ，利用层次化表征实现快速人脸几何、纹理恢复，输出高精度3D人头重建mesh。

iic/cv_HRN_head-reconstruction 是 ModelScope 魔搭社区上的机器学习模型，采用 Apache License 2.0 许可。

- **Repository**: iic/cv_HRN_head-reconstruction
- **License**: Apache License 2.0
- **Tags**: face reconstruction, Alibaba, head reconstruction, avatar, 人脸重建, 三维重建
- **Downloads**: 1189788
- **Stars**: 77
- **Last updated**: 2023-11-28

Source: https://www.modelscope.cn/models/iic/cv_HRN_head-reconstruction

---

# 基于HRN的高精度人头重建模型

人头重建模型以单张人像图作为输入，基于人脸重建模型[HRN](https://www.modelscope.cn/models/damo/cv_resnet50_face-reconstruction/summary) ，利用层次化表征实现快速人脸几何、纹理恢复，输出高精度3D人头重建mesh。


![Output1](results/result_1.gif)
![Output2](results/result_2.jpg)

## 三维视觉系列模型

| [<img src="results/example_face_reconstruction.jpg" height="200px">](https://www.modelscope.cn/models/damo/cv_resnet50_face-reconstruction/summary) | [<img src="results/example_text-to-head.jpg" height="200px">](https://modelscope.cn/models/damo/cv_HRN_text-to-head/summary) |
|:--:|:--:| 
| [HRN人脸重建](https://www.modelscope.cn/models/damo/cv_resnet50_face-reconstruction/summary) | [文本生成3D头部](https://modelscope.cn/models/damo/cv_HRN_text-to-head/summary) |


## 模型描述

- 该人头重建模型以[HRN](https://www.modelscope.cn/models/damo/cv_resnet50_face-reconstruction/summary) 为基础，融合了BFM与FLAME，构建新的head 3DMM模型，结合两者的头部完整性、脸部高精度等优势。
- 重建区域限于脸部，头部其他区域（后脑、耳朵、脖子）为补全效果，与输入可能不符。

## 期望模型使用方式以及适用范围

模型参数：
- hair_tex: pipeline参数，可在configuration.json中修改，或者在pipeline初始化中传入，如： 
    ```python
    pipeline(Tasks.head_reconstruction, model='damo/cv_HRN_head-reconstruction', model_revision='v0.1', hair_tex=True))
    ```
    当hair_tex为False时（默认），将输出光头的纹理，如以上示例；
  
    当hair_tex为True时，将输出带头发的纹理（效果不稳定，取决于输入图像）。

使用方式：
- 直接推理，输入图像直接进行推理。

使用范围:
- 适用于包含人脸的人像照片，其中人脸分辨率大于100x100，图像整体分辨率小于5000x5000。

目标场景:
- 影视、娱乐、医美等。

### 如何使用

本模型基于pytorch进行训练和推理，在ModelScope框架上，提供输入图片，即可以通过简单的Pipeline调用来使用人头重建模型。

#### 代码范例
```python
import os
import cv2
from modelscope.models.cv.face_reconstruction.utils import write_obj
from modelscope.outputs import OutputKeys
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks


def save_results(result, save_root):
    os.makedirs(save_root, exist_ok=True)

    # export obj and texture
    mesh = result[OutputKeys.OUTPUT]['mesh']
    texture_map = result[OutputKeys.OUTPUT_IMG]
    mesh['texture_map'] = texture_map
    write_obj(os.path.join(save_root, 'head_recon_result.obj'), mesh)

    print(f'Output written to {os.path.abspath(save_root)}')

head_reconstruction = pipeline(Tasks.head_reconstruction, model='damo/cv_HRN_head-reconstruction', model_revision='v0.1')
result = head_reconstruction('https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/face_reconstruction.jpg')

save_results(result, './head_reconstruction_results')
```

### 模型局限性以及可能的偏差
- 人像占比过小可能会影响纹理重建的效果,在人脸分辨率大于200×200的图像上可取得期望效果。
- 对于脸部存在严重遮挡的情况，重建效果可能不符合预期。

## 训练数据介绍
- 本模型通过自监督的方式进行训练，训练数据仅需2D人脸图像，可使用人脸公开数据集如CeleA、300W-LP等。

### 预处理
- 人脸区域裁剪、resize到224x224分辨率作为网络输入。

### 后处理
- 将顶点坐标、三角面片、贴图等数据转化为obj等模型文件。

## 引用
如果你觉得这个该模型对有所帮助，请考虑引用下面的相关的论文：

```BibTeX
@inproceedings{lei2023hierarchical,
  title={A Hierarchical Representation Network for Accurate and Detailed Face Reconstruction from In-The-Wild Images},
  author={Lei, Biwen and Ren, Jianqiang and Feng, Mengyang and Cui, Miaomiao and Xie, Xuansong},
  booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  pages={394--403},
  year={2023}
}
```
