Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,53 @@
|
|
1 |
-
---
|
2 |
-
license: cc-by-nc-4.0
|
3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: cc-by-nc-4.0
|
3 |
+
---
|
4 |
+
**Github repo**: https://github.com/magic-research/piecewise-rectified-flow <br>
|
5 |
+
**PeRFlow accelerated SDXL-base**: https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0
|
6 |
+
|
7 |
+
**Demo:**
|
8 |
+
```python
|
9 |
+
from pathlib import Path
|
10 |
+
import torch, torchvision
|
11 |
+
|
12 |
+
from diffusers import StableDiffusionXLPipeline
|
13 |
+
pipe = StableDiffusionXLPipeline.from_pretrained("hansyan/perflow-sdxl-base", torch_dtype=torch.float16, use_safetensors=True, variant="v0-fix")
|
14 |
+
from src.scheduler_perflow import PeRFlowScheduler
|
15 |
+
pipe.scheduler = PeRFlowScheduler.from_config(pipe.scheduler.config, prediction_type="ddim_eps", num_time_windows=4)
|
16 |
+
pipe.to("cuda", torch.float16)
|
17 |
+
|
18 |
+
|
19 |
+
prompts_list = [
|
20 |
+
["photorealistic, uhd, high resolution, high quality, highly detailed; RAW photo, a handsome man, wearing a black coat, outside, closeup face",
|
21 |
+
"distorted, blur, low-quality, haze, out of focus",],
|
22 |
+
["photorealistic, uhd, high resolution, high quality, highly detailed; masterpiece, A closeup face photo of girl, wearing a rain coat, in the street, heavy rain, bokeh,",
|
23 |
+
"distorted, blur, low-quality, haze, out of focus",],
|
24 |
+
["photorealistic, uhd, high resolution, high quality, highly detailed; RAW photo, a red luxury car, studio light",
|
25 |
+
"distorted, blur, low-quality, haze, out of focus",],
|
26 |
+
["photorealistic, uhd, high resolution, high quality, highly detailed; masterpiece, A beautiful cat bask in the sun",
|
27 |
+
"distorted, blur, low-quality, haze, out of focus",],
|
28 |
+
]
|
29 |
+
|
30 |
+
num_inference_steps = 6 # suggest steps >= num_win=4
|
31 |
+
cfg_scale_list = [2.0] # suggest values [1.5, 2.0, 2.5]
|
32 |
+
num_img = 2
|
33 |
+
seed = 42
|
34 |
+
|
35 |
+
for cfg_scale in cfg_scale_list:
|
36 |
+
for i, prompts in enumerate(prompts_list):
|
37 |
+
setup_seed(seed)
|
38 |
+
prompt, neg_prompt = prompts[0], prompts[1]
|
39 |
+
samples = pipe(
|
40 |
+
prompt = [prompt] * num_img,
|
41 |
+
negative_prompt = [neg_prompt] * num_img,
|
42 |
+
height = 1024,
|
43 |
+
width = 1024,
|
44 |
+
num_inference_steps = num_inference_steps,
|
45 |
+
guidance_scale = cfg_scale,
|
46 |
+
output_type = 'pt',
|
47 |
+
).images
|
48 |
+
|
49 |
+
cfg_int = int(cfg_scale); cfg_float = int(cfg_scale*10 - cfg_int*10)
|
50 |
+
save_name = f'step_{num_inference_steps}_txt{i+1}_cfg{cfg_int}-{cfg_float}.png'
|
51 |
+
torchvision.utils.save_image(torchvision.utils.make_grid(samples, nrow = num_img), os.path.join("demo", save_name))
|
52 |
+
|
53 |
+
```
|