@@ -39,32 +39,48 @@ pip install fastdeploy-gpu-python -f https://www.paddlepaddle.org.cn/whl/fastdep
39
39
40
40
下面将指定模型目录,推理引擎后端,硬件以及 scheduler 类型,运行 ` infer.py ` 脚本,完成文图生成任务。
41
41
42
- ```
42
+ ``` sh
43
43
python infer.py --model_dir stable-diffusion-v1-4/ --scheduler " pndm" --backend paddle --task_name text2img
44
44
```
45
45
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。生成的图片示例如下(每次生成的图片都不相同,示例仅作参考):
47
47
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 )
49
49
50
50
如果使用 stable-diffusion-v1-5 模型,则可执行以下命令完成推理:
51
51
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
52
54
```
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
- ```
55
55
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
+ ```
56
72
57
73
<a name =" 文本引导的图像变换 " ></a >
58
74
59
75
### 文本引导的图像变换(Image-to-Image Text-Guided Generation)
60
76
61
77
下面将指定模型目录,推理引擎后端,硬件以及 scheduler 类型,运行 ` infer.py ` 脚本,完成文本引导的图像变换任务。
62
78
63
- ```
79
+ ``` sh
64
80
python infer.py --model_dir stable-diffusion-v1-4/ --scheduler " pndm" --backend paddle_tensorrt --use_fp16 True --device gpu --task_name img2img
65
81
```
66
82
67
- 脚本输入的提示语句为 ** "A fantasy landscape, trending on artstation"** ,运行得到的图像文件为 fantasy_landscape .png。生成的图片示例如下(每次生成的图片都不相同,示例仅作参考):
83
+ 脚本输入的提示语句为 ** "A fantasy landscape, trending on artstation"** ,运行得到的图像文件为 img2img .png。生成的图片示例如下(每次生成的图片都不相同,示例仅作参考):
68
84
69
85
| input image | output image |
70
86
| :-------------------:| :-------------------:|
@@ -77,18 +93,18 @@ python infer.py --model_dir stable-diffusion-v1-4/ --scheduler "pndm" --backend
77
93
78
94
如果使用 stable-diffusion-v1-5 模型,则可执行以下命令完成推理:
79
95
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
82
98
```
83
99
84
100
85
101
同时,我们还提供基于 CycleDiffusion 的文本引导的图像变换示例。下面将指定模型目录,运行 ` infer.py ` 脚本,完成文本引导的图像变换任务。
86
102
87
- ```
103
+ ``` sh
88
104
python infer.py --model_dir stable-diffusion-v1-4/ --backend paddle_tensorrt --use_fp16 True --device gpu --task_name cycle_diffusion
89
105
```
90
106
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。生成的图片示例如下(每次生成的图片都不相同,示例仅作参考):
92
108
93
109
| input image | output image |
94
110
| :-------------------:| :-------------------:|
@@ -107,11 +123,11 @@ python infer.py --model_dir stable-diffusion-v1-4/ --backend paddle_tensorrt --u
107
123
108
124
下面将指定模型目录,推理引擎后端,硬件以及 scheduler 类型,运行 ` infer.py ` 脚本,完成文本引导的图像编辑任务。
109
125
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
112
128
```
113
129
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。生成的图片示例如下(每次生成的图片都不相同,示例仅作参考):
115
131
116
132
| input image | mask image | output image
117
133
| :-------------------:| :-------------------:| :-------------------:|
@@ -123,19 +139,19 @@ python infer.py --model_dir stable-diffusion-v1-4/ --scheduler euler_ancestral -
123
139
124
140
如果使用 stable-diffusion-v1-5 模型,则可执行以下命令完成推理:
125
141
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
128
144
```
129
145
130
146
#### 正式版本
131
147
132
148
下面将指定模型目录,推理引擎后端,硬件以及 scheduler 类型,运行 ` infer.py ` 脚本,完成文本引导的图像编辑任务。
133
149
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
136
152
```
137
153
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。生成的图片示例如下(每次生成的图片都不相同,示例仅作参考):
139
155
140
156
| input image | mask image | output image
141
157
| :-------------------:| :-------------------:| :-------------------:|
@@ -153,13 +169,18 @@ python infer.py --model_dir stable-diffusion-v1-5-inpainting/ --scheduler euler_
153
169
| 参数 | 参数说明 |
154
170
| ----------| --------------|
155
171
| --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'] ` 。 |
158
174
| --device_id | ` gpu ` 设备的 id。若 ` device_id ` 为` -1 ` ,视为使用 ` cpu ` 推理。 |
159
175
| --inference_steps | ` UNet ` 模型运行的次数,默认为 ` 50 ` 。 |
160
176
| --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