mirror of
https://github.com/huggingface/diffusers.git
synced 2026-01-27 17:22:53 +03:00
61 lines
2.9 KiB
Markdown
61 lines
2.9 KiB
Markdown
<!--Copyright 2023 The HuggingFace Team. 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.
|
|
-->
|
|
|
|
# Unconditional ์ด๋ฏธ์ง ์์ฑ
|
|
|
|
[[open-in-colab]]
|
|
|
|
Unconditional ์ด๋ฏธ์ง ์์ฑ์ ๋น๊ต์ ๊ฐ๋จํ ์์
์
๋๋ค. ๋ชจ๋ธ์ด ํ
์คํธ๋ ์ด๋ฏธ์ง์ ๊ฐ์ ์ถ๊ฐ ์กฐ๊ฑด ์์ด ์ด๋ฏธ ํ์ต๋ ํ์ต ๋ฐ์ดํฐ์ ์ ์ฌํ ์ด๋ฏธ์ง๋ง ์์ฑํฉ๋๋ค.
|
|
|
|
['DiffusionPipeline']์ ์ถ๋ก ์ ์ํด ๋ฏธ๋ฆฌ ํ์ต๋ diffusion ์์คํ
์ ์ฌ์ฉํ๋ ๊ฐ์ฅ ์ฌ์ด ๋ฐฉ๋ฒ์
๋๋ค.
|
|
|
|
๋จผ์ ['DiffusionPipeline']์ ์ธ์คํด์ค๋ฅผ ์์ฑํ๊ณ ๋ค์ด๋ก๋ํ ํ์ดํ๋ผ์ธ์ [์ฒดํฌํฌ์ธํธ](https://huggingface.co/models?library=diffusers&sort=downloads)๋ฅผ ์ง์ ํฉ๋๋ค. ํ๋ธ์ ๐งจ diffusion ์ฒดํฌํฌ์ธํธ ์ค ํ๋๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค(์ฌ์ฉํ ์ฒดํฌํฌ์ธํธ๋ ๋๋น ์ด๋ฏธ์ง๋ฅผ ์์ฑํฉ๋๋ค).
|
|
|
|
<Tip>
|
|
|
|
๐ก ๋๋ง์ unconditional ์ด๋ฏธ์ง ์์ฑ ๋ชจ๋ธ์ ํ์ต์ํค๊ณ ์ถ์ผ์ ๊ฐ์? ํ์ต ๊ฐ์ด๋๋ฅผ ์ดํด๋ณด๊ณ ๋๋ง์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋ ๋ฐฉ๋ฒ์ ์์๋ณด์ธ์.
|
|
|
|
</Tip>
|
|
|
|
|
|
์ด ๊ฐ์ด๋์์๋ unconditional ์ด๋ฏธ์ง ์์ฑ์ ['DiffusionPipeline']๊ณผ [DDPM](https://arxiv.org/abs/2006.11239)์ ์ฌ์ฉํฉ๋๋ค:
|
|
|
|
```python
|
|
>>> from diffusers import DiffusionPipeline
|
|
|
|
>>> generator = DiffusionPipeline.from_pretrained("anton-l/ddpm-butterflies-128")
|
|
```
|
|
|
|
[diffusion ํ์ดํ๋ผ์ธ]์ ๋ชจ๋ ๋ชจ๋ธ๋ง, ํ ํฐํ, ์ค์ผ์ค๋ง ๊ตฌ์ฑ ์์๋ฅผ ๋ค์ด๋ก๋ํ๊ณ ์บ์ํฉ๋๋ค. ์ด ๋ชจ๋ธ์ ์ฝ 14์ต ๊ฐ์ ํ๋ผ๋ฏธํฐ๋ก ๊ตฌ์ฑ๋์ด ์๊ธฐ ๋๋ฌธ์ GPU์์ ์คํํ ๊ฒ์ ๊ฐ๋ ฅํ ๊ถ์ฅํฉ๋๋ค. PyTorch์์์ ๋ง์ฐฌ๊ฐ์ง๋ก ์ ๋๋ ์ดํฐ ๊ฐ์ฒด๋ฅผ GPU๋ก ์ฎ๊ธธ ์ ์์ต๋๋ค:
|
|
|
|
```python
|
|
>>> generator.to("cuda")
|
|
```
|
|
|
|
์ด์ ์ ๋๋ ์ดํฐ๋ฅผ ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ ์ ์์ต๋๋ค:
|
|
|
|
```python
|
|
>>> image = generator().images[0]
|
|
```
|
|
|
|
์ถ๋ ฅ์ ๊ธฐ๋ณธ์ ์ผ๋ก [PIL.Image](https://pillow.readthedocs.io/en/stable/reference/Image.html?highlight=image#the-image-class) ๊ฐ์ฒด๋ก ๊ฐ์ธ์ง๋๋ค.
|
|
|
|
๋ค์์ ํธ์ถํ์ฌ ์ด๋ฏธ์ง๋ฅผ ์ ์ฅํ ์ ์์ต๋๋ค:
|
|
|
|
```python
|
|
>>> image.save("generated_image.png")
|
|
```
|
|
|
|
์๋ ์คํ์ด์ค(๋ฐ๋ชจ ๋งํฌ)๋ฅผ ์ด์ฉํด ๋ณด๊ณ , ์ถ๋ก ๋จ๊ณ์ ๋งค๊ฐ๋ณ์๋ฅผ ์์ ๋กญ๊ฒ ์กฐ์ ํ์ฌ ์ด๋ฏธ์ง ํ์ง์ ์ด๋ค ์ํฅ์ ๋ฏธ์น๋์ง ํ์ธํด ๋ณด์ธ์!
|
|
|
|
<iframe src="https://stevhliu-ddpm-butterflies-128.hf.space" frameborder="0" width="850" height="500"></iframe>
|