์ด๋ฏธ์ง, ๋น๋์ค, ์ค๋์ค ์์ฑ์ ์ง์ํ๋ ์ต์ฒจ๋จ ํ์ฐ ๋ชจ๋ธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
๐ค Diffusers ํ๋ก์ ํธ ์์ธ ์๊ฐ
ํ๋ก์ ํธ ๊ฐ์
๐ค Diffusers๋ Hugging Face์์ ๊ฐ๋ฐํ ์ต์ฒจ๋จ ํ์ฐ ๋ชจ๋ธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ก, ์ด๋ฏธ์ง, ์ค๋์ค, ์ฌ์ง์ด ๋ถ์ 3D ๊ตฌ์กฐ ์์ฑ์ ํนํ๋์ด ์์ต๋๋ค. ๊ฐ๋จํ ์ถ๋ก ์๋ฃจ์ ์ ์ฐพ๋ , ์์ ๋ง์ ํ์ฐ ๋ชจ๋ธ์ ํ๋ จํ๋ , ๐ค Diffusers๋ ๋ ๋ค ์ง์ํ๋ ๋ชจ๋์ ๋๊ตฌ ์์์ ๋๋ค.
ํ๋ก์ ํธ ์ฃผ์: https://github.com/huggingface/diffusers
ํต์ฌ ๊ธฐ๋ฅ
์ค๊ณ ์ฒ ํ
- ์ฑ๋ฅ๋ณด๋ค ์ค์ฉ์ฑ (usability over performance)
- ์ฌ์๋ณด๋ค ๋จ์ํจ (simple over easy)
- ์ถ์ํ๋ณด๋ค ์ฌ์ฉ์ ์ ์ ๊ฐ๋ฅ์ฑ (customizability over abstractions)
์ธ ๊ฐ์ง ํต์ฌ ๊ตฌ์ฑ ์์
์ต์ฒจ๋จ ํ์ฐ ํ์ดํ๋ผ์ธ (Diffusion Pipelines)
- ๋จ ๋ช ์ค์ ์ฝ๋๋ก ์ถ๋ก ์คํ ๊ฐ๋ฅ
- ๋ค์ํ ์์ฑ ์์ ์ง์
๊ต์ฒด ๊ฐ๋ฅํ ๋ ธ์ด์ฆ ์ค์ผ์ค๋ฌ (Noise Schedulers)
- ๋ค์ํ ํ์ฐ ์๋ ์ง์
- ์ถ๋ ฅ ํ์ง ์กฐ์ ๊ฐ๋ฅ
์ฌ์ ํ๋ จ๋ ๋ชจ๋ธ (Pretrained Models)
- ๋น๋ฉ ๋ธ๋ก์ผ๋ก ์ฌ์ฉ ๊ฐ๋ฅ
- ์ค์ผ์ค๋ฌ์ ๊ฒฐํฉํ์ฌ ์๋ ํฌ ์๋ ํ์ฐ ์์คํ ์์ฑ
์ค์น ๋ฐฉ๋ฒ
PyTorch ๋ฒ์
# ๊ณต์ ํจํค์ง
pip install --upgrade diffusers[torch]
# ์ปค๋ฎค๋ํฐ์์ ๊ด๋ฆฌํ๋ conda ๋ฒ์
conda install -c conda-forge diffusers
Flax ๋ฒ์
pip install --upgrade diffusers[flax]
๋น ๋ฅธ ์์
ํ ์คํธ-์ด๋ฏธ์ง ์์ฑ
from diffusers import DiffusionPipeline
import torch
pipeline = DiffusionPipeline.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5", torch_dtype=torch.float16)
pipeline.to("cuda")
pipeline("An image of a squirrel in Picasso style").images[0]
์ฌ์ฉ์ ์ ์ ํ์ฐ ์์คํ
from diffusers import DDPMScheduler, UNet2DModel
from PIL import Image
import torch
scheduler = DDPMScheduler.from_pretrained("google/ddpm-cat-256")
model = UNet2DModel.from_pretrained("google/ddpm-cat-256").to("cuda")
scheduler.set_timesteps(50)
sample_size = model.config.sample_size
noise = torch.randn((1, 3, sample_size, sample_size), device="cuda")
input = noise
for t in scheduler.timesteps:
with torch.no_grad():
noisy_residual = model(input, t).sample
prev_noisy_sample = scheduler.step(noisy_residual, t, input).prev_sample
input = prev_noisy_sample
image = (input / 2 + 0.5).clamp(0, 1)
image = image.cpu().permute(0, 2, 3, 1).numpy()[0]
image = Image.fromarray((image * 255).round().astype("uint8"))
image
์ง์ํ๋ ์ฃผ์ ์์ ๋ฐ ๋ชจ๋ธ
์์ | ํ์ดํ๋ผ์ธ | ์ถ์ฒ ๋ชจ๋ธ |
---|---|---|
๋ฌด์กฐ๊ฑด์ ์ด๋ฏธ์ง ์์ฑ | DDPMPipeline | google/ddpm-ema-church-256 |
ํ ์คํธ-์ด๋ฏธ์ง | StableDiffusionPipeline | stable-diffusion-v1-5/stable-diffusion-v1-5 |
ํ ์คํธ-์ด๋ฏธ์ง (unCLIP) | UnCLIPPipeline | kakaobrain/karlo-v1-alpha |
ํ ์คํธ-์ด๋ฏธ์ง (DeepFloyd IF) | IFPipeline | DeepFloyd/IF-I-XL-v1.0 |
ํ ์คํธ-์ด๋ฏธ์ง (Kandinsky) | KandinskyPipeline | kandinsky-community/kandinsky-2-2-decoder |
์ ์ด ๊ฐ๋ฅํ ์์ฑ | StableDiffusionControlNetPipeline | lllyasviel/sd-controlnet-canny |
์ด๋ฏธ์ง ํธ์ง | StableDiffusionInstructPix2PixPipeline | timbrooks/instruct-pix2pix |
์ด๋ฏธ์ง-์ด๋ฏธ์ง | StableDiffusionImg2ImgPipeline | stable-diffusion-v1-5/stable-diffusion-v1-5 |
์ด๋ฏธ์ง ๋ณต์ | StableDiffusionInpaintPipeline | runwayml/stable-diffusion-inpainting |
์ด๋ฏธ์ง ๋ณํ | StableDiffusionImageVariationPipeline | lambdalabs/sd-image-variations-diffusers |
์ด๋ฏธ์ง ์ดํด์๋ | StableDiffusionUpscalePipeline | stabilityai/stable-diffusion-x4-upscaler |
์ ์ฌ ๊ณต๊ฐ ์ดํด์๋ | StableDiffusionLatentUpscalePipeline | stabilityai/sd-x2-latent-upscaler |
๋ฌธ์ ๊ตฌ์กฐ
๋ฌธ์ ์ ํ | ํ์ต ๋ด์ฉ |
---|---|
Tutorial | ๋ชจ๋ธ ๋ฐ ์ค์ผ์ค๋ฌ๋ฅผ ์ฌ์ฉํ์ฌ ํ์ฐ ์์คํ ๊ตฌ์ถ, ์์ ๋ง์ ํ์ฐ ๋ชจ๋ธ ํ๋ จ๊ณผ ๊ฐ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๊ธฐ๋ณธ ๊ธฐ์ ํ์ต |
Loading | ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋ชจ๋ ๊ตฌ์ฑ ์์(ํ์ดํ๋ผ์ธ, ๋ชจ๋ธ ๋ฐ ์ค์ผ์ค๋ฌ)๋ฅผ ๋ก๋ํ๊ณ ๊ตฌ์ฑํ๋ ๋ฐฉ๋ฒ, ๋ค์ํ ์ค์ผ์ค๋ฌ๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ |
Pipelines for inference | ํ์ดํ๋ผ์ธ์ ์ฌ์ฉํ์ฌ ๋ค์ํ ์ถ๋ก ์์ ์ํ, ์ผ๊ด ์์ฑ, ์์ฑ ์ถ๋ ฅ ๋ฐ ๋ฌด์์์ฑ ์ ์ด ๋ฐฉ๋ฒ |
Optimization | ๋ฉ๋ชจ๋ฆฌ ์ ํ์ ์ธ ํ๋์จ์ด์์ ์คํํ๊ณ ์ถ๋ก ์๋๋ฅผ ๋์ด๊ธฐ ์ํด ํ์ดํ๋ผ์ธ์ ์ต์ ํํ๋ ๋ฐฉ๋ฒ |
Training | ๋ค์ํ ์์ ์ ์ํด ์์ ๋ง์ ํ์ฐ ๋ชจ๋ธ์ ํ๋ จํ๋ ๋ฐฉ๋ฒ |
์ปค๋ฎค๋ํฐ ์ํ๊ณ
ํตํฉ ํ๋ก์ ํธ
- Microsoft TaskMatrix
- InvokeAI
- InstantID
- Apple ML Stable Diffusion
- Lama Cleaner
- Grounded Segment Anything
- Stable DreamFusion
- DeepFloyd IF
- BentoML
- Kohya_ss
์์ฝ
๐ค Diffusers๋ ํ์ฌ ๊ฐ์ฅ ์์ ํ๊ณ ์ฌ์ฉํ๊ธฐ ์ฌ์ด ํ์ฐ ๋ชจ๋ธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค ํ๋์ ๋๋ค. ํ๋ถํ ์ฌ์ ํ๋ จ๋ ๋ชจ๋ธ๊ณผ ํ์ดํ๋ผ์ธ์ ์ ๊ณตํ ๋ฟ๋ง ์๋๋ผ ์ฌ์ฉ์ ์ ์ ํ๋ จ ๋ฐ ์ต์ ํ๋ฅผ ์ง์ํฉ๋๋ค. AI ์ฐ๊ตฌ์, ๊ฐ๋ฐ์ ๋๋ ์ฐฝ์์ ๋ชจ๋ ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ์์ ๋ค์ํ ์์ฑ AI ์ ํ๋ฆฌ์ผ์ด์ ์ ๊ตฌํํ๋ ๋ฐ ํ์ํ ๋๊ตฌ๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.