Skip to content

Commit aa4a62c

Browse files
authored
【PPDiffusers】增加FD ControlNet text2img, img2img, inpaint_legacy, hiresfix pipeline (PaddlePaddle#6234)
* 增加fd contorlnet img2img text2img inpainting pipeline, hiresfix fd pipleine * update * update controlnet * update readme * update rm * update fd * update gpu * add lpw fix preconfig bug in img2img etc * 默认使用LPW * fix inpainting * 使用老版本的_load_pretrained_model_old
1 parent b69063d commit aa4a62c

29 files changed

+6982
-921
lines changed

ppdiffusers/deploy/README.md

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,48 @@ pip install fastdeploy-gpu-python -f https://www.paddlepaddle.org.cn/whl/fastdep
3939

4040
下面将指定模型目录,推理引擎后端,硬件以及 scheduler 类型,运行 `infer.py` 脚本,完成文图生成任务。
4141

42-
```
42+
```sh
4343
python infer.py --model_dir stable-diffusion-v1-4/ --scheduler "pndm" --backend paddle --task_name text2img
4444
```
4545

46-
脚本的输入提示语句为 **"a photo of an astronaut riding a horse on mars"**, 得到的图像文件为 fd_astronaut_rides_horse.png。生成的图片示例如下(每次生成的图片都不相同,示例仅作参考):
46+
脚本的输入提示语句为 **"a photo of an astronaut riding a horse on mars"**, 得到的图像文件为 text2img.png。生成的图片示例如下(每次生成的图片都不相同,示例仅作参考):
4747

48-
![fd_astronaut_rides_horse.png](https://user-images.githubusercontent.com/10826371/200261112-68e53389-e0a0-42d1-8c3a-f35faa6627d7.png)
48+
![text2img.png](https://user-images.githubusercontent.com/10826371/200261112-68e53389-e0a0-42d1-8c3a-f35faa6627d7.png)
4949

5050
如果使用 stable-diffusion-v1-5 模型,则可执行以下命令完成推理:
5151

52+
```sh
53+
python infer.py --model_dir stable-diffusion-v1-5/ --scheduler "preconfig-euler-ancestral" --backend paddle_tensorrt --use_fp16 True --device gpu --task_name text2img
5254
```
53-
python infer.py --model_dir stable-diffusion-v1-5/ --scheduler "euler_ancestral" --backend paddle_tensorrt --use_fp16 True --device gpu --task_name text2img
54-
```
5555

56+
同时,我们还提供基于两阶段 HiresFix 的文图生成示例。下面将指定模型目录,指定任务名称为 `hiresfix` 后,运行 `infer.py` 脚本,完成`两阶段hiresfix任务`,在第一阶段我们生成了 `512x512分辨率` 的图片,然后在第二阶段我们在一阶段的基础上修复生成了 `768x768分辨率` 图片。
57+
58+
| without hiresfix | with hiresfix |
59+
|:-------------------:|:-------------------:|
60+
|![][without-hiresfix]|![][with-hiresfix]|
61+
62+
[without-hiresfix]: https://github.com/PaddlePaddle/PaddleNLP/assets/50394665/38ab6032-b960-4b76-8d69-0e0f8b5e1f42
63+
[with-hiresfix]: https://github.com/PaddlePaddle/PaddleNLP/assets/50394665/a472cb31-d8a2-451d-bf80-cd84c9ef0d08
64+
65+
在80G A100上,ppdiffusers==0.16.1、fastdeploy==1.0.7、develop paddle、cuda11.7 的环境下,我们测出了如下的速度。
66+
- without hiresfix 的速度为:Mean latency: 1.930896 s, p50 latency: 1.932413 s, p90 latency: 1.933565 s, p95 latency: 1.933630 s.
67+
- with hiresfix 的速度为:Mean latency: 1.442178 s, p50 latency: 1.442885 s, p90 latency: 1.446133 s, p95 latency: 1.446285 s.
68+
69+
```sh
70+
python infer.py --model_dir stable-diffusion-v1-5/ --scheduler "euler-ancestral" --backend paddle_tensorrt --use_fp16 True --device gpu --task_name hiresfix
71+
```
5672

5773
<a name="文本引导的图像变换"></a>
5874

5975
### 文本引导的图像变换(Image-to-Image Text-Guided Generation)
6076

6177
下面将指定模型目录,推理引擎后端,硬件以及 scheduler 类型,运行 `infer.py` 脚本,完成文本引导的图像变换任务。
6278

63-
```
79+
```sh
6480
python infer.py --model_dir stable-diffusion-v1-4/ --scheduler "pndm" --backend paddle_tensorrt --use_fp16 True --device gpu --task_name img2img
6581
```
6682

67-
脚本输入的提示语句为 **"A fantasy landscape, trending on artstation"**,运行得到的图像文件为 fantasy_landscape.png。生成的图片示例如下(每次生成的图片都不相同,示例仅作参考):
83+
脚本输入的提示语句为 **"A fantasy landscape, trending on artstation"**,运行得到的图像文件为 img2img.png。生成的图片示例如下(每次生成的图片都不相同,示例仅作参考):
6884

6985
| input image | output image |
7086
|:-------------------:|:-------------------:|
@@ -77,18 +93,18 @@ python infer.py --model_dir stable-diffusion-v1-4/ --scheduler "pndm" --backend
7793

7894
如果使用 stable-diffusion-v1-5 模型,则可执行以下命令完成推理:
7995

80-
```
81-
python infer.py --model_dir stable-diffusion-v1-5/ --scheduler "euler_ancestral" --backend paddle_tensorrt --use_fp16 True --device gpu --task_name img2img
96+
```sh
97+
python infer.py --model_dir stable-diffusion-v1-5/ --scheduler "euler-ancestral" --backend paddle_tensorrt --use_fp16 True --device gpu --task_name img2img
8298
```
8399

84100

85101
同时,我们还提供基于 CycleDiffusion 的文本引导的图像变换示例。下面将指定模型目录,运行 `infer.py` 脚本,完成文本引导的图像变换任务。
86102

87-
```
103+
```sh
88104
python infer.py --model_dir stable-diffusion-v1-4/ --backend paddle_tensorrt --use_fp16 True --device gpu --task_name cycle_diffusion
89105
```
90106

91-
脚本输入的源提示语句为 **"An astronaut riding a horse"**,目标提示语句为 **"An astronaut riding an elephant"**,运行得到的图像文件为 horse_to_elephant.png。生成的图片示例如下(每次生成的图片都不相同,示例仅作参考):
107+
脚本输入的源提示语句为 **"An astronaut riding a horse"**,目标提示语句为 **"An astronaut riding an elephant"**,运行得到的图像文件为 cycle_diffusion.png。生成的图片示例如下(每次生成的图片都不相同,示例仅作参考):
92108

93109
| input image | output image |
94110
|:-------------------:|:-------------------:|
@@ -107,11 +123,11 @@ python infer.py --model_dir stable-diffusion-v1-4/ --backend paddle_tensorrt --u
107123

108124
下面将指定模型目录,推理引擎后端,硬件以及 scheduler 类型,运行 `infer.py` 脚本,完成文本引导的图像编辑任务。
109125

110-
```
111-
python infer.py --model_dir stable-diffusion-v1-4/ --scheduler euler_ancestral --backend paddle_tensorrt --use_fp16 True --device gpu --task_name inpaint_legacy
126+
```sh
127+
python infer.py --model_dir stable-diffusion-v1-4/ --scheduler euler-ancestral --backend paddle_tensorrt --use_fp16 True --device gpu --task_name inpaint_legacy
112128
```
113129

114-
脚本输入的提示语为 **"Face of a yellow cat, high resolution, sitting on a park bench"**,运行得到的图像文件为 cat_on_bench_new.png。生成的图片示例如下(每次生成的图片都不相同,示例仅作参考):
130+
脚本输入的提示语为 **"Face of a yellow cat, high resolution, sitting on a park bench"**,运行得到的图像文件为 inpaint_legacy.png。生成的图片示例如下(每次生成的图片都不相同,示例仅作参考):
115131

116132
| input image | mask image | output image
117133
|:-------------------:|:-------------------:|:-------------------:|
@@ -123,19 +139,19 @@ python infer.py --model_dir stable-diffusion-v1-4/ --scheduler euler_ancestral -
123139

124140
如果使用 stable-diffusion-v1-5 模型,则可执行以下命令完成推理:
125141

126-
```
127-
python infer.py --model_dir stable-diffusion-v1-5/ --scheduler euler_ancestral --backend paddle_tensorrt --use_fp16 True --device gpu --task_name inpaint_legacy
142+
```sh
143+
python infer.py --model_dir stable-diffusion-v1-5/ --scheduler euler-ancestral --backend paddle_tensorrt --use_fp16 True --device gpu --task_name inpaint_legacy
128144
```
129145

130146
#### 正式版本
131147

132148
下面将指定模型目录,推理引擎后端,硬件以及 scheduler 类型,运行 `infer.py` 脚本,完成文本引导的图像编辑任务。
133149

134-
```
135-
python infer.py --model_dir stable-diffusion-v1-5-inpainting/ --scheduler euler_ancestral --backend paddle_tensorrt --use_fp16 True --device gpu --task_name inpaint
150+
```sh
151+
python infer.py --model_dir stable-diffusion-v1-5-inpainting/ --scheduler euler-ancestral --backend paddle_tensorrt --use_fp16 True --device gpu --task_name inpaint
136152
```
137153

138-
脚本输入的提示语为 **"Face of a yellow cat, high resolution, sitting on a park bench"**,运行得到的图像文件为 cat_on_bench_new.png。生成的图片示例如下(每次生成的图片都不相同,示例仅作参考):
154+
脚本输入的提示语为 **"Face of a yellow cat, high resolution, sitting on a park bench"**,运行得到的图像文件为 inpaint.png。生成的图片示例如下(每次生成的图片都不相同,示例仅作参考):
139155

140156
| input image | mask image | output image
141157
|:-------------------:|:-------------------:|:-------------------:|
@@ -153,13 +169,18 @@ python infer.py --model_dir stable-diffusion-v1-5-inpainting/ --scheduler euler_
153169
| 参数 |参数说明 |
154170
|----------|--------------|
155171
| --model_dir | 导出后模型的目录。默认为 `runwayml/stable-diffusion-v1-5@fastdeploy` |
156-
| --backend | 推理引擎后端。默认为 `paddle_tensorrt`,可选列表:`['onnx_runtime', 'paddle', 'paddlelite', 'paddle_tensorrt']`|
157-
| --device | 运行设备。默认为 `cpu`,可选列表:`['cpu', 'gpu', 'huawei_ascend_npu', 'kunlunxin_xpu']`|
172+
| --backend | 推理引擎后端。默认为 `paddle_tensorrt`,可选列表:`['onnx_runtime', 'paddle', 'paddlelite', 'paddle_tensorrt', 'tensorrt']`|
173+
| --device | 运行设备。默认为 `gpu`,可选列表:`['cpu', 'gpu', 'huawei_ascend_npu', 'kunlunxin_xpu']`|
158174
| --device_id | `gpu` 设备的 id。若 `device_id``-1`,视为使用 `cpu` 推理。 |
159175
| --inference_steps | `UNet` 模型运行的次数,默认为 `50`|
160176
| --benchmark_steps | `Benchmark` 运行的次数,默认为 `1`|
161-
| --use_fp16 | 是否使用 `fp16` 精度。默认为 `False`。使用 `paddle_tensorrt` 后端时可以设为 `True` 开启。 |
162-
| --task_name | 任务类型,默认为`text2img`,可选列表:`['text2img', 'img2img', 'inpaint', 'inpaint_legacy', 'cycle_diffusion', 'all']`。 注意,当`task_name``inpaint`时候,我们需要配合`runwayml/stable-diffusion-inpainting@fastdeploy`权重才能正常使用。|
163-
| --scheduler | 采样器类型。默认为 `'pndm'`。可选列表:`['pndm', 'lms', 'preconfig-lms', 'euler', 'euler-ancestral', 'preconfig-euler-ancestral', 'dpm-multi', 'dpm-single', 'unipc-multi', 'ddim', 'ddpm', 'deis-multi', 'heun', 'kdpm2-ancestral', 'kdpm2']`|
164-
| --width | 生成图片的宽度,取值范围 512~768。|
165-
| --height | 生成图片的高度,取值范围 512~768。|
177+
| --use_fp16 | 是否使用 `fp16` 精度。默认为 `False`。使用 `paddle_tensorrt` 后端及 `kunlunxin_xpu` 设备时可以设为 `True` 开启。 |
178+
| --task_name | 任务类型,默认为`text2img`,可选列表:`['text2img', 'img2img', 'inpaint', 'inpaint_legacy', 'cycle_diffusion', 'hiresfix', 'all']`。 注意,当`task_name``inpaint`时候,我们需要配合`runwayml/stable-diffusion-inpainting@fastdeploy`权重才能正常使用。|
179+
| --scheduler | 采样器类型。默认为 `'preconfig-euler-ancestral'`。可选列表:`['pndm', 'lms', 'euler', 'euler-ancestral', 'preconfig-euler-ancestral', 'dpm-multi', 'dpm-single', 'unipc-multi', 'ddim', 'ddpm', 'deis-multi', 'heun', 'kdpm2-ancestral', 'kdpm2']`|
180+
| --infer_op | 推理所采用的op,可选列表 `['zero_copy_infer', 'raw', 'all']``zero_copy_infer`推理速度更快,默认值为`zero_copy_infer`|
181+
| --parse_prompt_type | 处理prompt文本所使用的方法,可选列表 `['raw', 'lpw']``lpw`可强调句子中的单词,并且支持更长的文本输入,默认值为`lpw`|
182+
| --width | 生成图片的宽度,取值范围 512~768。默认值为 512。|
183+
| --height | 生成图片的高度,取值范围 512~768。默认值为 512。|
184+
| --hr_resize_width | hiresfix 所要生成的宽度,取值范围 512~768。默认值为 768。|
185+
| --hr_resize_height | hiresfix 所要生成的高度,取值范围 512~768。默认值为 768。|
186+
| --is_sd2_0 | 是否为sd2.0的模型?默认为 False 。|

0 commit comments

Comments
 (0)