|
| 1 | +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import paddle |
| 16 | + |
| 17 | +from ppdiffusers import DiffusionPipeline |
| 18 | +from ppdiffusers.utils import load_image |
| 19 | + |
| 20 | +img_url = "https://paddlenlp.bj.bcebos.com/models/community/Fantasy-Studio/data/image_example_1.png" |
| 21 | +mask_url = "https://paddlenlp.bj.bcebos.com/models/community/Fantasy-Studio/data/mask_example_1.png" |
| 22 | +example_url = "https://paddlenlp.bj.bcebos.com/models/community/Fantasy-Studio/data/reference_example_1.jpeg" |
| 23 | + |
| 24 | +init_image = load_image(img_url).resize((512, 512)) |
| 25 | +mask_image = load_image(mask_url).resize((512, 512)) |
| 26 | +example_image = load_image(example_url).resize((512, 512)) |
| 27 | + |
| 28 | +pipe = DiffusionPipeline.from_pretrained("Fantasy-Studio/Paint-by-Example") |
| 29 | + |
| 30 | +# 使用fp16加快生成速度 |
| 31 | +with paddle.amp.auto_cast(True): |
| 32 | + image = pipe(image=init_image, mask_image=mask_image, example_image=example_image).images[0] |
| 33 | +image.save("paint_by_example_test.png") |
0 commit comments