Update README.md
Browse files
README.md
CHANGED
@@ -2,8 +2,94 @@
|
|
2 |
tags:
|
3 |
- model_hub_mixin
|
4 |
- pytorch_model_hub_mixin
|
|
|
|
|
5 |
---
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
tags:
|
3 |
- model_hub_mixin
|
4 |
- pytorch_model_hub_mixin
|
5 |
+
license: cc-by-nc-4.0
|
6 |
+
library: pytorch
|
7 |
---
|
8 |
|
9 |
+
# img2pose
|
10 |
+
|
11 |
+
## Model Description
|
12 |
+
img2pose uses Faster R-CNN to predict 6 Degree of Freedom Pose (DoF) for all faces in the photo. An interesting property of this model is that it can project the 3D face onto a 2D plane to also identify bounding boxes for each face. It does not require any other face detection model.
|
13 |
+
|
14 |
+
## Model Details
|
15 |
+
- **Model Type**: Convolutional Neural Network (CNN)
|
16 |
+
- **Architecture**: Faster R-CNN
|
17 |
+
- **Framework**: PyTorch
|
18 |
+
|
19 |
+
## Model Sources
|
20 |
+
- **Repository**: [GitHub Repository](https://github.com/vitoralbiero/img2pose)
|
21 |
+
- **Paper**: [img2pose: Face Alignment and Detection via 6DoF, Face Pose Estimation](https://arxiv.org/abs/2012.07791)
|
22 |
+
|
23 |
+
## Citation
|
24 |
+
If you use this model in your research or application, please cite the following paper:
|
25 |
+
|
26 |
+
Vítor Albiero, Xingyu Chen, Xi Yin, Guan Pang, Tal Hassner, "img2pose: Face Alignment and Detection via 6DoF, Face Pose Estimation," CVPR, 2021, arXiv:2012.07791
|
27 |
+
|
28 |
+
```
|
29 |
+
@inproceedings{albiero2021img2pose,
|
30 |
+
title={img2pose: Face Alignment and Detection via 6DoF, Face Pose Estimation},
|
31 |
+
author={Albiero, Vítor and Chen, Xingyu and Yin, Xi and Pang, Guan and Hassner, Tal},
|
32 |
+
booktitle={CVPR},
|
33 |
+
year={2021},
|
34 |
+
url={https://arxiv.org/abs/2012.07791},
|
35 |
+
}
|
36 |
+
```
|
37 |
+
|
38 |
+
## Acknowledgements
|
39 |
+
We thank Albiero Vítor for sharing their code and training weights with a permissive license.
|
40 |
+
|
41 |
+
## Example Useage
|
42 |
+
|
43 |
+
```{python}
|
44 |
+
import numpy as np
|
45 |
+
import os
|
46 |
+
import json
|
47 |
+
import torch
|
48 |
+
import torch.nn as nn
|
49 |
+
from huggingface_hub import hf_hub_download
|
50 |
+
from safetensors.torch import load_file
|
51 |
+
from feat.facepose_detectors.img2pose.deps.models import FasterDoFRCNN, postprocess_img2pose
|
52 |
+
from feat.utils.io import get_resource_path
|
53 |
+
from torchvision.models.detection.backbone_utils import resnet_fpn_backbone
|
54 |
+
|
55 |
+
|
56 |
+
# Load Model Configurations
|
57 |
+
facepose_config_file = hf_hub_download(repo_id= "py-feat/img2pose", filename="config.json", cache_dir=get_resource_path())
|
58 |
+
with open(facepose_config_file, "r") as f:
|
59 |
+
facepose_config = json.load(f)
|
60 |
+
|
61 |
+
# Initialize img2pose
|
62 |
+
device = 'cpu'
|
63 |
+
backbone = resnet_fpn_backbone(backbone_name="resnet18", weights=None)
|
64 |
+
backbone.eval()
|
65 |
+
backbone.to(device)
|
66 |
+
facepose_detector = FasterDoFRCNN(backbone=backbone,
|
67 |
+
num_classes=2,
|
68 |
+
min_size=facepose_config['min_size'],
|
69 |
+
max_size=facepose_config['max_size'],
|
70 |
+
pose_mean=torch.tensor(facepose_config['pose_mean']),
|
71 |
+
pose_stddev=torch.tensor(facepose_config['pose_stddev']),
|
72 |
+
threed_68_points=torch.tensor(facepose_config['threed_points']),
|
73 |
+
rpn_pre_nms_top_n_test=facepose_config['rpn_pre_nms_top_n_test'],
|
74 |
+
rpn_post_nms_top_n_test=facepose_config['rpn_post_nms_top_n_test'],
|
75 |
+
bbox_x_factor=facepose_config['bbox_x_factor'],
|
76 |
+
bbox_y_factor=facepose_config['bbox_y_factor'],
|
77 |
+
expand_forehead=facepose_config['expand_forehead'])
|
78 |
+
facepose_model_file = hf_hub_download(repo_id= "py-feat/img2pose", filename="model.safetensors", cache_dir=get_resource_path())
|
79 |
+
facepose_checkpoint = load_file(facepose_model_file)
|
80 |
+
facepose_detector.load_state_dict(facepose_checkpoint)
|
81 |
+
facepose_detector.eval()
|
82 |
+
facepose_detector.to(device)
|
83 |
+
|
84 |
+
# Test model
|
85 |
+
face_image = "path/to/your/test_image.jpg" # Replace with your image
|
86 |
+
|
87 |
+
img2pose_output = facepose_detector(face_image)
|
88 |
+
|
89 |
+
# Postprocess
|
90 |
+
img2pose_output = postprocess_img2pose(img2pose_output[0])
|
91 |
+
bbox = img2pose_output['boxes']
|
92 |
+
poses = img2pose_output['dofs']
|
93 |
+
facescores = img2pose_output['scores']
|
94 |
+
|
95 |
+
```
|