Commit
Β·
4c0efa6
0
Parent(s):
Initial commit with model files
Browse files- .gitattributes +7 -0
- README.md +85 -0
- optimizer.bin +3 -0
- pytorch_lora_weights.safetensors +3 -0
- random_states_0.pkl +0 -0
- scaler.pt +3 -0
- scheduler.bin +3 -0
.gitattributes
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.tar.gz filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
datasets:
|
3 |
+
- yuvalkirstain/pickapic_v2
|
4 |
+
language:
|
5 |
+
- en
|
6 |
+
base_model:
|
7 |
+
- stabilityai/stable-diffusion-2-1
|
8 |
+
pipeline_tag: text-to-image
|
9 |
+
library_name: diffusers
|
10 |
+
---
|
11 |
+
|
12 |
+
|
13 |
+
---
|
14 |
+
# Anonymize Anyone: Toward Race Fairness in Text-to-Face Synthesis using Simple Preference Optimization in Diffusion Model
|
15 |
+
|
16 |
+
For detailed information, code, and documentation, please visit our GitHub repository:
|
17 |
+
[Anonymize-Anyone](https://github.com/fh2c1/Anonymize-Anyone)
|
18 |
+
|
19 |
+
## Anonymize Anyone
|
20 |
+
|
21 |
+

|
22 |
+
|
23 |
+
## Model
|
24 |
+
|
25 |
+

|
26 |
+
|
27 |
+
**Anonymize Anyone** presents a novel approach to text-to-face synthesis using a Diffusion Model that considers Race Fairness. Our method uses facial segmentation masks to edit specific facial regions, and employs a Stable Diffusion v2 Inpainting model trained on a curated Asian dataset. We introduce two key losses: **βπΉπΉπΈ** (Focused Feature Enhancement Loss) to enhance performance with limited data, and **βπ«π°ππ** (Difference Loss) to address catastrophic forgetting. Finally, we apply **Simple Preference Optimization** (SimPO) for refined and enhanced image generation.
|
28 |
+
|
29 |
+
## Model Checkpoints
|
30 |
+
|
31 |
+
- [Anonymize-Anyone (Inpainting model with **βπΉπΉπΈ** and **βπ«π°ππ**)](https://huggingface.co/fh2c1/Anonymize-Anyone)
|
32 |
+
- [SimPO-LoRA (Diffusion model with **Simple Preference Optimization**)](https://huggingface.co/fh2c1/SimPO-LoRA-1.2)
|
33 |
+
|
34 |
+
### Using with Diffusersπ§¨
|
35 |
+
|
36 |
+
You can use this model directly with the `diffusers` library:
|
37 |
+
|
38 |
+
|
39 |
+
```python
|
40 |
+
import torch
|
41 |
+
from PIL import Image
|
42 |
+
from diffusers import StableDiffusionInpaintPipeline
|
43 |
+
|
44 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
45 |
+
sd_pipe = StableDiffusionInpaintPipeline.from_pretrained(
|
46 |
+
"fh2c1/Anonymize-Anyone",
|
47 |
+
torch_dtype=torch.float16,
|
48 |
+
safety_checker=None,
|
49 |
+
).to(device)
|
50 |
+
sd_pipe.load_lora_weights("fh2c1/SimPO-LoRA-1.2", adapter_name="SimPO")
|
51 |
+
sd_pipe.set_adapters(["SimPO"], adapter_weights=[0.5])
|
52 |
+
|
53 |
+
def generate_image(image_path, mask_path, prompt, negative_prompt, pipe, seed):
|
54 |
+
try:
|
55 |
+
in_image = Image.open(image_path)
|
56 |
+
in_mask = Image.open(mask_path)
|
57 |
+
except IOError as e:
|
58 |
+
print(f"Loading error: {e}")
|
59 |
+
return None
|
60 |
+
generator = torch.Generator(device).manual_seed(seed)
|
61 |
+
result = pipe(image=in_image, mask_image=in_mask, prompt=prompt,
|
62 |
+
negative_prompt=negative_prompt, generator=generator)
|
63 |
+
return result.images[0]
|
64 |
+
|
65 |
+
image = '/content/Anonymize-Anyone/data/2.png'
|
66 |
+
mask = "/content/Anonymize-Anyone/data/2_mask.png"
|
67 |
+
prompt = "he is an asian man."
|
68 |
+
seed = 38189219984105
|
69 |
+
negative_prompt = "low resolution, ugly, disfigured, ugly, bad, immature, cartoon, anime, 3d, painting, b&w, deformed eyes, low quailty, noise"
|
70 |
+
|
71 |
+
try:
|
72 |
+
generated_image = generate_image(image_path=image, mask_path=mask, prompt=prompt,
|
73 |
+
negative_prompt=negative_prompt, pipe=sd_pipe, seed=seed)
|
74 |
+
except TypeError as e:
|
75 |
+
print(f"TypeError : {e}")
|
76 |
+
|
77 |
+
generated_image
|
78 |
+
```
|
79 |
+

|
80 |
+
|
81 |
+
For more detailed usage instructions, including how to prepare segmentation masks and run inference, please refer to our [GitHub repository](https://github.com/fh2c1/Anonymize-Anyone).
|
82 |
+
|
83 |
+
## Training
|
84 |
+
|
85 |
+
For information on how to train the model, including the use of **βπΉπΉπΈ** (Focused Feature Enhancement Loss) and **βπ«π°ππ** (Difference Loss), please see our GitHub repository's [training section](https://github.com/fh2c1/Anonymize-Anyone#running_man-train).
|
optimizer.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a578a5d4d1b0615f7b81426b14998056200e9827a9245cc5d84977296886fb30
|
3 |
+
size 4654586
|
pytorch_lora_weights.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c1c06e7534b499a1b6d4647bc4b805379840ea84b5280881fd602058cd9f7d61
|
3 |
+
size 6677176
|
random_states_0.pkl
ADDED
Binary file (14.3 kB). View file
|
|
scaler.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a1d64a986cf16698550eb29cdcaebce016e0124c48d0224004513d5914a56639
|
3 |
+
size 988
|
scheduler.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c9b60b4f92ec11f63bd7ec5d81951de7e3bf250074d6d2864be907c49fb0011b
|
3 |
+
size 1000
|