fh2c1 commited on
Commit
0626990
·
verified ·
1 Parent(s): 0aa5329

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +72 -0
README.md ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Anonymize Anyone: Toward Race Fairness in Text-to-Face Synthesis using Simple Preference Optimization in Diffusion Model
2
+
3
+ For detailed information, code, and documentation, please visit our GitHub repository:
4
+ [Anonymize-Anyone](https://github.com/fh2c1/Anonymize-Anyone)
5
+
6
+ ## Anonymize Anyone
7
+
8
+ ![anonymiza-anyone demo images](./assets/Fig1.png)
9
+
10
+ ## Model
11
+
12
+ ![overall_structure](./assets/Fig2.png)
13
+
14
+ **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.
15
+
16
+ ## Model Checkpoints
17
+
18
+ - [Anonymize-Anyone (Inpainting model with FFEL and DIFF losses)](https://huggingface.co/fh2c1/Anonymize-Anyone)
19
+ - [SimPO-LoRA (Diffusion model with Simple Preference Optimization)](https://huggingface.co/fh2c1/SimPO-LoRA)
20
+
21
+ ### Using with Diffusers🧨
22
+
23
+ You can use this model directly with the `diffusers` library:
24
+
25
+
26
+ ```python
27
+ import torch
28
+ from PIL import Image
29
+ from diffusers import StableDiffusionInpaintPipeline
30
+
31
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
32
+ sd_pipe = StableDiffusionInpaintPipeline.from_pretrained(
33
+ "fh2c1/Anonymize-Anyone",
34
+ torch_dtype=torch.float16,
35
+ safety_checker=None,
36
+ ).to(device)
37
+ sd_pipe.load_lora_weights("fh2c1/SimPO-LoRA", adapter_name="SimPO")
38
+ sd_pipe.set_adapters(["SimPO"], adapter_weights=[0.5])
39
+
40
+ def generate_image(image_path, mask_path, prompt, negative_prompt, pipe, seed):
41
+ try:
42
+ in_image = Image.open(image_path)
43
+ in_mask = Image.open(mask_path)
44
+ except IOError as e:
45
+ print(f"Loading error: {e}")
46
+ return None
47
+ generator = torch.Generator(device).manual_seed(seed)
48
+ result = pipe(image=in_image, mask_image=in_mask, prompt=prompt,
49
+ negative_prompt=negative_prompt, generator=generator)
50
+ return result.images[0]
51
+
52
+ image = '/content/Anonymize-Anyone/data/2.png'
53
+ mask = "/content/Anonymize-Anyone/data/2_mask.png"
54
+ prompt = "he is an asian man."
55
+ seed = 38189219984105
56
+ negative_prompt = "low resolution, ugly, disfigured, ugly, bad, immature, cartoon, anime, 3d, painting, b&w, deformed eyes, low quailty, noise"
57
+
58
+ try:
59
+ generated_image = generate_image(image_path=image, mask_path=mask, prompt=prompt,
60
+ negative_prompt=negative_prompt, pipe=sd_pipe, seed=seed)
61
+ except TypeError as e:
62
+ print(f"TypeError : {e}")
63
+
64
+ generated_image
65
+ ```
66
+ ![result](./assets/Fig3.png)
67
+
68
+ 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).
69
+
70
+ ## Training
71
+
72
+ 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).