dreambooth-dog-1 / diffusers /docs /source /ko /using-diffusers /unconditional_image_generation.md
Upamanyu098's picture
End of training
ef4d689 verified
|
raw
history blame
2.92 kB

Unconditional ์ด๋ฏธ์ง€ ์ƒ์„ฑ

[[open-in-colab]]

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

['DiffusionPipeline']์€ ์ถ”๋ก ์„ ์œ„ํ•ด ๋ฏธ๋ฆฌ ํ•™์Šต๋œ diffusion ์‹œ์Šคํ…œ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฐ€์žฅ ์‰ฌ์šด ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.

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

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

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

 >>> from diffusers import DiffusionPipeline

 >>> generator = DiffusionPipeline.from_pretrained("anton-l/ddpm-butterflies-128")

[diffusion ํŒŒ์ดํ”„๋ผ์ธ]์€ ๋ชจ๋“  ๋ชจ๋ธ๋ง, ํ† ํฐํ™”, ์Šค์ผ€์ค„๋ง ๊ตฌ์„ฑ ์š”์†Œ๋ฅผ ๋‹ค์šด๋กœ๋“œํ•˜๊ณ  ์บ์‹œํ•ฉ๋‹ˆ๋‹ค. ์ด ๋ชจ๋ธ์€ ์•ฝ 14์–ต ๊ฐœ์˜ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— GPU์—์„œ ์‹คํ–‰ํ•  ๊ฒƒ์„ ๊ฐ•๋ ฅํžˆ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค. PyTorch์—์„œ์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ œ๋„ˆ๋ ˆ์ดํ„ฐ ๊ฐ์ฒด๋ฅผ GPU๋กœ ์˜ฎ๊ธธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

 >>> generator.to("cuda")

์ด์ œ ์ œ๋„ˆ๋ ˆ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

 >>> image = generator().images[0]

์ถœ๋ ฅ์€ ๊ธฐ๋ณธ์ ์œผ๋กœ PIL.Image ๊ฐ์ฒด๋กœ ๊ฐ์‹ธ์ง‘๋‹ˆ๋‹ค.

๋‹ค์Œ์„ ํ˜ธ์ถœํ•˜์—ฌ ์ด๋ฏธ์ง€๋ฅผ ์ €์žฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

 >>> image.save("generated_image.png")

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