Skip to content

unconditional_image_generation first draft #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 6, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions docs/source/ko/using-diffusers/unconditional_image_generation.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!--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.
-->

#๋ฌด์กฐ๊ฑด์  ์ด๋ฏธ์ง€ ์ƒ์„ฑ
[[Colab์—์„œ ์—ด๊ธฐ]]

๋ฌด์กฐ๊ฑด์  ์ด๋ฏธ์ง€ ์ƒ์„ฑ์€ ๋น„๊ต์  ๊ฐ„๋‹จํ•œ ์ž‘์—…์ž…๋‹ˆ๋‹ค. ๋ชจ๋ธ์ด ํ…์ŠคํŠธ๋‚˜ ์ด๋ฏธ์ง€์™€ ๊ฐ™์€ ์ถ”๊ฐ€ ์กฐ๊ฑด ์—†์ด ์ด๋ฏธ ํ•™์Šต๋œ ํ›ˆ๋ จ ๋ฐ์ดํ„ฐ์™€ ์œ ์‚ฌํ•œ ์ด๋ฏธ์ง€๋งŒ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

[๋””ํ“จ์ „ ํŒŒ์ดํ”„๋ผ์ธ]์€ ์ถ”๋ก ์„ ์œ„ํ•ด ๋ฏธ๋ฆฌ ํ›ˆ๋ จ๋œ ๋””ํ“จ์ „ ์‹œ์Šคํ…œ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฐ€์žฅ ์‰ฌ์šด ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.

๋จผ์ € [๋””ํ“จ์ „ ํŒŒ์ดํ”„๋ผ์ธ]์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ๋‹ค์šด๋กœ๋“œํ•  ํŒŒ์ดํ”„๋ผ์ธ์˜ ์ฒดํฌํฌ์ธํŠธ๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. ํ—ˆ๋ธŒ์˜ ๐Ÿงจ ๋””ํ“จ์ „ ์ฒดํฌํฌ์ธํŠธ ์ค‘ ํ•˜๋‚˜๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค(์‚ฌ์šฉํ•  ์ฒดํฌํฌ์ธํŠธ๋Š” ๋‚˜๋น„ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค).

<Tip>
๐Ÿ’ก ๋‚˜๋งŒ์˜ ๋ฌด์กฐ๊ฑด์  ์ด๋ฏธ์ง€ ์ƒ์„ฑ ๋ชจ๋ธ์„ ํ•™์Šต์‹œํ‚ค๊ณ  ์‹ถ์œผ์‹ ๊ฐ€์š”? ํ•™์Šต ๊ฐ€์ด๋“œ๋ฅผ ์‚ดํŽด๋ณด๊ณ  ๋‚˜๋งŒ์˜ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณด์„ธ์š”.
</Tip>

์ด ๊ฐ€์ด๋“œ์—์„œ๋Š” ๋ฌด์กฐ๊ฑด์  ์ด๋ฏธ์ง€ ์ƒ์„ฑ์— [DiffusionPipeline]๊ณผ DDPM์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค:

```py
>>> from diffusers import DiffusionPipeline

>>> generator = DiffusionPipeline.from_pretrained("anton-l/ddpm-butterflies-128")
```
[๋””ํ“จ์ „ ํŒŒ์ดํ”„๋ผ์ธ]์€ ๋ชจ๋“  ๋ชจ๋ธ๋ง, ํ† ํฐํ™”, ์Šค์ผ€์ค„๋ง ๊ตฌ์„ฑ ์š”์†Œ๋ฅผ ๋‹ค์šด๋กœ๋“œํ•˜๊ณ  ์บ์‹œํ•ฉ๋‹ˆ๋‹ค. ์ด ๋ชจ๋ธ์€ ์•ฝ 14์–ต ๊ฐœ์˜ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— GPU์—์„œ ์‹คํ–‰ํ•  ๊ฒƒ์„ ๊ฐ•๋ ฅํžˆ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค. PyTorch์—์„œ์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ œ๋„ˆ๋ ˆ์ดํ„ฐ ๊ฐ์ฒด๋ฅผ GPU๋กœ ์˜ฎ๊ธธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:
```py
>>> generator.to("cuda")
```
์ด์ œ ์ œ๋„ˆ๋ ˆ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:
```py
>>> image = generator().images[0]
```
์ถœ๋ ฅ์€ ๊ธฐ๋ณธ์ ์œผ๋กœ PIL.Image ๊ฐ์ฒด๋กœ ๊ฐ์‹ธ์ง‘๋‹ˆ๋‹ค.

ํ˜ธ์ถœํ•˜์—ฌ ์ด๋ฏธ์ง€๋ฅผ ์ €์žฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:
```py
>>> image.save("generated_image.png")
```
์•„๋ž˜ ์ŠคํŽ˜์ด์Šค(๋ฐ๋ชจ ๋งํฌ)๋ฅผ ์ด์šฉํ•ด ๋ณด๊ณ , ์ถ”๋ก  ๋‹จ๊ณ„์˜ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ž์œ ๋กญ๊ฒŒ ์กฐ์ ˆํ•˜์—ฌ ์ด๋ฏธ์ง€ ํ’ˆ์งˆ์— ์–ด๋–ค ์˜ํ–ฅ์„ ๋ฏธ์น˜๋Š”์ง€ ํ™•์ธํ•ด ๋ณด์„ธ์š”!

<iframe src="https://stevhliu-ddpm-butterflies-128.hf.space" frameborder="0" width="850" height="500"></iframe>