AIGCer-OPPO
commited on
Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,137 @@
|
|
1 |
-
---
|
2 |
-
license: apache-2.0
|
3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
---
|
4 |
+
# FaceScore
|
5 |
+
|
6 |
+
<p align="center">
|
7 |
+
📃 <a href="https://arxiv.org/abs/2406.17100" target="_blank">Paper</a> • 🤗 <a href="https://huggingface.co/OPPOer/FaceScore" target="_blank">Checkpoints</a>
|
8 |
+
</p>
|
9 |
+
|
10 |
+
**FaceScore: Benchmarking and Enhancing Face Quality in Human Generation**
|
11 |
+
|
12 |
+
Traditional facial quality assessment focuses on whether a face is suitable for recognition, while image aesthetic scorers emphasize overall aesthetics rather than details. FaceScore is the first reward model that focuses on faces in text-to-image models, designed to score the faces generated in images. It is fine-tuned on positive and negative sample pairs generated using an inpainting pipeline based on real face images and surpasses previous models in predicting human preferences for generated faces.
|
13 |
+
|
14 |
+
- [Install Dependency](#install-dependency)
|
15 |
+
- [Example Use](#example-use)
|
16 |
+
- [LoRA base on SDXL](#lora-based-on-sdxl)
|
17 |
+
- [Acknowledgement](#acknowledgement)
|
18 |
+
- [Citation](#citation)
|
19 |
+
|
20 |
+
## Install Dependency
|
21 |
+
|
22 |
+
This codebase relies heavily on [ImageReward](https://github.com/THUDM/ImageReward).
|
23 |
+
Please follow the instruction in it.
|
24 |
+
Besides, we introduce two addtional package.
|
25 |
+
You can install them as following:
|
26 |
+
```
|
27 |
+
pip install batch-face image-reward
|
28 |
+
```
|
29 |
+
|
30 |
+
## Example Use
|
31 |
+
|
32 |
+
We provide an example inference script in the directory of this repo.
|
33 |
+
We also provide a real face image for testing. Note that the model can also score real face in the image, and no need to provide a specific prompt.
|
34 |
+
|
35 |
+
|
36 |
+
Use the following code to get the human preference scores from ImageReward:
|
37 |
+
|
38 |
+
```python
|
39 |
+
from FaceScore.FaceScore import FaceScore
|
40 |
+
import os
|
41 |
+
|
42 |
+
|
43 |
+
face_score_model = FaceScore('FaceScore')
|
44 |
+
# load locally
|
45 |
+
# face_score_model = FaceScore(path_to_checkpoint,med_config = path_to_config)
|
46 |
+
|
47 |
+
img_path = 'assets/Lecun.jpg'
|
48 |
+
face_score,box,confidences = face_score_model.get_reward(img_path)
|
49 |
+
print(f'The face score of {img_path} is {face_score}, and the bounding box of the face(s) is {box}')
|
50 |
+
|
51 |
+
```
|
52 |
+
You can also choose to load the model locally, after downloading the checkpoint in [FaceScore](https://huggingface.co/OPPOer/FaceScore/tree/main).
|
53 |
+
|
54 |
+
The output should be like as follow (the exact numbers may be slightly different depending on the compute device):
|
55 |
+
|
56 |
+
```
|
57 |
+
The face score of assets/Lecun.jpg is 3.993915319442749, and the bounding box of the faces is [[104.02845764160156, 28.232379913330078, 143.57421875, 78.53730773925781]]
|
58 |
+
```
|
59 |
+
|
60 |
+
|
61 |
+
## LoRA based on SDXL
|
62 |
+
We leverage FaceScore to filter data and perform direct preference optimization on SDXL.
|
63 |
+
The LoRA weight is [here](https://huggingface.co/OPPOer/FaceScore/tree/main).
|
64 |
+
Here we provide a quick example:
|
65 |
+
```
|
66 |
+
from diffusers import StableDiffusionXLPipeline, UNet2DConditionModel
|
67 |
+
import torch
|
68 |
+
|
69 |
+
# load pipeline
|
70 |
+
inference_dtype = torch.float16
|
71 |
+
pipe = StableDiffusionXLPipeline.from_pretrained(
|
72 |
+
"stabilityai/stable-diffusion-xl-base-1.0",
|
73 |
+
torch_dtype=inference_dtype,
|
74 |
+
)
|
75 |
+
vae = AutoencoderKL.from_pretrained(
|
76 |
+
'madebyollin/sdxl-vae-fp16-fix',
|
77 |
+
torch_dtype=inference_dtype,
|
78 |
+
)
|
79 |
+
pipe.vae = vae
|
80 |
+
# You can load it locally
|
81 |
+
pipe.load_lora_weights("OPPOer/FaceScore/FaceLoRA")
|
82 |
+
pipe.to('cuda')
|
83 |
+
|
84 |
+
generator=torch.Generator(device='cuda').manual_seed(42)
|
85 |
+
image = pipe(
|
86 |
+
prompt='A woman in a costume standing in the desert',
|
87 |
+
guidance_scale=5.0,
|
88 |
+
generator=generator,
|
89 |
+
output_type='pil',
|
90 |
+
).images[0]
|
91 |
+
image.save('A woman in a costume standing in the desert.png')
|
92 |
+
```
|
93 |
+
We provide some examples generated by ours (right) and compare with the original SDXL (left) below.
|
94 |
+
<div style="display: flex; justify-content: space-around; text-align: center;">
|
95 |
+
<div style="text-align: center;">
|
96 |
+
<img src="assets/desert.jpg" alt="图片1" style="width: 600px;" />
|
97 |
+
<p>A woman in a costume standing in the desert. </p>
|
98 |
+
</div>
|
99 |
+
<div style="text-align: center;">
|
100 |
+
<img src="assets/scarf.jpg" alt="图片2" style="width: 600px;" />
|
101 |
+
<p>A woman wearing a blue jacket and scarf.</p>
|
102 |
+
</div>
|
103 |
+
</div>
|
104 |
+
<div style="display: flex; justify-content: space-around; text-align: center;">
|
105 |
+
<div style="text-align: center;">
|
106 |
+
<img src="assets/stage.jpg" alt="图片1" style="width: 600px;" />
|
107 |
+
<p>A young woman in a blue dress performing on stage. </p>
|
108 |
+
</div>
|
109 |
+
<div style="text-align: center;">
|
110 |
+
<img src="assets/striped.jpg" alt="图片2" style="width: 600px;" />
|
111 |
+
<p>A woman with black hair and a striped shirt.</p>
|
112 |
+
</div>
|
113 |
+
</div>
|
114 |
+
<div style="display: flex; justify-content: space-around; text-align: center;">
|
115 |
+
<div style="text-align: center;">
|
116 |
+
<img src="assets/sword.jpg" alt="图片1" style="width: 600px;" />
|
117 |
+
<p>A woman with white hair and white armor is holding a sword. </p>
|
118 |
+
</div>
|
119 |
+
<div style="text-align: center;">
|
120 |
+
<img src="assets/white.jpg" alt="图片2" style="width: 600px;" />
|
121 |
+
<p>A woman with long black hair and a white shirt.</p>
|
122 |
+
</div>
|
123 |
+
</div>
|
124 |
+
|
125 |
+
## Acknowledgement
|
126 |
+
Our codebase references the code from [ImageReward](https://github.com/THUDM/ImageReward). We extend our gratitude to the authors for open-sourcing their codes.
|
127 |
+
|
128 |
+
## Citation
|
129 |
+
|
130 |
+
```
|
131 |
+
@article{liao2024facescore,
|
132 |
+
title={FaceScore: Benchmarking and Enhancing Face Quality in Human Generation},
|
133 |
+
author={Liao, Zhenyi and Xie, Qingsong and Chen, Chen and Lu, Hannan and Deng, Zhijie},
|
134 |
+
journal={arXiv preprint arXiv:2406.17100},
|
135 |
+
year={2024}
|
136 |
+
|
137 |
+
```
|