-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update ppdiffusers pipelines (#4230)
- Loading branch information
Showing
3 changed files
with
389 additions
and
14 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
ppdiffusers/examples/inference/image_guided_image_inpainting-paint_by_example.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import paddle | ||
|
||
from ppdiffusers import DiffusionPipeline | ||
from ppdiffusers.utils import load_image | ||
|
||
img_url = "https://paddlenlp.bj.bcebos.com/models/community/Fantasy-Studio/data/image_example_1.png" | ||
mask_url = "https://paddlenlp.bj.bcebos.com/models/community/Fantasy-Studio/data/mask_example_1.png" | ||
example_url = "https://paddlenlp.bj.bcebos.com/models/community/Fantasy-Studio/data/reference_example_1.jpeg" | ||
|
||
init_image = load_image(img_url).resize((512, 512)) | ||
mask_image = load_image(mask_url).resize((512, 512)) | ||
example_image = load_image(example_url).resize((512, 512)) | ||
|
||
pipe = DiffusionPipeline.from_pretrained("Fantasy-Studio/Paint-by-Example") | ||
|
||
# 使用fp16加快生成速度 | ||
with paddle.amp.auto_cast(True): | ||
image = pipe(image=init_image, mask_image=mask_image, example_image=example_image).images[0] | ||
image.save("paint_by_example_test.png") |
34 changes: 34 additions & 0 deletions
34
ppdiffusers/examples/inference/unconditional_audio_generation-audio_diffusion.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import paddle | ||
from scipy.io.wavfile import write | ||
|
||
from ppdiffusers import AudioDiffusionPipeline | ||
|
||
# 加载模型和scheduler | ||
pipe = AudioDiffusionPipeline.from_pretrained("teticio/audio-diffusion-ddim-256") | ||
pipe.set_progress_bar_config(disable=None) | ||
generator = paddle.Generator().manual_seed(42) | ||
|
||
output = pipe(generator=generator) | ||
audio = output.audios[0] | ||
image = output.images[0] | ||
|
||
# 保存音频到本地 | ||
for i, audio in enumerate(audio): | ||
write(f"audio_diffusion_test{i}.wav", pipe.mel.sample_rate, audio.transpose()) | ||
|
||
# 保存图片 | ||
image.save("audio_diffusion_test.png") |
Oops, something went wrong.