* Docs kr update 3 controlnet, reproducibility ์ ๋ก๋ generator ๊ทธ๋๋ก ์ฌ์ฉ seamless multi-GPU ๊ทธ๋๋ก ์ฌ์ฉ create_dataset ๋ฒ์ญ 1์ฐจ stable_diffusion_jax new translation Add coreml, tome kr docs minor fix translate training/instructpix2pix fix training/instructpix2pix.mdx using-diffusers/weighting_prompts ๋ฒ์ญ 1์ฐจ add SDXL docs Translate using-diffuers/loading_overview.md translate using-diffusers/textual_inversion_inference.md Conditional image generation (#37) * stable_diffusion_jax * index_update * index_update * condition_image_generation --------- Co-authored-by: Seongsu Park <tjdtnsu@gmail.com> jihwan/stable_diffusion.mdx custom_diffusion ์์ ์๋ฃ quicktour ์์ ์๋ฃ distributed inference & control brightness (#40) * distributed_inference.mdx * control_brightness --------- Co-authored-by: idra79haza <idra79haza@github.com> Co-authored-by: Seongsu Park <tjdtnsu@gmail.com> using_safetensors (#41) * distributed_inference.mdx * control_brightness * using_safetensors.mdx --------- Co-authored-by: idra79haza <idra79haza@github.com> Co-authored-by: Seongsu Park <tjdtnsu@gmail.com> delete safetensor short * Repace mdx to md * toctree update * Add controlling_generation * toctree fix * colab link, minor fix * docs name typo fix * frontmatter fix * translation fix
5.5 KiB
ํ๋กฌํํธ์ ๊ฐ์ค์น ๋ถ์ฌํ๊ธฐ
ํ ์คํธ ๊ฐ์ด๋ ๊ธฐ๋ฐ์ diffusion ๋ชจ๋ธ์ ์ฃผ์ด์ง ํ ์คํธ ํ๋กฌํํธ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ด๋ฏธ์ง๋ฅผ ์์ฑํฉ๋๋ค. ํ ์คํธ ํ๋กฌํํธ์๋ ๋ชจ๋ธ์ด ์์ฑํด์ผ ํ๋ ์ฌ๋ฌ ๊ฐ๋ ์ด ํฌํจ๋ ์ ์์ผ๋ฉฐ ํ๋กฌํํธ์ ํน์ ๋ถ๋ถ์ ๊ฐ์ค์น๋ฅผ ๋ถ์ฌํ๋ ๊ฒ์ด ๋ฐ๋์งํ ๊ฒฝ์ฐ๊ฐ ๋ง์ต๋๋ค.
Diffusion ๋ชจ๋ธ์ ๋ฌธ๋งฅํ๋ ํ ์คํธ ์๋ฒ ๋ฉ์ผ๋ก diffusion ๋ชจ๋ธ์ cross attention ๋ ์ด์ด๋ฅผ ์กฐ์ ํจ์ผ๋ก์จ ์๋ํฉ๋๋ค. (๋ ๋ง์ ์ ๋ณด๋ฅผ ์ํ Stable Diffusion Guide๋ฅผ ์ฐธ๊ณ ํ์ธ์). ๋ฐ๋ผ์ ํ๋กฌํํธ์ ํน์ ๋ถ๋ถ์ ๊ฐ์กฐํ๋(๋๋ ๊ฐ์กฐํ์ง ์๋) ๊ฐ๋จํ ๋ฐฉ๋ฒ์ ํ๋กฌํํธ์ ๊ด๋ จ ๋ถ๋ถ์ ํด๋นํ๋ ํ ์คํธ ์๋ฒ ๋ฉ ๋ฒกํฐ์ ํฌ๊ธฐ๋ฅผ ๋๋ฆฌ๊ฑฐ๋ ์ค์ด๋ ๊ฒ์ ๋๋ค. ์ด๊ฒ์ "ํ๋กฌํํธ ๊ฐ์ค์น ๋ถ์ฌ" ๋ผ๊ณ ํ๋ฉฐ, ์ปค๋ฎค๋ํฐ์์ ๊ฐ์ฅ ์๊ตฌํ๋ ๊ธฐ๋ฅ์ ๋๋ค.(์ด๊ณณ์ issue๋ฅผ ๋ณด์ธ์ ).
Diffusers์์ ํ๋กฌํํธ ๊ฐ์ค์น ๋ถ์ฌํ๋ ๋ฐฉ๋ฒ
์ฐ๋ฆฌ๋ diffusers์ ์ญํ ์ด ๋ค๋ฅธ ํ๋ก์ ํธ๋ฅผ ๊ฐ๋ฅํ๊ฒ ํ๋ ํ์์ ์ธ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ toolbex๋ผ๊ณ ์๊ฐํฉ๋๋ค.
InvokeAI ๋ diffuzers ๊ฐ์ ๊ฐ๋ ฅํ UI๋ฅผ ๊ตฌ์ถํ ์ ์์ต๋๋ค.
ํ๋กฌํํธ๋ฅผ ์กฐ์ํ๋ ๋ฐฉ๋ฒ์ ์ง์ํ๊ธฐ ์ํด, diffusers ๋
StableDiffusionPipeline์ ๊ฐ์
๋ง์ ํ์ดํ๋ผ์ธ์ prompt_embeds
์ธ์๋ฅผ ๋
ธ์ถ์์ผ, "prompt-weighted"/์ถ์ฒ๋ ํ
์คํธ ์๋ฒ ๋ฉ์ ํ์ดํ๋ผ์ธ์ ๋ฐ๋ก ์ ๋ฌํ ์ ์๊ฒ ํฉ๋๋ค.
Compel ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ํ๋กฌํํธ์ ์ผ๋ถ๋ฅผ ๊ฐ์กฐํ๊ฑฐ๋ ๊ฐ์กฐํ์ง ์์ ์ ์๋ ์ฌ์ด ๋ฐฉ๋ฒ์ ์ ๊ณตํฉ๋๋ค. ์๋ฒ ๋ฉ์ ์ง์ ์ค๋นํ๋ ๊ฒ ๋์ ์ด ๋ฐฉ๋ฒ์ ์ฌ์ฉํ๋ ๊ฒ์ ๊ฐ๋ ฅํ ์ถ์ฒํฉ๋๋ค.
๊ฐ๋จํ ์์ ๋ฅผ ์ดํด๋ณด๊ฒ ์ต๋๋ค.
๋ค์๊ณผ ๊ฐ์ด "๊ณต์ ๊ฐ๊ณ ๋
ธ๋ ๋ถ์์ ๊ณ ์์ด" ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๊ณ ์ถ์ต๋๋ค:
from diffusers import StableDiffusionPipeline, UniPCMultistepScheduler
pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4")
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
prompt = "a red cat playing with a ball"
generator = torch.Generator(device="cpu").manual_seed(33)
image = pipe(prompt, generator=generator, num_inference_steps=20).images[0]
image
์์ฑ๋ ์ด๋ฏธ์ง:
์ฌ์ง์์ ์ ์ ์๋ฏ์ด, "๊ณต"์ ์ด๋ฏธ์ง์ ์์ต๋๋ค. ์ด ๋ถ๋ถ์ ๊ฐ์กฐํด ๋ณผ๊น์!
๋จผ์ compel ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ค์นํด์ผํฉ๋๋ค:
pip install compel
๊ทธ๋ฐ ๋ค์์๋ Compel ์ค๋ธ์ ํธ๋ฅผ ์์ฑํฉ๋๋ค:
from compel import Compel
compel_proc = Compel(tokenizer=pipe.tokenizer, text_encoder=pipe.text_encoder)
์ด์ "++" ๋ฅผ ์ฌ์ฉํด์ "๊ณต" ์ ๊ฐ์กฐํด ๋ด
์๋ค:
prompt = "a red cat playing with a ball++"
๊ทธ๋ฆฌ๊ณ ์ด ํ๋กฌํํธ๋ฅผ ํ์ดํ๋ผ์ธ์ ๋ฐ๋ก ์ ๋ฌํ์ง ์๊ณ , compel_proc ๋ฅผ ์ฌ์ฉํ์ฌ ์ฒ๋ฆฌํด์ผํฉ๋๋ค:
prompt_embeds = compel_proc(prompt)
ํ์ดํ๋ผ์ธ์ prompt_embeds ๋ฅผ ๋ฐ๋ก ์ ๋ฌํ ์ ์์ต๋๋ค:
generator = torch.Generator(device="cpu").manual_seed(33)
images = pipe(prompt_embeds=prompt_embeds, generator=generator, num_inference_steps=20).images[0]
image
์ด์ "๊ณต"์ด ์๋ ๊ทธ๋ฆผ์ ์ถ๋ ฅํ ์ ์์ต๋๋ค!
๋ง์ฐฌ๊ฐ์ง๋ก -- ์ ๋ฏธ์ฌ๋ฅผ ๋จ์ด์ ์ฌ์ฉํ์ฌ ๋ฌธ์ฅ์ ์ผ๋ถ๋ฅผ ๊ฐ์กฐํ์ง ์์ ์ ์์ต๋๋ค. ํ๋ฒ ์๋ํด ๋ณด์ธ์!
์ฆ๊ฒจ์ฐพ๋ ํ์ดํ๋ผ์ธ์ prompt_embeds ์
๋ ฅ์ด ์๋ ๊ฒฝ์ฐ issue๋ฅผ ์๋ก ๋ง๋ค์ด์ฃผ์ธ์.
Diffusers ํ์ ์ต๋ํ ๋์ํ๋ ค๊ณ ๋
ธ๋ ฅํฉ๋๋ค.
Compel 1.1.6 ๋ textual inversions์ ์ฌ์ฉํ์ฌ ๋จ์ํํ๋ ์ ํฐ๋ฆดํฐ ํด๋์ค๋ฅผ ์ถ๊ฐํฉ๋๋ค.
DiffusersTextualInversionManager๋ฅผ ์ธ์คํด์คํ ํ ํ ์ด๋ฅผ Compel init์ ์ ๋ฌํฉ๋๋ค:
textual_inversion_manager = DiffusersTextualInversionManager(pipe)
compel = Compel(
tokenizer=pipe.tokenizer,
text_encoder=pipe.text_encoder,
textual_inversion_manager=textual_inversion_manager)
๋ ๋ง์ ์ ๋ณด๋ฅผ ์ป๊ณ ์ถ๋ค๋ฉด compel ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ฌธ์๋ฅผ ์ฐธ๊ณ ํ์ธ์.

