Update README.md
Browse files
README.md
CHANGED
@@ -2,39 +2,107 @@
|
|
2 |
license: apache-2.0
|
3 |
library_name: diffusers
|
4 |
---
|
5 |
-
test under this PR https://github.com/huggingface/diffusers/pull/
|
|
|
|
|
6 |
|
7 |
```python
|
|
|
8 |
from diffusers.modular_pipelines import ModularPipeline, ComponentsManager
|
9 |
import torch
|
10 |
from diffusers.utils import load_image
|
11 |
|
12 |
repo_id = "YiYiXu/modular-diffdiff"
|
|
|
13 |
components = ComponentsManager()
|
14 |
|
15 |
diffdiff_pipeline = ModularPipeline.from_pretrained(repo_id, trust_remote_code=True, component_manager=components, collection="diffdiff")
|
16 |
-
diffdiff_pipeline.
|
17 |
-
|
18 |
components.enable_auto_cpu_offload()
|
|
|
|
|
|
|
19 |
|
20 |
-
|
21 |
-
|
|
|
|
|
22 |
|
23 |
prompt = "a green pear"
|
24 |
negative_prompt = "blurry"
|
|
|
25 |
|
26 |
image = diffdiff_pipeline(
|
27 |
prompt=prompt,
|
28 |
negative_prompt=negative_prompt,
|
29 |
num_inference_steps=25,
|
|
|
30 |
diffdiff_map=mask,
|
31 |
image=image,
|
32 |
output="images"
|
33 |
)[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
```
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
-

|
40 |
|
|
|
2 |
license: apache-2.0
|
3 |
library_name: diffusers
|
4 |
---
|
5 |
+
test under this PR https://github.com/huggingface/diffusers/pull/9672
|
6 |
+
|
7 |
+
#### create differential diffusion pipeline
|
8 |
|
9 |
```python
|
10 |
+
|
11 |
from diffusers.modular_pipelines import ModularPipeline, ComponentsManager
|
12 |
import torch
|
13 |
from diffusers.utils import load_image
|
14 |
|
15 |
repo_id = "YiYiXu/modular-diffdiff"
|
16 |
+
|
17 |
components = ComponentsManager()
|
18 |
|
19 |
diffdiff_pipeline = ModularPipeline.from_pretrained(repo_id, trust_remote_code=True, component_manager=components, collection="diffdiff")
|
20 |
+
diffdiff_pipeline.loader.load(torch_dtype=torch.float16)
|
|
|
21 |
components.enable_auto_cpu_offload()
|
22 |
+
```
|
23 |
+
|
24 |
+
#### basic diff-diff
|
25 |
|
26 |
+
```python
|
27 |
+
|
28 |
+
image = load_image("https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/differential/20240329211129_4024911930.png?download=true")
|
29 |
+
mask = load_image("https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/differential/gradient_mask.png?download=true")
|
30 |
|
31 |
prompt = "a green pear"
|
32 |
negative_prompt = "blurry"
|
33 |
+
generator = torch.Generator(device="cuda").manual_seed(42)
|
34 |
|
35 |
image = diffdiff_pipeline(
|
36 |
prompt=prompt,
|
37 |
negative_prompt=negative_prompt,
|
38 |
num_inference_steps=25,
|
39 |
+
generator=generator,
|
40 |
diffdiff_map=mask,
|
41 |
image=image,
|
42 |
output="images"
|
43 |
)[0]
|
44 |
+
```
|
45 |
+
|
46 |
+

|
47 |
+
|
48 |
+
|
49 |
+
#### ip-adapter
|
50 |
|
51 |
+
```python
|
52 |
+
diffdiff_pipeline.loader.load_ip_adapter("h94/IP-Adapter", subfolder="sdxl_models", weight_name="ip-adapter_sdxl.bin")
|
53 |
+
diffdiff_pipeline.loader.set_ip_adapter_scale(0.6)
|
54 |
+
|
55 |
+
ip_adapter_image = load_image("https://huggingface.co/datasets/YiYiXu/testing-images/resolve/main/diffdiff_orange.jpeg")
|
56 |
+
image = load_image("https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/differential/20240329211129_4024911930.png?download=true")
|
57 |
+
mask = load_image("https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/differential/gradient_mask.png?download=true")
|
58 |
+
|
59 |
+
prompt = "a green pear"
|
60 |
+
negative_prompt = "blurry"
|
61 |
+
generator = torch.Generator(device="cuda").manual_seed(42)
|
62 |
+
|
63 |
+
image = diffdiff_pipeline(
|
64 |
+
prompt=prompt,
|
65 |
+
negative_prompt=negative_prompt,
|
66 |
+
num_inference_steps=25,
|
67 |
+
generator=generator,
|
68 |
+
ip_adapter_image=ip_adapter_image,
|
69 |
+
diffdiff_map=mask,
|
70 |
+
image=image,
|
71 |
+
output="images"
|
72 |
+
)[0]
|
73 |
```
|
74 |
|
75 |
+

|
76 |
+
|
77 |
+
|
78 |
+
#### controlnet
|
79 |
+
|
80 |
+
```python
|
81 |
+
diffdiff_pipeline.loader.unload_ip_adapter()
|
82 |
+
|
83 |
+
control_image = load_image("https://huggingface.co/datasets/YiYiXu/testing-images/resolve/main/diffdiff_tomato_canny.png")
|
84 |
+
image = load_image("https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/differential/20240329211129_4024911930.png?download=true")
|
85 |
+
mask = load_image("https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/differential/gradient_mask.png?download=true")
|
86 |
+
|
87 |
+
prompt = "a green pear"
|
88 |
+
negative_prompt = "blurry"
|
89 |
+
generator = torch.Generator(device="cuda").manual_seed(42)
|
90 |
+
|
91 |
+
image = diffdiff_pipeline(
|
92 |
+
prompt=prompt,
|
93 |
+
negative_prompt=negative_prompt,
|
94 |
+
num_inference_steps=25,
|
95 |
+
generator=generator,
|
96 |
+
control_image=control_image,
|
97 |
+
controlnet_conditioning_scale=0.5,
|
98 |
+
diffdiff_map=mask,
|
99 |
+
image=image,
|
100 |
+
output="images"
|
101 |
+
)[0]
|
102 |
+
|
103 |
+
```
|
104 |
+
|
105 |
+
|
106 |
+

|
107 |
|
|
|
108 |
|