Buckets:
Kandinsky 2.2
Kandinsky 2.2๋ Arseniy Shakhmatov, Anton Razzhigaev, Aleksandr Nikolich, Vladimir Arkhipkin, Igor Pavlov, Andrey Kuznetsov, Denis Dimitrov์ ์ํด ๊ฐ๋ฐ๋์์ต๋๋ค.
GitHub ํ์ด์ง์ ์ค๋ช ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค:
Kandinsky 2.2๋ ์ด์ ๋ฒ์ ์ธ Kandinsky 2.1์ ๋นํด ์๋ก์ด ์ด๋ฏธ์ง ์ธ์ฝ๋์ธ CLIP-ViT-G์ ControlNet ์ง์์ ๋์ ํจ์ผ๋ก์จ ์๋นํ ์ฑ๋ฅ ํฅ์์ ๊ฐ์ ธ์์ต๋๋ค. ์ด๋ฏธ์ง ์ธ์ฝ๋๋ฅผ CLIP-ViT-G๋ก ์ ํํ ๊ฒ์ ๋ชจ๋ธ์ด ๋ ๋ฏธํ์ ์ธ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๊ณ ํ ์คํธ๋ฅผ ๋ ์ ์ดํดํ๋ ๋ฅ๋ ฅ์ ํฌ๊ฒ ํฅ์์์ผ ๋ชจ๋ธ์ ์ ๋ฐ์ ์ธ ์ฑ๋ฅ์ ๋์์ต๋๋ค. ControlNet ๋ฉ์ปค๋์ฆ์ ์ถ๊ฐ๋ ๋ชจ๋ธ์ด ์ด๋ฏธ์ง ์์ฑ ๊ณผ์ ์ ํจ๊ณผ์ ์ผ๋ก ์ ์ดํ ์ ์๊ฒ ํฉ๋๋ค. ์ด๋ฅผ ํตํด ๋ ์ ํํ๊ณ ์๊ฐ์ ์ผ๋ก ๋งค๋ ฅ์ ์ธ ์ถ๋ ฅ์ด ๊ฐ๋ฅํด์ง๋ฉฐ, ํ ์คํธ ๊ธฐ๋ฐ ์ด๋ฏธ์ง ์กฐ์์ ๋ํ ์๋ก์ด ๊ฐ๋ฅ์ฑ์ ์ด์ด์ค๋๋ค.
์๋ณธ ์ฝ๋๋ฒ ์ด์ค๋ ai-forever/Kandinsky-2์์ ์ฐพ์ ์ ์์ต๋๋ค.
Hub์ Kandinsky Community ์กฐ์ง์์ ํ ์คํธ-์ด๋ฏธ์ง, ์ด๋ฏธ์ง-์ด๋ฏธ์ง, ์ธํ์ธํ ๊ณผ ๊ฐ์ ์์ ์ ๋ํ ๊ณต์ ๋ชจ๋ธ ์ฒดํฌํฌ์ธํธ๋ฅผ ํ์ธํด ๋ณด์ธ์.
์ค์ผ์ค๋ฌ์ ๊ฐ์ด๋๋ฅผ ํ์ธํ์ฌ ์ค์ผ์ค๋ฌ์ ์๋์ ํ์ง ์ฌ์ด์ ํธ๋ ์ด๋์คํ๋ฅผ ํ์ํ๋ ๋ฐฉ๋ฒ์ ๋ฐฐ์ฐ๊ณ , ํ์ดํ๋ผ์ธ ๊ฐ ๊ตฌ์ฑ ์์ ์ฌ์ฌ์ฉ ์น์ ์ ํ์ธํ์ฌ ๋์ผํ ๊ตฌ์ฑ ์์๋ฅผ ์ฌ๋ฌ ํ์ดํ๋ผ์ธ์ ํจ์จ์ ์ผ๋ก ๋ก๋ํ๋ ๋ฐฉ๋ฒ์ ๋ฐฐ์๋ณด์ธ์.
KandinskyV22PriorPipeline[[diffusers.KandinskyV22PriorPipeline]]
diffusers.KandinskyV22PriorPipeline[[diffusers.KandinskyV22PriorPipeline]]
diffusers.KandinskyV22PriorPipeline(prior: PriorTransformer, image_encoder: CLIPVisionModelWithProjection, text_encoder: CLIPTextModelWithProjection, tokenizer: CLIPTokenizer, scheduler: UnCLIPScheduler, image_processor: CLIPImageProcessorPil)
๋งค๊ฐ๋ณ์:
prior (PriorTransformer) : ํ ์คํธ ์๋ฒ ๋ฉ์์ ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ ๊ทผ์ฌํ๊ธฐ ์ํ unCLIP์ ํ์ค ์ฌ์ ๋ถํฌ ๋ชจ๋ธ.
image_encoder (CLIPVisionModelWithProjection) : ๊ณ ์ ๋ ์ด๋ฏธ์ง ์ธ์ฝ๋.
text_encoder (CLIPTextModelWithProjection) : ๊ณ ์ ๋ ํ
์คํธ ์ธ์ฝ๋.
tokenizer (CLIPTokenizer) : CLIPTokenizer ํด๋์ค์ ํ ํฌ๋์ด์ .
scheduler (UnCLIPScheduler) : prior์ ํจ๊ป ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ ์์ฑํ๋ ์ค์ผ์ค๋ฌ์
๋๋ค.
image_processor (CLIPImageProcessor) : clip์์ ์ด๋ฏธ์ง๋ฅผ ์ ์ฒ๋ฆฌํ๋ ๋ฐ ์ฌ์ฉ๋๋ image_processor์
๋๋ค.
Kandinsky์ ์ด๋ฏธ์ง prior๋ฅผ ์์ฑํ๋ Pipeline
์ด ๋ชจ๋ธ์ DiffusionPipeline์์ ์์๋ฉ๋๋ค. ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ๋ชจ๋ ํ์ดํ๋ผ์ธ์ ๋ํด ๊ตฌํํ๋ ์ผ๋ฐ์ ๋ฉ์๋(๋ค์ด๋ก๋ ๋๋ ์ ์ฅ, ํน์ ๋๋ฐ์ด์ค์์ ์คํ ๋ฑ)์ ๋ํด์๋ ์์ ํด๋์ค ๋ฌธ์๋ฅผ ํ์ธํ์ธ์.
ํธ์ถ[[diffusers.KandinskyV22PriorPipeline.call]]
__call__(prompt: str | list[str], negative_prompt: str | list[str] | None = None, num_images_per_prompt: int = 1, num_inference_steps: int = 25, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, guidance_scale: float = 4.0, output_type: str | None = 'pt', return_dict: bool = True, callback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'])
๋งค๊ฐ๋ณ์:
prompt (str ๋๋ list[str]) : ์ด๋ฏธ์ง ์์ฑ์ ์๋ดํ๋ ํ๋กฌํํธ ๋๋ ํ๋กฌํํธ ๋ชฉ๋ก์
๋๋ค.
negative_prompt (str ๋๋ list[str], ์ ํ ์ฌํญ) : ์ด๋ฏธ์ง ์์ฑ์ ์๋ดํ์ง ์์ ํ๋กฌํํธ์
๋๋ค. ๊ฐ์ด๋์ค๋ฅผ ์ฌ์ฉํ์ง ์๋ ๊ฒฝ์ฐ ๋ฌด์๋ฉ๋๋ค(์ฆ, guidance_scale์ด 1๋ณด๋ค ์์ ๊ฒฝ์ฐ ๋ฌด์๋ฉ๋๋ค).
num_images_per_prompt (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 1) : ํ๋กฌํํธ๋น ์์ฑํ ์ด๋ฏธ์ง์ ์.
num_inference_steps (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 100) : ๋๋
ธ์ด์ง ๋จ๊ณ์ ์์
๋๋ค. ๋๋
ธ์ด์ง ๋จ๊ณ๊ฐ ๋ง์์๋ก ์ผ๋ฐ์ ์ผ๋ก ์ถ๋ก ์๋๊ฐ ๋๋ ค์ง๋ ๋์ ๋ ๋์ ํ์ง์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํฉ๋๋ค.
generator (torch.Generator ๋๋ list[torch.Generator], ์ ํ ์ฌํญ) : ์์ฑ์ ๊ฒฐ์ ์ ์ผ๋ก ๋ง๋ค๊ธฐ ์ํ torch generator ํ๋ ๋๋ ๋ชฉ๋ก.
latents (torch.Tensor, ์ ํ ์ฌํญ) : ์ด๋ฏธ์ง ์์ฑ์ ์
๋ ฅ์ผ๋ก ์ฌ์ฉํ ๊ฐ์ฐ์์ ๋ถํฌ์์ ์ํ๋ง๋ ์ฌ์ ์์ฑ๋ ๋
ธ์ด์ฆ๋ latents์
๋๋ค. ๋์ผํ ์์ฑ์ ๋ค๋ฅธ ํ๋กฌํํธ๋ก ์กฐ์ ํ๋ ๋ฐ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์ ๊ณต๋์ง ์์ผ๋ฉด, ์ ๊ณต๋ ๋๋ค generator๋ฅผ ์ฌ์ฉํ์ฌ ์ํ๋งํ์ฌ latents ํ
์๊ฐ ์์ฑ๋ฉ๋๋ค.
guidance_scale (float, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 4.0) : Classifier-Free Diffusion Guidance์์ ์ ์ํ ๊ฐ์ด๋์ค ์ค์ผ์ผ์
๋๋ค. guidance_scale์ Imagen Paper์ 2๋ฒ ์์ w๋ก ์ ์๋ฉ๋๋ค. guidance_scale > 1๋ก ์ค์ ํ๋ฉด ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ํ์ฑํ๋ฉ๋๋ค. ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ๋์์๋ก prompt ํ
์คํธ์ ๋ฐ์ ํ๊ฒ ์ฐ๊ฒฐ๋ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋๋ก ์ฅ๋ คํ์ง๋ง, ์ผ๋ฐ์ ์ผ๋ก ์ด๋ฏธ์ง ํ์ง์ด ๋ฎ์์ง๋ ๋๊ฐ๋ฅผ ์น๋ฆ
๋๋ค.
output_type (str, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ "pt") : ์ด๋ฏธ์ง ์์ฑ์ ์ถ๋ ฅ ํ์์
๋๋ค. ๋ค์ ์ค ํ๋๋ฅผ ์ ํํฉ๋๋ค: "np" (np.array) ๋๋ "pt" (torch.Tensor).
return_dict (bool, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ True) : ์ผ๋ฐ ํํ ๋์ ImagePipelineOutput์ ๋ฐํํ ์ง ์ฌ๋ถ.
callback_on_step_end (Callable, ์ ํ ์ฌํญ) : ์ถ๋ก ์ค ๊ฐ ๋๋
ธ์ด์ง ๋จ๊ณ์ ๋์์ ํธ์ถ๋๋ ํจ์์
๋๋ค. ์ด ํจ์๋ ๋ค์ ์ธ์๋ฅผ ๋ฐ์ ํธ์ถ๋ฉ๋๋ค: callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict). callback_kwargs์๋ callback_on_step_end_tensor_inputs๋ก ์ง์ ๋ ๋ชจ๋ ํ
์ ๋ชฉ๋ก์ด ํฌํจ๋ฉ๋๋ค.
callback_on_step_end_tensor_inputs (list, ์ ํ ์ฌํญ) : callback_on_step_end ํจ์์ ํ
์ ์
๋ ฅ ๋ชฉ๋ก์
๋๋ค. ๋ชฉ๋ก์ ์ง์ ๋ ํ
์๋ callback_kwargs ์ธ์๋ก ์ ๋ฌ๋ฉ๋๋ค. ํ์ดํ๋ผ์ธ ํด๋์ค์ ._callback_tensor_inputs ์์ฑ์ ๋์ด๋ ๋ณ์๋ง ํฌํจํ ์ ์์ต๋๋ค.
๋ฐํ๊ฐ: KandinskyPriorPipelineOutput ๋๋ tuple
์์ฑ์ ์ํด ํ์ดํ๋ผ์ธ์ ํธ์ถํ ๋ ํธ์ถ๋๋ ํจ์.
์:
>>> from diffusers import KandinskyV22Pipeline, KandinskyV22PriorPipeline
>>> import torch
>>> pipe_prior = KandinskyV22PriorPipeline.from_pretrained("kandinsky-community/kandinsky-2-2-prior")
>>> pipe_prior.to("cuda")
>>> prompt = "red cat, 4k photo"
>>> image_emb, negative_image_emb = pipe_prior(prompt).to_tuple()
>>> pipe = KandinskyV22Pipeline.from_pretrained("kandinsky-community/kandinsky-2-2-decoder")
>>> pipe.to("cuda")
>>> image = pipe(
... image_embeds=image_emb,
... negative_image_embeds=negative_image_emb,
... height=768,
... width=768,
... num_inference_steps=50,
... ).images
>>> image[0].save("cat.png")
interpolate[[diffusers.KandinskyV22PriorPipeline.interpolate]]
interpolate(images_and_prompts: list[typing.Union[str, PIL.Image.Image, torch.Tensor]], weights: list[float], num_images_per_prompt: int = 1, num_inference_steps: int = 25, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, negative_prior_prompt: str | None = None, negative_prompt: str = '', guidance_scale: float = 4.0, device = None)
๋งค๊ฐ๋ณ์:
images_and_prompts (list[str | PIL.Image.Image | torch.Tensor]) : ์ด๋ฏธ์ง ์์ฑ์ ์๋ดํ ํ๋กฌํํธ์ ์ด๋ฏธ์ง์ ๋ชฉ๋ก.
weights : (list[float]): images_and_prompts์ ๊ฐ ์กฐ๊ฑด์ ๋ํ ๊ฐ์ค์น ๋ชฉ๋ก
num_images_per_prompt (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 1) : ํ๋กฌํํธ๋น ์์ฑํ ์ด๋ฏธ์ง์ ์.
num_inference_steps (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 100) : ๋๋
ธ์ด์ง ๋จ๊ณ์ ์์
๋๋ค. ๋๋
ธ์ด์ง ๋จ๊ณ๊ฐ ๋ง์์๋ก ์ผ๋ฐ์ ์ผ๋ก ์ถ๋ก ์๋๊ฐ ๋๋ ค์ง๋ ๋์ ๋ ๋์ ํ์ง์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํฉ๋๋ค.
generator (torch.Generator ๋๋ list[torch.Generator], ์ ํ ์ฌํญ) : ์์ฑ์ ๊ฒฐ์ ์ ์ผ๋ก ๋ง๋ค๊ธฐ ์ํ torch generator ํ๋ ๋๋ ๋ชฉ๋ก.
latents (torch.Tensor, ์ ํ ์ฌํญ) : ์ด๋ฏธ์ง ์์ฑ์ ์
๋ ฅ์ผ๋ก ์ฌ์ฉํ ๊ฐ์ฐ์์ ๋ถํฌ์์ ์ํ๋ง๋ ์ฌ์ ์์ฑ๋ ๋
ธ์ด์ฆ๋ latents์
๋๋ค. ๋์ผํ ์์ฑ์ ๋ค๋ฅธ ํ๋กฌํํธ๋ก ์กฐ์ ํ๋ ๋ฐ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์ ๊ณต๋์ง ์์ผ๋ฉด, ์ ๊ณต๋ ๋๋ค generator๋ฅผ ์ฌ์ฉํ์ฌ ์ํ๋งํ์ฌ latents ํ
์๊ฐ ์์ฑ๋ฉ๋๋ค.
negative_prior_prompt (str, ์ ํ ์ฌํญ) : ์ด์ ํ์ฐ ๊ณผ์ ์ ์๋ดํ์ง ์์ ํ๋กฌํํธ์
๋๋ค. ๊ฐ์ด๋์ค๋ฅผ ์ฌ์ฉํ์ง ์๋ ๊ฒฝ์ฐ ๋ฌด์๋ฉ๋๋ค(์ฆ, guidance_scale์ด 1๋ณด๋ค ์์ ๊ฒฝ์ฐ ๋ฌด์๋ฉ๋๋ค).
negative_prompt (str ๋๋ list[str], ์ ํ ์ฌํญ) : ์ด๋ฏธ์ง ์์ฑ์ ์๋ดํ์ง ์์ ํ๋กฌํํธ์
๋๋ค. ๊ฐ์ด๋์ค๋ฅผ ์ฌ์ฉํ์ง ์๋ ๊ฒฝ์ฐ ๋ฌด์๋ฉ๋๋ค(์ฆ, guidance_scale์ด 1๋ณด๋ค ์์ ๊ฒฝ์ฐ ๋ฌด์๋ฉ๋๋ค).
guidance_scale (float, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 4.0) : Classifier-Free Diffusion Guidance์์ ์ ์ํ ๊ฐ์ด๋์ค ์ค์ผ์ผ์
๋๋ค. guidance_scale์ Imagen Paper์ 2๋ฒ ์์ w๋ก ์ ์๋ฉ๋๋ค. guidance_scale > 1๋ก ์ค์ ํ๋ฉด ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ํ์ฑํ๋ฉ๋๋ค. ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ๋์์๋ก prompt ํ
์คํธ์ ๋ฐ์ ํ๊ฒ ์ฐ๊ฒฐ๋ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋๋ก ์ฅ๋ คํ์ง๋ง, ์ผ๋ฐ์ ์ผ๋ก ์ด๋ฏธ์ง ํ์ง์ด ๋ฎ์์ง๋ ๋๊ฐ๋ฅผ ์น๋ฆ
๋๋ค.
๋ฐํ๊ฐ: KandinskyPriorPipelineOutput ๋๋ tuple
interpolation์ pipeline์ ์ฌ์ฉํ ๋ ํธ์ถ๋๋ ํจ์์ ๋๋ค.
์:
>>> from diffusers import KandinskyV22PriorPipeline, KandinskyV22Pipeline
>>> from diffusers.utils import load_image
>>> import PIL
>>> import torch
>>> from torchvision import transforms
>>> pipe_prior = KandinskyV22PriorPipeline.from_pretrained(
... "kandinsky-community/kandinsky-2-2-prior", torch_dtype=torch.float16
... )
>>> pipe_prior.to("cuda")
>>> img1 = load_image(
... "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/kandinsky/cat.png"
... )
>>> img2 = load_image(
... "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
... "/kandinsky/starry_night.jpeg"
... )
>>> images_texts = ["a cat", img1, img2]
>>> weights = [0.3, 0.3, 0.4]
>>> out = pipe_prior.interpolate(images_texts, weights)
>>> pipe = KandinskyV22Pipeline.from_pretrained(
... "kandinsky-community/kandinsky-2-2-decoder", torch_dtype=torch.float16
... )
>>> pipe.to("cuda")
>>> image = pipe(
... image_embeds=out.image_embeds,
... negative_image_embeds=out.negative_image_embeds,
... height=768,
... width=768,
... num_inference_steps=50,
... ).images[0]
>>> image.save("starry_cat.png")
KandinskyV22Pipeline[[diffusers.KandinskyV22Pipeline]]
diffusers.KandinskyV22Pipeline[[diffusers.KandinskyV22Pipeline]]
diffusers.KandinskyV22Pipeline(unet: UNet2DConditionModel, scheduler: DDPMScheduler, movq: VQModel)
๋งค๊ฐ๋ณ์:
scheduler (DDIMScheduler | DDPMScheduler) : unet์ ํจ๊ป ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง latents๋ฅผ ์์ฑํ๋ ๋ฐ ์ฌ์ฉ๋๋ ์ค์ผ์ค๋ฌ.
unet (UNet2DConditionModel) : ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ ๋ ธ์ด์ฆ๋ฅผ ์ ๊ฑฐํ๊ธฐ ์ํ ์กฐ๊ฑด๋ถ U-Net ์ํคํ ์ฒ.
movq (VQModel) : latents์์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๊ธฐ ์ํ MoVQ Decoder์ ๋๋ค.
Kandinsky๋ฅผ ์ฌ์ฉํ ํ ์คํธ-์ด๋ฏธ์ง ์์ฑ์ ์ํ Pipeline
์ด ๋ชจ๋ธ์ DiffusionPipeline์์ ์์๋ฉ๋๋ค. ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ๋ชจ๋ ํ์ดํ๋ผ์ธ์ ๋ํด ๊ตฌํํ๋ ์ผ๋ฐ์ ๋ฉ์๋(๋ค์ด๋ก๋ ๋๋ ์ ์ฅ, ํน์ ๋๋ฐ์ด์ค์์ ์คํ ๋ฑ)์ ๋ํด์๋ ์์ ํด๋์ค ๋ฌธ์๋ฅผ ํ์ธํ์ธ์.
ํธ์ถ[[diffusers.KandinskyV22Pipeline.call]]
__call__(image_embeds: typing.Union[torch.Tensor, list[torch.Tensor]], negative_image_embeds: typing.Union[torch.Tensor, list[torch.Tensor]], height: int = 512, width: int = 512, num_inference_steps: int = 100, guidance_scale: float = 4.0, num_images_per_prompt: int = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, callback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], **kwargs)
๋งค๊ฐ๋ณ์:
image_embeds (torch.Tensor ๋๋ list[torch.Tensor]) : ํ
์คํธ ํ๋กฌํํธ์ ๋ํ ํด๋ฆฝ ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ผ๋ก, ์ด๋ฏธ์ง ์์ฑ์ ์กฐ๊ฑดํํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.
negative_image_embeds (torch.Tensor ๋๋ list[torch.Tensor]) : ๋ถ์ ํ
์คํธ ํ๋กฌํํธ์ ๋ํ ํด๋ฆฝ ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ผ๋ก, ์ด๋ฏธ์ง ์์ฑ์ ์กฐ๊ฑดํํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.
height (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 512) : ์์ฑ๋ ์ด๋ฏธ์ง์ ํฝ์
๋จ์ ๋์ด์
๋๋ค.
width (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 512) : ์์ฑ๋ ์ด๋ฏธ์ง์ ํฝ์
๋จ์ ๋๋น์
๋๋ค.
num_inference_steps (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 100) : ๋๋
ธ์ด์ง ๋จ๊ณ์ ์์
๋๋ค. ๋๋
ธ์ด์ง ๋จ๊ณ๊ฐ ๋ง์์๋ก ์ผ๋ฐ์ ์ผ๋ก ์ถ๋ก ์๋๊ฐ ๋๋ ค์ง๋ ๋์ ๋ ๋์ ํ์ง์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํฉ๋๋ค.
guidance_scale (float, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 4.0) : Classifier-Free Diffusion Guidance์์ ์ ์ํ ๊ฐ์ด๋์ค ์ค์ผ์ผ์
๋๋ค. guidance_scale์ Imagen Paper์ 2๋ฒ ์์ w๋ก ์ ์๋ฉ๋๋ค. guidance_scale > 1๋ก ์ค์ ํ๋ฉด ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ํ์ฑํ๋ฉ๋๋ค. ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ๋์์๋ก prompt ํ
์คํธ์ ๋ฐ์ ํ๊ฒ ์ฐ๊ฒฐ๋ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋๋ก ์ฅ๋ คํ์ง๋ง, ์ผ๋ฐ์ ์ผ๋ก ์ด๋ฏธ์ง ํ์ง์ด ๋ฎ์์ง๋ ๋๊ฐ๋ฅผ ์น๋ฆ
๋๋ค.
num_images_per_prompt (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 1) : ํ๋กฌํํธ๋น ์์ฑํ ์ด๋ฏธ์ง์ ์.
generator (torch.Generator ๋๋ list[torch.Generator], ์ ํ ์ฌํญ) : ์์ฑ์ ๊ฒฐ์ ์ ์ผ๋ก ๋ง๋ค๊ธฐ ์ํ torch generator ํ๋ ๋๋ ๋ชฉ๋ก.
latents (torch.Tensor, ์ ํ ์ฌํญ) : ์ด๋ฏธ์ง ์์ฑ์ ์
๋ ฅ์ผ๋ก ์ฌ์ฉํ ๊ฐ์ฐ์์ ๋ถํฌ์์ ์ํ๋ง๋ ์ฌ์ ์์ฑ๋ ๋
ธ์ด์ฆ๋ latents์
๋๋ค. ๋์ผํ ์์ฑ์ ๋ค๋ฅธ ํ๋กฌํํธ๋ก ์กฐ์ ํ๋ ๋ฐ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์ ๊ณต๋์ง ์์ผ๋ฉด, ์ ๊ณต๋ ๋๋ค generator๋ฅผ ์ฌ์ฉํ์ฌ ์ํ๋งํ์ฌ latents ํ
์๊ฐ ์์ฑ๋ฉ๋๋ค.
output_type (str, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ "pil") : ์ด๋ฏธ์ง ์์ฑ์ ์ถ๋ ฅ ํ์์
๋๋ค. ๋ค์ ์ค ํ๋๋ฅผ ์ ํํฉ๋๋ค: "pil" (PIL.Image.Image), "np" (np.array) ๋๋ "pt" (torch.Tensor).
return_dict (bool, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ True) : ์ผ๋ฐ ํํ ๋์ ImagePipelineOutput์ ๋ฐํํ ์ง ์ฌ๋ถ.
callback_on_step_end (Callable, ์ ํ ์ฌํญ) : ์ถ๋ก ์ค ๊ฐ ๋๋
ธ์ด์ง ๋จ๊ณ์ ๋์์ ํธ์ถ๋๋ ํจ์์
๋๋ค. ์ด ํจ์๋ ๋ค์ ์ธ์๋ฅผ ๋ฐ์ ํธ์ถ๋ฉ๋๋ค: callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict). callback_kwargs์๋ callback_on_step_end_tensor_inputs๋ก ์ง์ ๋ ๋ชจ๋ ํ
์ ๋ชฉ๋ก์ด ํฌํจ๋ฉ๋๋ค.
callback_on_step_end_tensor_inputs (list, ์ ํ ์ฌํญ) : callback_on_step_end ํจ์์ ํ
์ ์
๋ ฅ ๋ชฉ๋ก์
๋๋ค. ๋ชฉ๋ก์ ์ง์ ๋ ํ
์๋ callback_kwargs ์ธ์๋ก ์ ๋ฌ๋ฉ๋๋ค. ํ์ดํ๋ผ์ธ ํด๋์ค์ ._callback_tensor_inputs ์์ฑ์ ๋์ด๋ ๋ณ์๋ง ํฌํจํ ์ ์์ต๋๋ค.
๋ฐํ๊ฐ: ImagePipelineOutput ๋๋ tuple
์์ฑ์ ์ํด ํ์ดํ๋ผ์ธ์ ํธ์ถํ ๋ ํธ์ถ๋๋ ํจ์.
์:
>>> from diffusers import KandinskyV22Pipeline, KandinskyV22PriorPipeline
>>> import torch
>>> pipe_prior = KandinskyV22PriorPipeline.from_pretrained("kandinsky-community/kandinsky-2-2-prior")
>>> pipe_prior.to("cuda")
>>> prompt = "red cat, 4k photo"
>>> out = pipe_prior(prompt)
>>> image_emb = out.image_embeds
>>> zero_image_emb = out.negative_image_embeds
>>> pipe = KandinskyV22Pipeline.from_pretrained("kandinsky-community/kandinsky-2-2-decoder")
>>> pipe.to("cuda")
>>> image = pipe(
... image_embeds=image_emb,
... negative_image_embeds=zero_image_emb,
... height=768,
... width=768,
... num_inference_steps=50,
... ).images
>>> image[0].save("cat.png")
KandinskyV22CombinedPipeline[[diffusers.KandinskyV22CombinedPipeline]]
diffusers.KandinskyV22CombinedPipeline[[diffusers.KandinskyV22CombinedPipeline]]
diffusers.KandinskyV22CombinedPipeline(unet: UNet2DConditionModel, scheduler: DDPMScheduler, movq: VQModel, prior_prior: PriorTransformer, prior_image_encoder: CLIPVisionModelWithProjection, prior_text_encoder: CLIPTextModelWithProjection, prior_tokenizer: CLIPTokenizer, prior_scheduler: UnCLIPScheduler, prior_image_processor: CLIPImageProcessorPil)
๋งค๊ฐ๋ณ์:
scheduler (DDIMScheduler | DDPMScheduler) : unet์ ํจ๊ป ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง latents๋ฅผ ์์ฑํ๋ ๋ฐ ์ฌ์ฉ๋๋ ์ค์ผ์ค๋ฌ.
unet (UNet2DConditionModel) : ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ ๋ ธ์ด์ฆ๋ฅผ ์ ๊ฑฐํ๊ธฐ ์ํ ์กฐ๊ฑด๋ถ U-Net ์ํคํ ์ฒ.
movq (VQModel) : latents์์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๊ธฐ ์ํ MoVQ Decoder์ ๋๋ค.
prior_prior (PriorTransformer) : ํ ์คํธ ์๋ฒ ๋ฉ์์ ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ ๊ทผ์ฌํ๊ธฐ ์ํ unCLIP์ ํ์ค ์ฌ์ ๋ถํฌ ๋ชจ๋ธ.
prior_image_encoder (CLIPVisionModelWithProjection) : ๊ณ ์ ๋ ์ด๋ฏธ์ง ์ธ์ฝ๋.
prior_text_encoder (CLIPTextModelWithProjection) : ๊ณ ์ ๋ ํ
์คํธ ์ธ์ฝ๋.
prior_tokenizer (CLIPTokenizer) : CLIPTokenizer ํด๋์ค์ ํ ํฌ๋์ด์ .
prior_scheduler (UnCLIPScheduler) : prior์ ํจ๊ป ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ ์์ฑํ๋ ์ค์ผ์ค๋ฌ์
๋๋ค.
prior_image_processor (CLIPImageProcessor) : clip์์ ์ด๋ฏธ์ง๋ฅผ ์ ์ฒ๋ฆฌํ๋ ๋ฐ ์ฌ์ฉ๋๋ image_processor์
๋๋ค.
Kandinsky๋ฅผ ์ฌ์ฉํ ํ ์คํธ-์ด๋ฏธ์ง ์์ฑ์ ์ํ ํตํฉ Pipeline
์ด ๋ชจ๋ธ์ DiffusionPipeline์์ ์์๋ฉ๋๋ค. ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ๋ชจ๋ ํ์ดํ๋ผ์ธ์ ๋ํด ๊ตฌํํ๋ ์ผ๋ฐ์ ๋ฉ์๋(๋ค์ด๋ก๋ ๋๋ ์ ์ฅ, ํน์ ๋๋ฐ์ด์ค์์ ์คํ ๋ฑ)์ ๋ํด์๋ ์์ ํด๋์ค ๋ฌธ์๋ฅผ ํ์ธํ์ธ์.
ํธ์ถ[[diffusers.KandinskyV22CombinedPipeline.call]]
__call__(prompt: str | list[str], negative_prompt: str | list[str] | None = None, num_inference_steps: int = 100, guidance_scale: float = 4.0, num_images_per_prompt: int = 1, height: int = 512, width: int = 512, prior_guidance_scale: float = 4.0, prior_num_inference_steps: int = 25, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', callback: typing.Optional[typing.Callable[[int, int, torch.Tensor], NoneType]] = None, callback_steps: int = 1, return_dict: bool = True, prior_callback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = None, prior_callback_on_step_end_tensor_inputs: list[str] = ['latents'], callback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'])
๋งค๊ฐ๋ณ์:
prompt (str ๋๋ list[str]) : ์ด๋ฏธ์ง ์์ฑ์ ์๋ดํ๋ ํ๋กฌํํธ ๋๋ ํ๋กฌํํธ ๋ชฉ๋ก์
๋๋ค.
negative_prompt (str ๋๋ list[str], ์ ํ ์ฌํญ) : ์ด๋ฏธ์ง ์์ฑ์ ์๋ดํ์ง ์์ ํ๋กฌํํธ์
๋๋ค. ๊ฐ์ด๋์ค๋ฅผ ์ฌ์ฉํ์ง ์๋ ๊ฒฝ์ฐ ๋ฌด์๋ฉ๋๋ค(์ฆ, guidance_scale์ด 1๋ณด๋ค ์์ ๊ฒฝ์ฐ ๋ฌด์๋ฉ๋๋ค).
num_images_per_prompt (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 1) : ํ๋กฌํํธ๋น ์์ฑํ ์ด๋ฏธ์ง์ ์.
num_inference_steps (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 100) : ๋๋
ธ์ด์ง ๋จ๊ณ์ ์์
๋๋ค. ๋๋
ธ์ด์ง ๋จ๊ณ๊ฐ ๋ง์์๋ก ์ผ๋ฐ์ ์ผ๋ก ์ถ๋ก ์๋๊ฐ ๋๋ ค์ง๋ ๋์ ๋ ๋์ ํ์ง์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํฉ๋๋ค.
height (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 512) : ์์ฑ๋ ์ด๋ฏธ์ง์ ํฝ์
๋จ์ ๋์ด์
๋๋ค.
width (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 512) : ์์ฑ๋ ์ด๋ฏธ์ง์ ํฝ์
๋จ์ ๋๋น์
๋๋ค.
prior_guidance_scale (float, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 4.0) : Classifier-Free Diffusion Guidance์์ ์ ์ํ ๊ฐ์ด๋์ค ์ค์ผ์ผ์
๋๋ค. guidance_scale์ Imagen Paper์ 2๋ฒ ์์ w๋ก ์ ์๋ฉ๋๋ค. guidance_scale > 1๋ก ์ค์ ํ๋ฉด ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ํ์ฑํ๋ฉ๋๋ค. ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ๋์์๋ก prompt ํ
์คํธ์ ๋ฐ์ ํ๊ฒ ์ฐ๊ฒฐ๋ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋๋ก ์ฅ๋ คํ์ง๋ง, ์ผ๋ฐ์ ์ผ๋ก ์ด๋ฏธ์ง ํ์ง์ด ๋ฎ์์ง๋ ๋๊ฐ๋ฅผ ์น๋ฆ
๋๋ค.
prior_num_inference_steps (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 100) : ๋๋
ธ์ด์ง ๋จ๊ณ์ ์์
๋๋ค. ๋๋
ธ์ด์ง ๋จ๊ณ๊ฐ ๋ง์์๋ก ์ผ๋ฐ์ ์ผ๋ก ์ถ๋ก ์๋๊ฐ ๋๋ ค์ง๋ ๋์ ๋ ๋์ ํ์ง์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํฉ๋๋ค.
guidance_scale (float, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 4.0) : Classifier-Free Diffusion Guidance์์ ์ ์ํ ๊ฐ์ด๋์ค ์ค์ผ์ผ์
๋๋ค. guidance_scale์ Imagen Paper์ 2๋ฒ ์์ w๋ก ์ ์๋ฉ๋๋ค. guidance_scale > 1๋ก ์ค์ ํ๋ฉด ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ํ์ฑํ๋ฉ๋๋ค. ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ๋์์๋ก prompt ํ
์คํธ์ ๋ฐ์ ํ๊ฒ ์ฐ๊ฒฐ๋ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋๋ก ์ฅ๋ คํ์ง๋ง, ์ผ๋ฐ์ ์ผ๋ก ์ด๋ฏธ์ง ํ์ง์ด ๋ฎ์์ง๋ ๋๊ฐ๋ฅผ ์น๋ฆ
๋๋ค.
generator (torch.Generator ๋๋ list[torch.Generator], ์ ํ ์ฌํญ) : ์์ฑ์ ๊ฒฐ์ ์ ์ผ๋ก ๋ง๋ค๊ธฐ ์ํ torch generator ํ๋ ๋๋ ๋ชฉ๋ก.
latents (torch.Tensor, ์ ํ ์ฌํญ) : ์ด๋ฏธ์ง ์์ฑ์ ์
๋ ฅ์ผ๋ก ์ฌ์ฉํ ๊ฐ์ฐ์์ ๋ถํฌ์์ ์ํ๋ง๋ ์ฌ์ ์์ฑ๋ ๋
ธ์ด์ฆ๋ latents์
๋๋ค. ๋์ผํ ์์ฑ์ ๋ค๋ฅธ ํ๋กฌํํธ๋ก ์กฐ์ ํ๋ ๋ฐ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์ ๊ณต๋์ง ์์ผ๋ฉด, ์ ๊ณต๋ ๋๋ค generator๋ฅผ ์ฌ์ฉํ์ฌ ์ํ๋งํ์ฌ latents ํ
์๊ฐ ์์ฑ๋ฉ๋๋ค.
output_type (str, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ "pil") : ์ด๋ฏธ์ง ์์ฑ์ ์ถ๋ ฅ ํ์์
๋๋ค. ๋ค์ ์ค ํ๋๋ฅผ ์ ํํฉ๋๋ค: "pil" (PIL.Image.Image), "np" (np.array) ๋๋ "pt" (torch.Tensor).
callback (Callable, ์ ํ ์ฌํญ) : ์ถ๋ก ์ค callback_steps ๋จ๊ณ๋ง๋ค ํธ์ถ๋๋ ํจ์์
๋๋ค. ์ด ํจ์๋ ๋ค์ ์ธ์๋ฅผ ๋ฐ์ ํธ์ถ๋ฉ๋๋ค: callback(step: int, timestep: int, latents: torch.Tensor).
callback_steps (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 1) : callback ํจ์๊ฐ ํธ์ถ๋๋ ์ฃผ๊ธฐ์
๋๋ค. ์ง์ ํ์ง ์์ผ๋ฉด ๋ชจ๋ ๋จ๊ณ์์ ์ฝ๋ฐฑ์ด ํธ์ถ๋ฉ๋๋ค.
return_dict (bool, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ True) : ์ผ๋ฐ ํํ ๋์ ImagePipelineOutput์ ๋ฐํํ ์ง ์ฌ๋ถ.
prior_callback_on_step_end (Callable, ์ ํ ์ฌํญ) : prior ํ์ดํ๋ผ์ธ ์ถ๋ก ์ค ๊ฐ denoising ๋จ๊ณ์ ๋์์ ํธ์ถ๋๋ ํจ์์
๋๋ค. ์ด ํจ์๋ ๋ค์ ์ธ์๋ฅผ ๋ฐ์ ํธ์ถ๋ฉ๋๋ค: prior_callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict).
prior_callback_on_step_end_tensor_inputs (list, ์ ํ ์ฌํญ) : prior_callback_on_step_end ํจ์์ ํ
์ ์
๋ ฅ ๋ชฉ๋ก์
๋๋ค. ๋ชฉ๋ก์ ์ง์ ๋ ํ
์๋ callback_kwargs ์ธ์๋ก ์ ๋ฌ๋ฉ๋๋ค. prior ํ์ดํ๋ผ์ธ ํด๋์ค์ ._callback_tensor_inputs ์์ฑ์ ๋์ด๋ ๋ณ์๋ง ํฌํจํ ์ ์์ต๋๋ค.
callback_on_step_end (Callable, ์ ํ ์ฌํญ) : ๋์ฝ๋ ํ์ดํ๋ผ์ธ ์ถ๋ก ์ค ๊ฐ ๋๋
ธ์ด์ง ๋จ๊ณ์ ๋์์ ํธ์ถ๋๋ ํจ์์
๋๋ค. ์ด ํจ์๋ ๋ค์ ์ธ์๋ฅผ ๋ฐ์ ํธ์ถ๋ฉ๋๋ค: callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict). callback_kwargs์๋ callback_on_step_end_tensor_inputs๋ก ์ง์ ๋ ๋ชจ๋ ํ
์ ๋ชฉ๋ก์ด ํฌํจ๋ฉ๋๋ค.
callback_on_step_end_tensor_inputs (list, ์ ํ ์ฌํญ) : callback_on_step_end ํจ์์ ํ
์ ์
๋ ฅ ๋ชฉ๋ก์
๋๋ค. ๋ชฉ๋ก์ ์ง์ ๋ ํ
์๋ callback_kwargs ์ธ์๋ก ์ ๋ฌ๋ฉ๋๋ค. ํ์ดํ๋ผ์ธ ํด๋์ค์ ._callback_tensor_inputs ์์ฑ์ ๋์ด๋ ๋ณ์๋ง ํฌํจํ ์ ์์ต๋๋ค.
๋ฐํ๊ฐ: ImagePipelineOutput ๋๋ tuple
์์ฑ์ ์ํด ํ์ดํ๋ผ์ธ์ ํธ์ถํ ๋ ํธ์ถ๋๋ ํจ์.
์:
from diffusers import AutoPipelineForText2Image
import torch
pipe = AutoPipelineForText2Image.from_pretrained(
"kandinsky-community/kandinsky-2-2-decoder", torch_dtype=torch.float16
)
pipe.enable_model_cpu_offload()
prompt = "A lion in galaxies, spirals, nebulae, stars, smoke, iridescent, intricate detail, octane render, 8k"
image = pipe(prompt=prompt, num_inference_steps=25).images[0]
enable_sequential_cpu_offload[[diffusers.KandinskyV22CombinedPipeline.enable_sequential_cpu_offload]]
enable_sequential_cpu_offload(gpu_id: int | None = None, device: typing.Union[torch.device, str] = None)
Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet, text_encoder, vae and safety checker have their state dicts saved to CPU and then are moved to a torch.device('meta') and loaded to GPU only when their specific submodule has its forwardmethod called. Note that offloading happens on a submodule basis. Memory savings are higher than withenable_model_cpu_offload`, but performance is lower.
KandinskyV22ControlnetPipeline[[diffusers.KandinskyV22ControlnetPipeline]]
diffusers.KandinskyV22ControlnetPipeline[[diffusers.KandinskyV22ControlnetPipeline]]
diffusers.KandinskyV22ControlnetPipeline(unet: UNet2DConditionModel, scheduler: DDPMScheduler, movq: VQModel)
๋งค๊ฐ๋ณ์:
scheduler (DDIMScheduler) : unet์ ํจ๊ป ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง latents๋ฅผ ์์ฑํ๋ ์ค์ผ์ค๋ฌ์
๋๋ค.
unet (UNet2DConditionModel) : ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ ๋ ธ์ด์ฆ๋ฅผ ์ ๊ฑฐํ๊ธฐ ์ํ ์กฐ๊ฑด๋ถ U-Net ์ํคํ ์ฒ.
movq (VQModel) : latents์์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๊ธฐ ์ํ MoVQ Decoder์ ๋๋ค.
Kandinsky๋ฅผ ์ฌ์ฉํ ํ ์คํธ-์ด๋ฏธ์ง ์์ฑ์ ์ํ Pipeline
์ด ๋ชจ๋ธ์ DiffusionPipeline์์ ์์๋ฉ๋๋ค. ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ๋ชจ๋ ํ์ดํ๋ผ์ธ์ ๋ํด ๊ตฌํํ๋ ์ผ๋ฐ์ ๋ฉ์๋(๋ค์ด๋ก๋ ๋๋ ์ ์ฅ, ํน์ ๋๋ฐ์ด์ค์์ ์คํ ๋ฑ)์ ๋ํด์๋ ์์ ํด๋์ค ๋ฌธ์๋ฅผ ํ์ธํ์ธ์.
ํธ์ถ[[diffusers.KandinskyV22ControlnetPipeline.call]]
__call__(image_embeds: typing.Union[torch.Tensor, list[torch.Tensor]], negative_image_embeds: typing.Union[torch.Tensor, list[torch.Tensor]], hint: Tensor, height: int = 512, width: int = 512, num_inference_steps: int = 100, guidance_scale: float = 4.0, num_images_per_prompt: int = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', callback: typing.Optional[typing.Callable[[int, int, torch.Tensor], NoneType]] = None, callback_steps: int = 1, return_dict: bool = True)
๋งค๊ฐ๋ณ์:
hint (torch.Tensor) : ControlNet ์กฐ๊ฑด.
image_embeds (torch.Tensor ๋๋ list[torch.Tensor]) : ํ
์คํธ ํ๋กฌํํธ์ ๋ํ ํด๋ฆฝ ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ผ๋ก, ์ด๋ฏธ์ง ์์ฑ์ ์กฐ๊ฑดํํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.
negative_image_embeds (torch.Tensor ๋๋ list[torch.Tensor]) : ๋ถ์ ํ
์คํธ ํ๋กฌํํธ์ ๋ํ ํด๋ฆฝ ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ผ๋ก, ์ด๋ฏธ์ง ์์ฑ์ ์กฐ๊ฑดํํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.
height (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 512) : ์์ฑ๋ ์ด๋ฏธ์ง์ ํฝ์
๋จ์ ๋์ด์
๋๋ค.
width (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 512) : ์์ฑ๋ ์ด๋ฏธ์ง์ ํฝ์
๋จ์ ๋๋น์
๋๋ค.
num_inference_steps (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 100) : ๋๋
ธ์ด์ง ๋จ๊ณ์ ์์
๋๋ค. ๋๋
ธ์ด์ง ๋จ๊ณ๊ฐ ๋ง์์๋ก ์ผ๋ฐ์ ์ผ๋ก ์ถ๋ก ์๋๊ฐ ๋๋ ค์ง๋ ๋์ ๋ ๋์ ํ์ง์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํฉ๋๋ค.
guidance_scale (float, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 4.0) : Classifier-Free Diffusion Guidance์์ ์ ์ํ ๊ฐ์ด๋์ค ์ค์ผ์ผ์
๋๋ค. guidance_scale์ Imagen Paper์ 2๋ฒ ์์ w๋ก ์ ์๋ฉ๋๋ค. guidance_scale > 1๋ก ์ค์ ํ๋ฉด ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ํ์ฑํ๋ฉ๋๋ค. ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ๋์์๋ก prompt ํ
์คํธ์ ๋ฐ์ ํ๊ฒ ์ฐ๊ฒฐ๋ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋๋ก ์ฅ๋ คํ์ง๋ง, ์ผ๋ฐ์ ์ผ๋ก ์ด๋ฏธ์ง ํ์ง์ด ๋ฎ์์ง๋ ๋๊ฐ๋ฅผ ์น๋ฆ
๋๋ค.
num_images_per_prompt (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 1) : ํ๋กฌํํธ๋น ์์ฑํ ์ด๋ฏธ์ง์ ์.
generator (torch.Generator ๋๋ list[torch.Generator], ์ ํ ์ฌํญ) : ์์ฑ์ ๊ฒฐ์ ์ ์ผ๋ก ๋ง๋ค๊ธฐ ์ํ torch generator ํ๋ ๋๋ ๋ชฉ๋ก.
latents (torch.Tensor, ์ ํ ์ฌํญ) : ์ด๋ฏธ์ง ์์ฑ์ ์
๋ ฅ์ผ๋ก ์ฌ์ฉํ ๊ฐ์ฐ์์ ๋ถํฌ์์ ์ํ๋ง๋ ์ฌ์ ์์ฑ๋ ๋
ธ์ด์ฆ๋ latents์
๋๋ค. ๋์ผํ ์์ฑ์ ๋ค๋ฅธ ํ๋กฌํํธ๋ก ์กฐ์ ํ๋ ๋ฐ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์ ๊ณต๋์ง ์์ผ๋ฉด, ์ ๊ณต๋ ๋๋ค generator๋ฅผ ์ฌ์ฉํ์ฌ ์ํ๋งํ์ฌ latents ํ
์๊ฐ ์์ฑ๋ฉ๋๋ค.
output_type (str, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ "pil") : ์ด๋ฏธ์ง ์์ฑ์ ์ถ๋ ฅ ํ์์
๋๋ค. ๋ค์ ์ค ํ๋๋ฅผ ์ ํํฉ๋๋ค: "pil" (PIL.Image.Image), "np" (np.array) ๋๋ "pt" (torch.Tensor).
callback (Callable, ์ ํ ์ฌํญ) : ์ถ๋ก ์ค callback_steps ๋จ๊ณ๋ง๋ค ํธ์ถ๋๋ ํจ์์
๋๋ค. ์ด ํจ์๋ ๋ค์ ์ธ์๋ฅผ ๋ฐ์ ํธ์ถ๋ฉ๋๋ค: callback(step: int, timestep: int, latents: torch.Tensor).
callback_steps (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 1) : callback ํจ์๊ฐ ํธ์ถ๋๋ ์ฃผ๊ธฐ์
๋๋ค. ์ง์ ํ์ง ์์ผ๋ฉด ๋ชจ๋ ๋จ๊ณ์์ ์ฝ๋ฐฑ์ด ํธ์ถ๋ฉ๋๋ค.
return_dict (bool, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ True) : ์ผ๋ฐ ํํ ๋์ ImagePipelineOutput์ ๋ฐํํ ์ง ์ฌ๋ถ.
๋ฐํ๊ฐ: ImagePipelineOutput ๋๋ tuple
์์ฑ์ ์ํด ํ์ดํ๋ผ์ธ์ ํธ์ถํ ๋ ํธ์ถ๋๋ ํจ์.
์:
KandinskyV22PriorEmb2EmbPipeline[[diffusers.KandinskyV22PriorEmb2EmbPipeline]]
diffusers.KandinskyV22PriorEmb2EmbPipeline[[diffusers.KandinskyV22PriorEmb2EmbPipeline]]
diffusers.KandinskyV22PriorEmb2EmbPipeline(prior: PriorTransformer, image_encoder: CLIPVisionModelWithProjection, text_encoder: CLIPTextModelWithProjection, tokenizer: CLIPTokenizer, scheduler: UnCLIPScheduler, image_processor: CLIPImageProcessorPil)
๋งค๊ฐ๋ณ์:
prior (PriorTransformer) : ํ ์คํธ ์๋ฒ ๋ฉ์์ ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ ๊ทผ์ฌํ๊ธฐ ์ํ unCLIP์ ํ์ค ์ฌ์ ๋ถํฌ ๋ชจ๋ธ.
image_encoder (CLIPVisionModelWithProjection) : ๊ณ ์ ๋ ์ด๋ฏธ์ง ์ธ์ฝ๋.
text_encoder (CLIPTextModelWithProjection) : ๊ณ ์ ๋ ํ
์คํธ ์ธ์ฝ๋.
tokenizer (CLIPTokenizer) : CLIPTokenizer ํด๋์ค์ ํ ํฌ๋์ด์ .
scheduler (UnCLIPScheduler) : prior์ ํจ๊ป ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ ์์ฑํ๋ ์ค์ผ์ค๋ฌ์
๋๋ค.
Kandinsky์ ์ด๋ฏธ์ง prior๋ฅผ ์์ฑํ๋ Pipeline
์ด ๋ชจ๋ธ์ DiffusionPipeline์์ ์์๋ฉ๋๋ค. ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ๋ชจ๋ ํ์ดํ๋ผ์ธ์ ๋ํด ๊ตฌํํ๋ ์ผ๋ฐ์ ๋ฉ์๋(๋ค์ด๋ก๋ ๋๋ ์ ์ฅ, ํน์ ๋๋ฐ์ด์ค์์ ์คํ ๋ฑ)์ ๋ํด์๋ ์์ ํด๋์ค ๋ฌธ์๋ฅผ ํ์ธํ์ธ์.
ํธ์ถ[[diffusers.KandinskyV22PriorEmb2EmbPipeline.call]]
__call__(prompt: str | list[str], image: typing.Union[torch.Tensor, list[torch.Tensor], PIL.Image.Image, list[PIL.Image.Image]], strength: float = 0.3, negative_prompt: str | list[str] | None = None, num_images_per_prompt: int = 1, num_inference_steps: int = 25, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, guidance_scale: float = 4.0, output_type: str | None = 'pt', return_dict: bool = True)
๋งค๊ฐ๋ณ์:
prompt (str ๋๋ list[str]) : ์ด๋ฏธ์ง ์์ฑ์ ์๋ดํ๋ ํ๋กฌํํธ ๋๋ ํ๋กฌํํธ ๋ชฉ๋ก์
๋๋ค.
image (torch.Tensor, PIL.Image.Image, list[torch.Tensor] ๋๋ list[PIL.Image.Image]) : Image ๋๋ ์ด๋ฏธ์ง ๋ฐฐ์น ํ
์. ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ ์์์ ์ผ๋ก ์ฌ์ฉ๋ฉ๋๋ค. image๋ก ์ด๋ฏธ์ง ๋ ์ดํดํธ๋ฅผ ์ง์ ์ ๋ฌํ๋ ๊ฒฝ์ฐ์๋ ํ์ฉ๋๋ฉฐ, ์ด ๊ฒฝ์ฐ ๋ค์ ์ธ์ฝ๋ฉ๋์ง ์์ต๋๋ค.
strength (float, optional, ๊ธฐ๋ณธ๊ฐ 0.8) : ๊ฐ๋
์ ์ผ๋ก ์ฐธ์กฐ image๋ฅผ ์ผ๋ง๋ ๋ณํํ ์ง๋ฅผ ๋ํ๋
๋๋ค. 0๊ณผ 1 ์ฌ์ด์ฌ์ผ ํฉ๋๋ค. image๋ ์์์ ์ผ๋ก ์ฌ์ฉ๋๋ฉฐ, strength ๊ฐ์ด ํด์๋ก ๋ ๋ง์ ๋
ธ์ด์ฆ๊ฐ ์ถ๊ฐ๋ฉ๋๋ค. ๋๋
ธ์ด์ง ๋จ๊ณ์ ์๋ ์ด๊ธฐ์ ์ถ๊ฐ๋ ๋
ธ์ด์ฆ์ ์์ ๋ฐ๋ผ ๋ฌ๋ผ์ง๋๋ค.
negative_prompt (str ๋๋ list[str], ์ ํ ์ฌํญ) : ์ด๋ฏธ์ง ์์ฑ์ ์๋ดํ์ง ์์ ํ๋กฌํํธ์
๋๋ค. ๊ฐ์ด๋์ค๋ฅผ ์ฌ์ฉํ์ง ์๋ ๊ฒฝ์ฐ ๋ฌด์๋ฉ๋๋ค(์ฆ, guidance_scale์ด 1๋ณด๋ค ์์ ๊ฒฝ์ฐ ๋ฌด์๋ฉ๋๋ค).
num_images_per_prompt (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 1) : ํ๋กฌํํธ๋น ์์ฑํ ์ด๋ฏธ์ง์ ์.
num_inference_steps (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 100) : ๋๋
ธ์ด์ง ๋จ๊ณ์ ์์
๋๋ค. ๋๋
ธ์ด์ง ๋จ๊ณ๊ฐ ๋ง์์๋ก ์ผ๋ฐ์ ์ผ๋ก ์ถ๋ก ์๋๊ฐ ๋๋ ค์ง๋ ๋์ ๋ ๋์ ํ์ง์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํฉ๋๋ค.
generator (torch.Generator ๋๋ list[torch.Generator], ์ ํ ์ฌํญ) : ์์ฑ์ ๊ฒฐ์ ์ ์ผ๋ก ๋ง๋ค๊ธฐ ์ํ torch generator ํ๋ ๋๋ ๋ชฉ๋ก.
guidance_scale (float, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 4.0) : Classifier-Free Diffusion Guidance์์ ์ ์ํ ๊ฐ์ด๋์ค ์ค์ผ์ผ์
๋๋ค. guidance_scale์ Imagen Paper์ 2๋ฒ ์์ w๋ก ์ ์๋ฉ๋๋ค. guidance_scale > 1๋ก ์ค์ ํ๋ฉด ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ํ์ฑํ๋ฉ๋๋ค. ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ๋์์๋ก prompt ํ
์คํธ์ ๋ฐ์ ํ๊ฒ ์ฐ๊ฒฐ๋ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋๋ก ์ฅ๋ คํ์ง๋ง, ์ผ๋ฐ์ ์ผ๋ก ์ด๋ฏธ์ง ํ์ง์ด ๋ฎ์์ง๋ ๋๊ฐ๋ฅผ ์น๋ฆ
๋๋ค.
output_type (str, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ "pt") : ์ด๋ฏธ์ง ์์ฑ์ ์ถ๋ ฅ ํ์์
๋๋ค. ๋ค์ ์ค ํ๋๋ฅผ ์ ํํฉ๋๋ค: "np" (np.array) ๋๋ "pt" (torch.Tensor).
return_dict (bool, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ True) : ์ผ๋ฐ ํํ ๋์ ImagePipelineOutput์ ๋ฐํํ ์ง ์ฌ๋ถ.
๋ฐํ๊ฐ: KandinskyPriorPipelineOutput ๋๋ tuple
์์ฑ์ ์ํด ํ์ดํ๋ผ์ธ์ ํธ์ถํ ๋ ํธ์ถ๋๋ ํจ์.
์:
>>> from diffusers import KandinskyV22Pipeline, KandinskyV22PriorEmb2EmbPipeline
>>> import torch
>>> pipe_prior = KandinskyPriorPipeline.from_pretrained(
... "kandinsky-community/kandinsky-2-2-prior", torch_dtype=torch.float16
... )
>>> pipe_prior.to("cuda")
>>> prompt = "red cat, 4k photo"
>>> img = load_image(
... "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/kandinsky/cat.png"
... )
>>> image_emb, nagative_image_emb = pipe_prior(prompt, image=img, strength=0.2).to_tuple()
>>> pipe = KandinskyPipeline.from_pretrained(
... "kandinsky-community/kandinsky-2-2-decoder, torch_dtype=torch.float16"
... )
>>> pipe.to("cuda")
>>> image = pipe(
... image_embeds=image_emb,
... negative_image_embeds=negative_image_emb,
... height=768,
... width=768,
... num_inference_steps=100,
... ).images
>>> image[0].save("cat.png")
interpolate[[diffusers.KandinskyV22PriorEmb2EmbPipeline.interpolate]]
interpolate(images_and_prompts: list[typing.Union[str, PIL.Image.Image, torch.Tensor]], weights: list[float], num_images_per_prompt: int = 1, num_inference_steps: int = 25, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, negative_prior_prompt: str | None = None, negative_prompt: str = '', guidance_scale: float = 4.0, device = None)
๋งค๊ฐ๋ณ์:
images_and_prompts (list[str | PIL.Image.Image | torch.Tensor]) : ์ด๋ฏธ์ง ์์ฑ์ ์๋ดํ ํ๋กฌํํธ์ ์ด๋ฏธ์ง์ ๋ชฉ๋ก.
weights : (list[float]): images_and_prompts์ ๊ฐ ์กฐ๊ฑด์ ๋ํ ๊ฐ์ค์น ๋ชฉ๋ก
num_images_per_prompt (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 1) : ํ๋กฌํํธ๋น ์์ฑํ ์ด๋ฏธ์ง์ ์.
num_inference_steps (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 100) : ๋๋
ธ์ด์ง ๋จ๊ณ์ ์์
๋๋ค. ๋๋
ธ์ด์ง ๋จ๊ณ๊ฐ ๋ง์์๋ก ์ผ๋ฐ์ ์ผ๋ก ์ถ๋ก ์๋๊ฐ ๋๋ ค์ง๋ ๋์ ๋ ๋์ ํ์ง์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํฉ๋๋ค.
generator (torch.Generator ๋๋ list[torch.Generator], ์ ํ ์ฌํญ) : ์์ฑ์ ๊ฒฐ์ ์ ์ผ๋ก ๋ง๋ค๊ธฐ ์ํ torch generator ํ๋ ๋๋ ๋ชฉ๋ก.
latents (torch.Tensor, ์ ํ ์ฌํญ) : ์ด๋ฏธ์ง ์์ฑ์ ์
๋ ฅ์ผ๋ก ์ฌ์ฉํ ๊ฐ์ฐ์์ ๋ถํฌ์์ ์ํ๋ง๋ ์ฌ์ ์์ฑ๋ ๋
ธ์ด์ฆ๋ latents์
๋๋ค. ๋์ผํ ์์ฑ์ ๋ค๋ฅธ ํ๋กฌํํธ๋ก ์กฐ์ ํ๋ ๋ฐ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์ ๊ณต๋์ง ์์ผ๋ฉด, ์ ๊ณต๋ ๋๋ค generator๋ฅผ ์ฌ์ฉํ์ฌ ์ํ๋งํ์ฌ latents ํ
์๊ฐ ์์ฑ๋ฉ๋๋ค.
negative_prior_prompt (str, ์ ํ ์ฌํญ) : ์ด์ ํ์ฐ ๊ณผ์ ์ ์๋ดํ์ง ์์ ํ๋กฌํํธ์
๋๋ค. ๊ฐ์ด๋์ค๋ฅผ ์ฌ์ฉํ์ง ์๋ ๊ฒฝ์ฐ ๋ฌด์๋ฉ๋๋ค(์ฆ, guidance_scale์ด 1๋ณด๋ค ์์ ๊ฒฝ์ฐ ๋ฌด์๋ฉ๋๋ค).
negative_prompt (str ๋๋ list[str], ์ ํ ์ฌํญ) : ์ด๋ฏธ์ง ์์ฑ์ ์๋ดํ์ง ์์ ํ๋กฌํํธ์
๋๋ค. ๊ฐ์ด๋์ค๋ฅผ ์ฌ์ฉํ์ง ์๋ ๊ฒฝ์ฐ ๋ฌด์๋ฉ๋๋ค(์ฆ, guidance_scale์ด 1๋ณด๋ค ์์ ๊ฒฝ์ฐ ๋ฌด์๋ฉ๋๋ค).
guidance_scale (float, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 4.0) : Classifier-Free Diffusion Guidance์์ ์ ์ํ ๊ฐ์ด๋์ค ์ค์ผ์ผ์
๋๋ค. guidance_scale์ Imagen Paper์ 2๋ฒ ์์ w๋ก ์ ์๋ฉ๋๋ค. guidance_scale > 1๋ก ์ค์ ํ๋ฉด ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ํ์ฑํ๋ฉ๋๋ค. ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ๋์์๋ก prompt ํ
์คํธ์ ๋ฐ์ ํ๊ฒ ์ฐ๊ฒฐ๋ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋๋ก ์ฅ๋ คํ์ง๋ง, ์ผ๋ฐ์ ์ผ๋ก ์ด๋ฏธ์ง ํ์ง์ด ๋ฎ์์ง๋ ๋๊ฐ๋ฅผ ์น๋ฆ
๋๋ค.
๋ฐํ๊ฐ: KandinskyPriorPipelineOutput ๋๋ tuple
interpolation์ pipeline์ ์ฌ์ฉํ ๋ ํธ์ถ๋๋ ํจ์์ ๋๋ค.
์:
>>> from diffusers import KandinskyV22PriorEmb2EmbPipeline, KandinskyV22Pipeline
>>> from diffusers.utils import load_image
>>> import PIL
>>> import torch
>>> from torchvision import transforms
>>> pipe_prior = KandinskyV22PriorPipeline.from_pretrained(
... "kandinsky-community/kandinsky-2-2-prior", torch_dtype=torch.float16
... )
>>> pipe_prior.to("cuda")
>>> img1 = load_image(
... "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/kandinsky/cat.png"
... )
>>> img2 = load_image(
... "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
... "/kandinsky/starry_night.jpeg"
... )
>>> images_texts = ["a cat", img1, img2]
>>> weights = [0.3, 0.3, 0.4]
>>> image_emb, zero_image_emb = pipe_prior.interpolate(images_texts, weights)
>>> pipe = KandinskyV22Pipeline.from_pretrained(
... "kandinsky-community/kandinsky-2-2-decoder", torch_dtype=torch.float16
... )
>>> pipe.to("cuda")
>>> image = pipe(
... image_embeds=image_emb,
... negative_image_embeds=zero_image_emb,
... height=768,
... width=768,
... num_inference_steps=150,
... ).images[0]
>>> image.save("starry_cat.png")
KandinskyV22Img2ImgPipeline[[diffusers.KandinskyV22Img2ImgPipeline]]
diffusers.KandinskyV22Img2ImgPipeline[[diffusers.KandinskyV22Img2ImgPipeline]]
diffusers.KandinskyV22Img2ImgPipeline(unet: UNet2DConditionModel, scheduler: DDPMScheduler, movq: VQModel)
๋งค๊ฐ๋ณ์:
scheduler (DDIMScheduler) : unet์ ํจ๊ป ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง latents๋ฅผ ์์ฑํ๋ ์ค์ผ์ค๋ฌ์
๋๋ค.
unet (UNet2DConditionModel) : ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ ๋ ธ์ด์ฆ๋ฅผ ์ ๊ฑฐํ๊ธฐ ์ํ ์กฐ๊ฑด๋ถ U-Net ์ํคํ ์ฒ.
movq (VQModel) : latents์์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๊ธฐ ์ํ MoVQ Decoder์ ๋๋ค.
Kandinsky๋ฅผ ์ฌ์ฉํ ์ด๋ฏธ์ง-์ด๋ฏธ์ง ์์ฑ์ ์ํ Pipeline
์ด ๋ชจ๋ธ์ DiffusionPipeline์์ ์์๋ฉ๋๋ค. ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ๋ชจ๋ ํ์ดํ๋ผ์ธ์ ๋ํด ๊ตฌํํ๋ ์ผ๋ฐ์ ๋ฉ์๋(๋ค์ด๋ก๋ ๋๋ ์ ์ฅ, ํน์ ๋๋ฐ์ด์ค์์ ์คํ ๋ฑ)์ ๋ํด์๋ ์์ ํด๋์ค ๋ฌธ์๋ฅผ ํ์ธํ์ธ์.
ํธ์ถ[[diffusers.KandinskyV22Img2ImgPipeline.call]]
__call__(image_embeds: typing.Union[torch.Tensor, list[torch.Tensor]], image: typing.Union[torch.Tensor, list[torch.Tensor], PIL.Image.Image, list[PIL.Image.Image]], negative_image_embeds: typing.Union[torch.Tensor, list[torch.Tensor]], height: int = 512, width: int = 512, num_inference_steps: int = 100, guidance_scale: float = 4.0, strength: float = 0.3, num_images_per_prompt: int = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, output_type: str | None = 'pil', return_dict: bool = True, callback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], **kwargs)
๋งค๊ฐ๋ณ์:
image_embeds (torch.Tensor ๋๋ list[torch.Tensor]) : ํ
์คํธ ํ๋กฌํํธ์ ๋ํ ํด๋ฆฝ ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ผ๋ก, ์ด๋ฏธ์ง ์์ฑ์ ์กฐ๊ฑดํํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.
image (torch.Tensor, PIL.Image.Image, np.ndarray, list[torch.Tensor], list[PIL.Image.Image], ๋๋ list[np.ndarray]) : Image ๋๋ ์ด๋ฏธ์ง ๋ฐฐ์น ํ
์๋ก, ํ๋ก์ธ์ค์ ์์์ ์ผ๋ก ์ฌ์ฉ๋ฉ๋๋ค. image๋ก ์ด๋ฏธ์ง ๋ ์ดํดํธ๋ฅผ ์ง์ ์ ๋ฌํ๋ ๊ฒฝ์ฐ์๋ ์ด๋ฅผ ๋ฐ์๋ค์ด๋ฉฐ, ์ด ๊ฒฝ์ฐ ๋ค์ ์ธ์ฝ๋ฉํ์ง ์์ต๋๋ค.
strength (float, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 0.8) : ๊ฐ๋
์ ์ผ๋ก ์ฐธ์กฐ image๋ฅผ ์ผ๋ง๋ ๋ณํํ ์ง๋ฅผ ๋ํ๋
๋๋ค. 0๊ณผ 1 ์ฌ์ด์ฌ์ผ ํฉ๋๋ค. image๋ ์์์ ์ผ๋ก ์ฌ์ฉ๋๋ฉฐ, strength ๊ฐ์ด ํด์๋ก ๋ ๋ง์ ๋
ธ์ด์ฆ๊ฐ ์ถ๊ฐ๋ฉ๋๋ค. ๋๋
ธ์ด์ง ๋จ๊ณ์ ์๋ ์ด๊ธฐ์ ์ถ๊ฐ๋ ๋
ธ์ด์ฆ์ ์์ ๋ฐ๋ผ ๊ฒฐ์ ๋ฉ๋๋ค. strength๊ฐ 1์ด๋ฉด ์ถ๊ฐ๋๋ ๋
ธ์ด์ฆ๊ฐ ์ต๋๊ฐ ๋๊ณ , num_inference_steps์ ์ง์ ๋ ์ ์ฒด ๋ฐ๋ณต ํ์๋งํผ ๋๋
ธ์ด์ง ํ๋ก์ธ์ค๊ฐ ์คํ๋ฉ๋๋ค. ๋ฐ๋ผ์ 1์ด๋ผ๋ ๊ฐ์ ์ฌ์ค์ image๋ฅผ ๋ฌด์ํ๋ ๊ฒ๊ณผ ๊ฐ์ต๋๋ค.
negative_image_embeds (torch.Tensor ๋๋ list[torch.Tensor]) : ๋ถ์ ํ
์คํธ ํ๋กฌํํธ์ ๋ํ ํด๋ฆฝ ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ผ๋ก, ์ด๋ฏธ์ง ์์ฑ์ ์กฐ๊ฑดํํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.
height (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 512) : ์์ฑ๋ ์ด๋ฏธ์ง์ ํฝ์
๋จ์ ๋์ด์
๋๋ค.
width (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 512) : ์์ฑ๋ ์ด๋ฏธ์ง์ ํฝ์
๋จ์ ๋๋น์
๋๋ค.
num_inference_steps (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 100) : ๋๋
ธ์ด์ง ๋จ๊ณ์ ์์
๋๋ค. ๋๋
ธ์ด์ง ๋จ๊ณ๊ฐ ๋ง์์๋ก ์ผ๋ฐ์ ์ผ๋ก ์ถ๋ก ์๋๊ฐ ๋๋ ค์ง๋ ๋์ ๋ ๋์ ํ์ง์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํฉ๋๋ค.
guidance_scale (float, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 4.0) : Classifier-Free Diffusion Guidance์์ ์ ์ํ ๊ฐ์ด๋์ค ์ค์ผ์ผ์
๋๋ค. guidance_scale์ Imagen Paper์ 2๋ฒ ์์ w๋ก ์ ์๋ฉ๋๋ค. guidance_scale > 1๋ก ์ค์ ํ๋ฉด ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ํ์ฑํ๋ฉ๋๋ค. ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ๋์์๋ก prompt ํ
์คํธ์ ๋ฐ์ ํ๊ฒ ์ฐ๊ฒฐ๋ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋๋ก ์ฅ๋ คํ์ง๋ง, ์ผ๋ฐ์ ์ผ๋ก ์ด๋ฏธ์ง ํ์ง์ด ๋ฎ์์ง๋ ๋๊ฐ๋ฅผ ์น๋ฆ
๋๋ค.
num_images_per_prompt (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 1) : ํ๋กฌํํธ๋น ์์ฑํ ์ด๋ฏธ์ง์ ์.
generator (torch.Generator ๋๋ list[torch.Generator], ์ ํ ์ฌํญ) : ์์ฑ์ ๊ฒฐ์ ์ ์ผ๋ก ๋ง๋ค๊ธฐ ์ํ torch generator ํ๋ ๋๋ ๋ชฉ๋ก.
output_type (str, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ "pil") : ์ด๋ฏธ์ง ์์ฑ์ ์ถ๋ ฅ ํ์์
๋๋ค. ๋ค์ ์ค ํ๋๋ฅผ ์ ํํฉ๋๋ค: "pil" (PIL.Image.Image), "np" (np.array) ๋๋ "pt" (torch.Tensor).
return_dict (bool, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ True) : ์ผ๋ฐ ํํ ๋์ ImagePipelineOutput์ ๋ฐํํ ์ง ์ฌ๋ถ.
callback_on_step_end (Callable, ์ ํ ์ฌํญ) : ์ถ๋ก ์ค ๊ฐ ๋๋
ธ์ด์ง ๋จ๊ณ์ ๋์์ ํธ์ถ๋๋ ํจ์์
๋๋ค. ์ด ํจ์๋ ๋ค์ ์ธ์๋ฅผ ๋ฐ์ ํธ์ถ๋ฉ๋๋ค: callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict). callback_kwargs์๋ callback_on_step_end_tensor_inputs๋ก ์ง์ ๋ ๋ชจ๋ ํ
์ ๋ชฉ๋ก์ด ํฌํจ๋ฉ๋๋ค.
callback_on_step_end_tensor_inputs (list, ์ ํ ์ฌํญ) : callback_on_step_end ํจ์์ ํ
์ ์
๋ ฅ ๋ชฉ๋ก์
๋๋ค. ๋ชฉ๋ก์ ์ง์ ๋ ํ
์๋ callback_kwargs ์ธ์๋ก ์ ๋ฌ๋ฉ๋๋ค. ํ์ดํ๋ผ์ธ ํด๋์ค์ ._callback_tensor_inputs ์์ฑ์ ๋์ด๋ ๋ณ์๋ง ํฌํจํ ์ ์์ต๋๋ค.
๋ฐํ๊ฐ: ImagePipelineOutput ๋๋ tuple
์์ฑ์ ์ํด ํ์ดํ๋ผ์ธ์ ํธ์ถํ ๋ ํธ์ถ๋๋ ํจ์.
์:
KandinskyV22Img2ImgCombinedPipeline[[diffusers.KandinskyV22Img2ImgCombinedPipeline]]
diffusers.KandinskyV22Img2ImgCombinedPipeline[[diffusers.KandinskyV22Img2ImgCombinedPipeline]]
diffusers.KandinskyV22Img2ImgCombinedPipeline(unet: UNet2DConditionModel, scheduler: DDPMScheduler, movq: VQModel, prior_prior: PriorTransformer, prior_image_encoder: CLIPVisionModelWithProjection, prior_text_encoder: CLIPTextModelWithProjection, prior_tokenizer: CLIPTokenizer, prior_scheduler: UnCLIPScheduler, prior_image_processor: CLIPImageProcessorPil)
๋งค๊ฐ๋ณ์:
scheduler (DDIMScheduler | DDPMScheduler) : unet์ ํจ๊ป ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง latents๋ฅผ ์์ฑํ๋ ๋ฐ ์ฌ์ฉ๋๋ ์ค์ผ์ค๋ฌ.
unet (UNet2DConditionModel) : ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ ๋ ธ์ด์ฆ๋ฅผ ์ ๊ฑฐํ๊ธฐ ์ํ ์กฐ๊ฑด๋ถ U-Net ์ํคํ ์ฒ.
movq (VQModel) : latents์์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๊ธฐ ์ํ MoVQ Decoder์ ๋๋ค.
prior_prior (PriorTransformer) : ํ ์คํธ ์๋ฒ ๋ฉ์์ ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ ๊ทผ์ฌํ๊ธฐ ์ํ unCLIP์ ํ์ค ์ฌ์ ๋ถํฌ ๋ชจ๋ธ.
prior_image_encoder (CLIPVisionModelWithProjection) : ๊ณ ์ ๋ ์ด๋ฏธ์ง ์ธ์ฝ๋.
prior_text_encoder (CLIPTextModelWithProjection) : ๊ณ ์ ๋ ํ
์คํธ ์ธ์ฝ๋.
prior_tokenizer (CLIPTokenizer) : CLIPTokenizer ํด๋์ค์ ํ ํฌ๋์ด์ .
prior_scheduler (UnCLIPScheduler) : prior์ ํจ๊ป ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ ์์ฑํ๋ ์ค์ผ์ค๋ฌ์
๋๋ค.
prior_image_processor (CLIPImageProcessor) : clip์์ ์ด๋ฏธ์ง๋ฅผ ์ ์ฒ๋ฆฌํ๋ ๋ฐ ์ฌ์ฉ๋๋ image_processor์
๋๋ค.
Kandinsky๋ฅผ ์ฌ์ฉํ ์ด๋ฏธ์ง-์ด๋ฏธ์ง ์์ฑ์ ์ํ ํตํฉ Pipeline
์ด ๋ชจ๋ธ์ DiffusionPipeline์์ ์์๋ฉ๋๋ค. ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ๋ชจ๋ ํ์ดํ๋ผ์ธ์ ๋ํด ๊ตฌํํ๋ ์ผ๋ฐ์ ๋ฉ์๋(๋ค์ด๋ก๋ ๋๋ ์ ์ฅ, ํน์ ๋๋ฐ์ด์ค์์ ์คํ ๋ฑ)์ ๋ํด์๋ ์์ ํด๋์ค ๋ฌธ์๋ฅผ ํ์ธํ์ธ์.
ํธ์ถ[[diffusers.KandinskyV22Img2ImgCombinedPipeline.call]]
__call__(prompt: str | list[str], image: typing.Union[torch.Tensor, list[torch.Tensor], PIL.Image.Image, list[PIL.Image.Image]], negative_prompt: str | list[str] | None = None, num_inference_steps: int = 100, guidance_scale: float = 4.0, strength: float = 0.3, num_images_per_prompt: int = 1, height: int = 512, width: int = 512, prior_guidance_scale: float = 4.0, prior_num_inference_steps: int = 25, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', callback: typing.Optional[typing.Callable[[int, int, torch.Tensor], NoneType]] = None, callback_steps: int = 1, return_dict: bool = True, prior_callback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = None, prior_callback_on_step_end_tensor_inputs: list[str] = ['latents'], callback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'])
๋งค๊ฐ๋ณ์:
prompt (str ๋๋ list[str]) : ์ด๋ฏธ์ง ์์ฑ์ ์๋ดํ๋ ํ๋กฌํํธ ๋๋ ํ๋กฌํํธ ๋ชฉ๋ก์
๋๋ค.
image (torch.Tensor, PIL.Image.Image, np.ndarray, list[torch.Tensor], list[PIL.Image.Image], ๋๋ list[np.ndarray]) : Image ๋๋ ์ด๋ฏธ์ง ๋ฐฐ์น ํ
์๋ก, ํ๋ก์ธ์ค์ ์์์ ์ผ๋ก ์ฌ์ฉ๋ฉ๋๋ค. image๋ก ์ด๋ฏธ์ง ๋ ์ดํดํธ๋ฅผ ์ง์ ์ ๋ฌํ๋ ๊ฒฝ์ฐ์๋ ์ด๋ฅผ ๋ฐ์๋ค์ด๋ฉฐ, ์ด ๊ฒฝ์ฐ ๋ค์ ์ธ์ฝ๋ฉํ์ง ์์ต๋๋ค.
negative_prompt (str ๋๋ list[str], ์ ํ ์ฌํญ) : ์ด๋ฏธ์ง ์์ฑ์ ์๋ดํ์ง ์์ ํ๋กฌํํธ์
๋๋ค. ๊ฐ์ด๋์ค๋ฅผ ์ฌ์ฉํ์ง ์๋ ๊ฒฝ์ฐ ๋ฌด์๋ฉ๋๋ค(์ฆ, guidance_scale์ด 1๋ณด๋ค ์์ ๊ฒฝ์ฐ ๋ฌด์๋ฉ๋๋ค).
num_images_per_prompt (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 1) : ํ๋กฌํํธ๋น ์์ฑํ ์ด๋ฏธ์ง์ ์.
guidance_scale (float, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 4.0) : Classifier-Free Diffusion Guidance์์ ์ ์ํ ๊ฐ์ด๋์ค ์ค์ผ์ผ์
๋๋ค. guidance_scale์ Imagen Paper์ 2๋ฒ ์์ w๋ก ์ ์๋ฉ๋๋ค. guidance_scale > 1๋ก ์ค์ ํ๋ฉด ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ํ์ฑํ๋ฉ๋๋ค. ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ๋์์๋ก prompt ํ
์คํธ์ ๋ฐ์ ํ๊ฒ ์ฐ๊ฒฐ๋ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋๋ก ์ฅ๋ คํ์ง๋ง, ์ผ๋ฐ์ ์ผ๋ก ์ด๋ฏธ์ง ํ์ง์ด ๋ฎ์์ง๋ ๋๊ฐ๋ฅผ ์น๋ฆ
๋๋ค.
strength (float, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 0.3) : ๊ฐ๋
์ ์ผ๋ก ์ฐธ์กฐ image๋ฅผ ์ผ๋ง๋ ๋ณํํ ์ง๋ฅผ ๋ํ๋
๋๋ค. 0๊ณผ 1 ์ฌ์ด์ฌ์ผ ํฉ๋๋ค. image๋ ์์์ ์ผ๋ก ์ฌ์ฉ๋๋ฉฐ, strength ๊ฐ์ด ํด์๋ก ๋ ๋ง์ ๋
ธ์ด์ฆ๊ฐ ์ถ๊ฐ๋ฉ๋๋ค. ๋๋
ธ์ด์ง ๋จ๊ณ์ ์๋ ์ด๊ธฐ์ ์ถ๊ฐ๋ ๋
ธ์ด์ฆ์ ์์ ๋ฐ๋ผ ๊ฒฐ์ ๋ฉ๋๋ค. strength๊ฐ 1์ด๋ฉด ์ถ๊ฐ๋๋ ๋
ธ์ด์ฆ๊ฐ ์ต๋๊ฐ ๋๊ณ , num_inference_steps์ ์ง์ ๋ ์ ์ฒด ๋ฐ๋ณต ํ์๋งํผ ๋๋
ธ์ด์ง ํ๋ก์ธ์ค๊ฐ ์คํ๋ฉ๋๋ค. ๋ฐ๋ผ์ 1์ด๋ผ๋ ๊ฐ์ ์ฌ์ค์ image๋ฅผ ๋ฌด์ํ๋ ๊ฒ๊ณผ ๊ฐ์ต๋๋ค.
num_inference_steps (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 100) : ๋๋
ธ์ด์ง ๋จ๊ณ์ ์์
๋๋ค. ๋๋
ธ์ด์ง ๋จ๊ณ๊ฐ ๋ง์์๋ก ์ผ๋ฐ์ ์ผ๋ก ์ถ๋ก ์๋๊ฐ ๋๋ ค์ง๋ ๋์ ๋ ๋์ ํ์ง์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํฉ๋๋ค.
height (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 512) : ์์ฑ๋ ์ด๋ฏธ์ง์ ํฝ์
๋จ์ ๋์ด์
๋๋ค.
width (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 512) : ์์ฑ๋ ์ด๋ฏธ์ง์ ํฝ์
๋จ์ ๋๋น์
๋๋ค.
prior_guidance_scale (float, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 4.0) : Classifier-Free Diffusion Guidance์์ ์ ์ํ ๊ฐ์ด๋์ค ์ค์ผ์ผ์
๋๋ค. guidance_scale์ Imagen Paper์ 2๋ฒ ์์ w๋ก ์ ์๋ฉ๋๋ค. guidance_scale > 1๋ก ์ค์ ํ๋ฉด ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ํ์ฑํ๋ฉ๋๋ค. ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ๋์์๋ก prompt ํ
์คํธ์ ๋ฐ์ ํ๊ฒ ์ฐ๊ฒฐ๋ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋๋ก ์ฅ๋ คํ์ง๋ง, ์ผ๋ฐ์ ์ผ๋ก ์ด๋ฏธ์ง ํ์ง์ด ๋ฎ์์ง๋ ๋๊ฐ๋ฅผ ์น๋ฆ
๋๋ค.
prior_num_inference_steps (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 100) : ๋๋
ธ์ด์ง ๋จ๊ณ์ ์์
๋๋ค. ๋๋
ธ์ด์ง ๋จ๊ณ๊ฐ ๋ง์์๋ก ์ผ๋ฐ์ ์ผ๋ก ์ถ๋ก ์๋๊ฐ ๋๋ ค์ง๋ ๋์ ๋ ๋์ ํ์ง์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํฉ๋๋ค.
generator (torch.Generator ๋๋ list[torch.Generator], ์ ํ ์ฌํญ) : ์์ฑ์ ๊ฒฐ์ ์ ์ผ๋ก ๋ง๋ค๊ธฐ ์ํ torch generator ํ๋ ๋๋ ๋ชฉ๋ก.
latents (torch.Tensor, ์ ํ ์ฌํญ) : ์ด๋ฏธ์ง ์์ฑ์ ์
๋ ฅ์ผ๋ก ์ฌ์ฉํ ๊ฐ์ฐ์์ ๋ถํฌ์์ ์ํ๋ง๋ ์ฌ์ ์์ฑ๋ ๋
ธ์ด์ฆ๋ latents์
๋๋ค. ๋์ผํ ์์ฑ์ ๋ค๋ฅธ ํ๋กฌํํธ๋ก ์กฐ์ ํ๋ ๋ฐ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์ ๊ณต๋์ง ์์ผ๋ฉด, ์ ๊ณต๋ ๋๋ค generator๋ฅผ ์ฌ์ฉํ์ฌ ์ํ๋งํ์ฌ latents ํ
์๊ฐ ์์ฑ๋ฉ๋๋ค.
output_type (str, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ "pil") : ์ด๋ฏธ์ง ์์ฑ์ ์ถ๋ ฅ ํ์์
๋๋ค. ๋ค์ ์ค ํ๋๋ฅผ ์ ํํฉ๋๋ค: "pil" (PIL.Image.Image), "np" (np.array) ๋๋ "pt" (torch.Tensor).
callback (Callable, ์ ํ ์ฌํญ) : ์ถ๋ก ์ค callback_steps ๋จ๊ณ๋ง๋ค ํธ์ถ๋๋ ํจ์์
๋๋ค. ์ด ํจ์๋ ๋ค์ ์ธ์๋ฅผ ๋ฐ์ ํธ์ถ๋ฉ๋๋ค: callback(step: int, timestep: int, latents: torch.Tensor).
callback_steps (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 1) : callback ํจ์๊ฐ ํธ์ถ๋๋ ์ฃผ๊ธฐ์
๋๋ค. ์ง์ ํ์ง ์์ผ๋ฉด ๋ชจ๋ ๋จ๊ณ์์ ์ฝ๋ฐฑ์ด ํธ์ถ๋ฉ๋๋ค.
return_dict (bool, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ True) : ์ผ๋ฐ ํํ ๋์ ImagePipelineOutput์ ๋ฐํํ ์ง ์ฌ๋ถ.
prior_callback_on_step_end (Callable, ์ ํ ์ฌํญ) : prior ํ์ดํ๋ผ์ธ ์ถ๋ก ์ค ๊ฐ denoising ๋จ๊ณ์ ๋์์ ํธ์ถ๋๋ ํจ์์
๋๋ค. ์ด ํจ์๋ ๋ค์ ์ธ์๋ฅผ ๋ฐ์ ํธ์ถ๋ฉ๋๋ค: prior_callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict).
prior_callback_on_step_end_tensor_inputs (list, ์ ํ ์ฌํญ) : prior_callback_on_step_end ํจ์์ ํ
์ ์
๋ ฅ ๋ชฉ๋ก์
๋๋ค. ๋ชฉ๋ก์ ์ง์ ๋ ํ
์๋ callback_kwargs ์ธ์๋ก ์ ๋ฌ๋ฉ๋๋ค. prior ํ์ดํ๋ผ์ธ ํด๋์ค์ ._callback_tensor_inputs ์์ฑ์ ๋์ด๋ ๋ณ์๋ง ํฌํจํ ์ ์์ต๋๋ค.
callback_on_step_end (Callable, ์ ํ ์ฌํญ) : ๋์ฝ๋ ํ์ดํ๋ผ์ธ ์ถ๋ก ์ค ๊ฐ ๋๋
ธ์ด์ง ๋จ๊ณ์ ๋์์ ํธ์ถ๋๋ ํจ์์
๋๋ค. ์ด ํจ์๋ ๋ค์ ์ธ์๋ฅผ ๋ฐ์ ํธ์ถ๋ฉ๋๋ค: callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict). callback_kwargs์๋ callback_on_step_end_tensor_inputs๋ก ์ง์ ๋ ๋ชจ๋ ํ
์ ๋ชฉ๋ก์ด ํฌํจ๋ฉ๋๋ค.
callback_on_step_end_tensor_inputs (list, ์ ํ ์ฌํญ) : callback_on_step_end ํจ์์ ํ
์ ์
๋ ฅ ๋ชฉ๋ก์
๋๋ค. ๋ชฉ๋ก์ ์ง์ ๋ ํ
์๋ callback_kwargs ์ธ์๋ก ์ ๋ฌ๋ฉ๋๋ค. ํ์ดํ๋ผ์ธ ํด๋์ค์ ._callback_tensor_inputs ์์ฑ์ ๋์ด๋ ๋ณ์๋ง ํฌํจํ ์ ์์ต๋๋ค.
๋ฐํ๊ฐ: ImagePipelineOutput ๋๋ tuple
์์ฑ์ ์ํด ํ์ดํ๋ผ์ธ์ ํธ์ถํ ๋ ํธ์ถ๋๋ ํจ์.
์:
from diffusers import AutoPipelineForImage2Image
import torch
import requests
from io import BytesIO
from PIL import Image
import os
pipe = AutoPipelineForImage2Image.from_pretrained(
"kandinsky-community/kandinsky-2-2-decoder", torch_dtype=torch.float16
)
pipe.enable_model_cpu_offload()
prompt = "A fantasy landscape, Cinematic lighting"
negative_prompt = "low quality, bad quality"
url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
response = requests.get(url)
image = Image.open(BytesIO(response.content)).convert("RGB")
image.thumbnail((768, 768))
image = pipe(prompt=prompt, image=original_image, num_inference_steps=25).images[0]
enable_model_cpu_offload[[diffusers.KandinskyV22Img2ImgCombinedPipeline.enable_model_cpu_offload]]
enable_model_cpu_offload(gpu_id: int | None = None, device: typing.Union[torch.device, str] = None)
accelerate๋ฅผ ์ฌ์ฉํ์ฌ ๋ชจ๋ ๋ชจ๋ธ์ CPU๋ก ์คํ๋ก๋ํ์ฌ ์ฑ๋ฅ์ ๋ฏธ์น๋ ์ํฅ์ ์ ์ผ๋ฉด์ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋์ ์ค์
๋๋ค. enable_sequential_cpu_offload์ ๋น๊ตํ๋ฉด, ์ด ๋ฉ์๋๋ forward ๋ฉ์๋๊ฐ ํธ์ถ๋ ๋ ํ ๋ฒ์ ํ๋์ ๋ชจ๋ธ์ GPU๋ก ์ด๋ํ๋ฉฐ, ๋ค์ ๋ชจ๋ธ์ด ์คํ๋ ๋๊น์ง ํด๋น ๋ชจ๋ธ์ GPU์ ์ ์ง๋ฉ๋๋ค. enable_sequential_cpu_offload๋ฅผ ์ฌ์ฉํ ๋๋ณด๋ค ๋ฉ๋ชจ๋ฆฌ ์ ๊ฐ ํจ๊ณผ๋ ๋ฎ์ง๋ง, unet์ ๋ฐ๋ณต์ ์คํ ๋๋ถ์ ์ฑ๋ฅ์ด ํจ์ฌ ์ข์ต๋๋ค.
enable_sequential_cpu_offload[[diffusers.KandinskyV22Img2ImgCombinedPipeline.enable_sequential_cpu_offload]]
enable_sequential_cpu_offload(gpu_id: int | None = None, device: typing.Union[torch.device, str] = None)
Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet, text_encoder, vae and safety checker have their state dicts saved to CPU and then are moved to a torch.device('meta') and loaded to GPU only when their specific submodule has its forwardmethod called. Note that offloading happens on a submodule basis. Memory savings are higher than withenable_model_cpu_offload`, but performance is lower.
KandinskyV22ControlnetImg2ImgPipeline[[diffusers.KandinskyV22ControlnetImg2ImgPipeline]]
diffusers.KandinskyV22ControlnetImg2ImgPipeline[[diffusers.KandinskyV22ControlnetImg2ImgPipeline]]
diffusers.KandinskyV22ControlnetImg2ImgPipeline(unet: UNet2DConditionModel, scheduler: DDPMScheduler, movq: VQModel)
๋งค๊ฐ๋ณ์:
scheduler (DDIMScheduler) : unet์ ํจ๊ป ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง latents๋ฅผ ์์ฑํ๋ ์ค์ผ์ค๋ฌ์
๋๋ค.
unet (UNet2DConditionModel) : ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ ๋ ธ์ด์ฆ๋ฅผ ์ ๊ฑฐํ๊ธฐ ์ํ ์กฐ๊ฑด๋ถ U-Net ์ํคํ ์ฒ.
movq (VQModel) : latents์์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๊ธฐ ์ํ MoVQ Decoder์ ๋๋ค.
Kandinsky๋ฅผ ์ฌ์ฉํ ์ด๋ฏธ์ง-์ด๋ฏธ์ง ์์ฑ์ ์ํ Pipeline
์ด ๋ชจ๋ธ์ DiffusionPipeline์์ ์์๋ฉ๋๋ค. ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ๋ชจ๋ ํ์ดํ๋ผ์ธ์ ๋ํด ๊ตฌํํ๋ ์ผ๋ฐ์ ๋ฉ์๋(๋ค์ด๋ก๋ ๋๋ ์ ์ฅ, ํน์ ๋๋ฐ์ด์ค์์ ์คํ ๋ฑ)์ ๋ํด์๋ ์์ ํด๋์ค ๋ฌธ์๋ฅผ ํ์ธํ์ธ์.
ํธ์ถ[[diffusers.KandinskyV22ControlnetImg2ImgPipeline.call]]
__call__(image_embeds: typing.Union[torch.Tensor, list[torch.Tensor]], image: typing.Union[torch.Tensor, list[torch.Tensor], PIL.Image.Image, list[PIL.Image.Image]], negative_image_embeds: typing.Union[torch.Tensor, list[torch.Tensor]], hint: Tensor, height: int = 512, width: int = 512, num_inference_steps: int = 100, guidance_scale: float = 4.0, strength: float = 0.3, num_images_per_prompt: int = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, output_type: str | None = 'pil', callback: typing.Optional[typing.Callable[[int, int, torch.Tensor], NoneType]] = None, callback_steps: int = 1, return_dict: bool = True)
๋งค๊ฐ๋ณ์:
image_embeds (torch.Tensor ๋๋ list[torch.Tensor]) : ํ
์คํธ ํ๋กฌํํธ์ ๋ํ ํด๋ฆฝ ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ผ๋ก, ์ด๋ฏธ์ง ์์ฑ์ ์กฐ๊ฑดํํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.
image (torch.Tensor, PIL.Image.Image, np.ndarray, list[torch.Tensor], list[PIL.Image.Image], ๋๋ list[np.ndarray]) : Image ๋๋ ์ด๋ฏธ์ง ๋ฐฐ์น ํ
์๋ก, ํ๋ก์ธ์ค์ ์์์ ์ผ๋ก ์ฌ์ฉ๋ฉ๋๋ค. image๋ก ์ด๋ฏธ์ง ๋ ์ดํดํธ๋ฅผ ์ง์ ์ ๋ฌํ๋ ๊ฒฝ์ฐ์๋ ์ด๋ฅผ ๋ฐ์๋ค์ด๋ฉฐ, ์ด ๊ฒฝ์ฐ ๋ค์ ์ธ์ฝ๋ฉํ์ง ์์ต๋๋ค.
strength (float, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 0.8) : ๊ฐ๋
์ ์ผ๋ก ์ฐธ์กฐ image๋ฅผ ์ผ๋ง๋ ๋ณํํ ์ง๋ฅผ ๋ํ๋
๋๋ค. 0๊ณผ 1 ์ฌ์ด์ฌ์ผ ํฉ๋๋ค. image๋ ์์์ ์ผ๋ก ์ฌ์ฉ๋๋ฉฐ, strength ๊ฐ์ด ํด์๋ก ๋ ๋ง์ ๋
ธ์ด์ฆ๊ฐ ์ถ๊ฐ๋ฉ๋๋ค. ๋๋
ธ์ด์ง ๋จ๊ณ์ ์๋ ์ด๊ธฐ์ ์ถ๊ฐ๋ ๋
ธ์ด์ฆ์ ์์ ๋ฐ๋ผ ๊ฒฐ์ ๋ฉ๋๋ค. strength๊ฐ 1์ด๋ฉด ์ถ๊ฐ๋๋ ๋
ธ์ด์ฆ๊ฐ ์ต๋๊ฐ ๋๊ณ , num_inference_steps์ ์ง์ ๋ ์ ์ฒด ๋ฐ๋ณต ํ์๋งํผ ๋๋
ธ์ด์ง ํ๋ก์ธ์ค๊ฐ ์คํ๋ฉ๋๋ค. ๋ฐ๋ผ์ 1์ด๋ผ๋ ๊ฐ์ ์ฌ์ค์ image๋ฅผ ๋ฌด์ํ๋ ๊ฒ๊ณผ ๊ฐ์ต๋๋ค.
hint (torch.Tensor) : ControlNet ์กฐ๊ฑด.
negative_image_embeds (torch.Tensor ๋๋ list[torch.Tensor]) : ๋ถ์ ํ
์คํธ ํ๋กฌํํธ์ ๋ํ ํด๋ฆฝ ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ผ๋ก, ์ด๋ฏธ์ง ์์ฑ์ ์กฐ๊ฑดํํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.
height (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 512) : ์์ฑ๋ ์ด๋ฏธ์ง์ ํฝ์
๋จ์ ๋์ด์
๋๋ค.
width (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 512) : ์์ฑ๋ ์ด๋ฏธ์ง์ ํฝ์
๋จ์ ๋๋น์
๋๋ค.
num_inference_steps (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 100) : ๋๋
ธ์ด์ง ๋จ๊ณ์ ์์
๋๋ค. ๋๋
ธ์ด์ง ๋จ๊ณ๊ฐ ๋ง์์๋ก ์ผ๋ฐ์ ์ผ๋ก ์ถ๋ก ์๋๊ฐ ๋๋ ค์ง๋ ๋์ ๋ ๋์ ํ์ง์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํฉ๋๋ค.
guidance_scale (float, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 4.0) : Classifier-Free Diffusion Guidance์์ ์ ์ํ ๊ฐ์ด๋์ค ์ค์ผ์ผ์
๋๋ค. guidance_scale์ Imagen Paper์ 2๋ฒ ์์ w๋ก ์ ์๋ฉ๋๋ค. guidance_scale > 1๋ก ์ค์ ํ๋ฉด ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ํ์ฑํ๋ฉ๋๋ค. ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ๋์์๋ก prompt ํ
์คํธ์ ๋ฐ์ ํ๊ฒ ์ฐ๊ฒฐ๋ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋๋ก ์ฅ๋ คํ์ง๋ง, ์ผ๋ฐ์ ์ผ๋ก ์ด๋ฏธ์ง ํ์ง์ด ๋ฎ์์ง๋ ๋๊ฐ๋ฅผ ์น๋ฆ
๋๋ค.
num_images_per_prompt (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 1) : ํ๋กฌํํธ๋น ์์ฑํ ์ด๋ฏธ์ง์ ์.
generator (torch.Generator ๋๋ list[torch.Generator], ์ ํ ์ฌํญ) : ์์ฑ์ ๊ฒฐ์ ์ ์ผ๋ก ๋ง๋ค๊ธฐ ์ํ torch generator ํ๋ ๋๋ ๋ชฉ๋ก.
output_type (str, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ "pil") : ์ด๋ฏธ์ง ์์ฑ์ ์ถ๋ ฅ ํ์์
๋๋ค. ๋ค์ ์ค ํ๋๋ฅผ ์ ํํฉ๋๋ค: "pil" (PIL.Image.Image), "np" (np.array) ๋๋ "pt" (torch.Tensor).
callback (Callable, ์ ํ ์ฌํญ) : ์ถ๋ก ์ค callback_steps ๋จ๊ณ๋ง๋ค ํธ์ถ๋๋ ํจ์์
๋๋ค. ์ด ํจ์๋ ๋ค์ ์ธ์๋ฅผ ๋ฐ์ ํธ์ถ๋ฉ๋๋ค: callback(step: int, timestep: int, latents: torch.Tensor).
callback_steps (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 1) : callback ํจ์๊ฐ ํธ์ถ๋๋ ์ฃผ๊ธฐ์
๋๋ค. ์ง์ ํ์ง ์์ผ๋ฉด ๋ชจ๋ ๋จ๊ณ์์ ์ฝ๋ฐฑ์ด ํธ์ถ๋ฉ๋๋ค.
return_dict (bool, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ True) : ์ผ๋ฐ ํํ ๋์ ImagePipelineOutput์ ๋ฐํํ ์ง ์ฌ๋ถ.
๋ฐํ๊ฐ: ImagePipelineOutput ๋๋ tuple
์์ฑ์ ์ํด ํ์ดํ๋ผ์ธ์ ํธ์ถํ ๋ ํธ์ถ๋๋ ํจ์.
์:
KandinskyV22InpaintPipeline[[diffusers.KandinskyV22InpaintPipeline]]
diffusers.KandinskyV22InpaintPipeline[[diffusers.KandinskyV22InpaintPipeline]]
diffusers.KandinskyV22InpaintPipeline(unet: UNet2DConditionModel, scheduler: DDPMScheduler, movq: VQModel)
๋งค๊ฐ๋ณ์:
scheduler (DDIMScheduler) : unet์ ํจ๊ป ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง latents๋ฅผ ์์ฑํ๋ ์ค์ผ์ค๋ฌ์
๋๋ค.
unet (UNet2DConditionModel) : ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ ๋ ธ์ด์ฆ๋ฅผ ์ ๊ฑฐํ๊ธฐ ์ํ ์กฐ๊ฑด๋ถ U-Net ์ํคํ ์ฒ.
movq (VQModel) : latents์์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๊ธฐ ์ํ MoVQ Decoder์ ๋๋ค.
Kandinsky2.1์ ์ฌ์ฉํ ํ ์คํธ ๊ธฐ๋ฐ ์ด๋ฏธ์ง ์ธํ์ธํ ์ ์ํ Pipeline
์ด ๋ชจ๋ธ์ DiffusionPipeline์์ ์์๋ฉ๋๋ค. ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ๋ชจ๋ ํ์ดํ๋ผ์ธ์ ๋ํด ๊ตฌํํ๋ ์ผ๋ฐ์ ๋ฉ์๋(๋ค์ด๋ก๋ ๋๋ ์ ์ฅ, ํน์ ๋๋ฐ์ด์ค์์ ์คํ ๋ฑ)์ ๋ํด์๋ ์์ ํด๋์ค ๋ฌธ์๋ฅผ ํ์ธํ์ธ์.
ํธ์ถ[[diffusers.KandinskyV22InpaintPipeline.call]]
__call__(image_embeds: typing.Union[torch.Tensor, list[torch.Tensor]], image: typing.Union[torch.Tensor, PIL.Image.Image], mask_image: typing.Union[PIL.Image.Image, torch.Tensor, numpy.ndarray], negative_image_embeds: typing.Union[torch.Tensor, list[torch.Tensor]], height: int = 512, width: int = 512, num_inference_steps: int = 100, guidance_scale: float = 4.0, num_images_per_prompt: int = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, callback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], **kwargs)
๋งค๊ฐ๋ณ์:
image_embeds (torch.Tensor ๋๋ list[torch.Tensor]) : ํ
์คํธ ํ๋กฌํํธ์ ๋ํ ํด๋ฆฝ ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ผ๋ก, ์ด๋ฏธ์ง ์์ฑ์ ์กฐ๊ฑดํํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.
image (PIL.Image.Image) : Image ๋๋ inpaint ๋์์ธ ์ด๋ฏธ์ง ๋ฐฐ์น์ ํ
์, ์ฆ ์ด๋ฏธ์ง์ ์ผ๋ถ๊ฐ mask_image๋ก ๋ง์คํน๋๊ณ prompt์ ๋ฐ๋ผ ๋ค์ ์ฑ์์ง๋๋ค.
mask_image (np.array) : image๋ฅผ ๋ง์คํนํ ์ด๋ฏธ์ง ๋ฐฐ์น ํ
์. ๋ง์คํฌ์ ํฐ์ ํฝ์
์ ๋ค์ ์ฑ์์ง๊ณ , ๊ฒ์์ ํฝ์
์ ์ ์ง๋ฉ๋๋ค. mask_image๊ฐ PIL ์ด๋ฏธ์ง์ธ ๊ฒฝ์ฐ, ์ฌ์ฉ ์ ์ ๋จ์ผ ์ฑ๋(ํ๋)๋ก ๋ณํ๋ฉ๋๋ค. ํ
์์ธ ๊ฒฝ์ฐ 3๊ฐ ๋์ ํ๋์ ์์ ์ฑ๋(L)์ ํฌํจํด์ผ ํ๋ฏ๋ก, ์์๋๋ ๋ชจ์์ (B, H, W, 1)์
๋๋ค.
negative_image_embeds (torch.Tensor ๋๋ list[torch.Tensor]) : ๋ถ์ ํ
์คํธ ํ๋กฌํํธ์ ๋ํ ํด๋ฆฝ ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ผ๋ก, ์ด๋ฏธ์ง ์์ฑ์ ์กฐ๊ฑดํํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.
height (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 512) : ์์ฑ๋ ์ด๋ฏธ์ง์ ํฝ์
๋จ์ ๋์ด์
๋๋ค.
width (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 512) : ์์ฑ๋ ์ด๋ฏธ์ง์ ํฝ์
๋จ์ ๋๋น์
๋๋ค.
num_inference_steps (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 100) : ๋๋
ธ์ด์ง ๋จ๊ณ์ ์์
๋๋ค. ๋๋
ธ์ด์ง ๋จ๊ณ๊ฐ ๋ง์์๋ก ์ผ๋ฐ์ ์ผ๋ก ์ถ๋ก ์๋๊ฐ ๋๋ ค์ง๋ ๋์ ๋ ๋์ ํ์ง์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํฉ๋๋ค.
guidance_scale (float, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 4.0) : Classifier-Free Diffusion Guidance์์ ์ ์ํ ๊ฐ์ด๋์ค ์ค์ผ์ผ์
๋๋ค. guidance_scale์ Imagen Paper์ 2๋ฒ ์์ w๋ก ์ ์๋ฉ๋๋ค. guidance_scale > 1๋ก ์ค์ ํ๋ฉด ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ํ์ฑํ๋ฉ๋๋ค. ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ๋์์๋ก prompt ํ
์คํธ์ ๋ฐ์ ํ๊ฒ ์ฐ๊ฒฐ๋ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋๋ก ์ฅ๋ คํ์ง๋ง, ์ผ๋ฐ์ ์ผ๋ก ์ด๋ฏธ์ง ํ์ง์ด ๋ฎ์์ง๋ ๋๊ฐ๋ฅผ ์น๋ฆ
๋๋ค.
num_images_per_prompt (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 1) : ํ๋กฌํํธ๋น ์์ฑํ ์ด๋ฏธ์ง์ ์.
generator (torch.Generator ๋๋ list[torch.Generator], ์ ํ ์ฌํญ) : ์์ฑ์ ๊ฒฐ์ ์ ์ผ๋ก ๋ง๋ค๊ธฐ ์ํ torch generator ํ๋ ๋๋ ๋ชฉ๋ก.
latents (torch.Tensor, ์ ํ ์ฌํญ) : ์ด๋ฏธ์ง ์์ฑ์ ์
๋ ฅ์ผ๋ก ์ฌ์ฉํ ๊ฐ์ฐ์์ ๋ถํฌ์์ ์ํ๋ง๋ ์ฌ์ ์์ฑ๋ ๋
ธ์ด์ฆ๋ latents์
๋๋ค. ๋์ผํ ์์ฑ์ ๋ค๋ฅธ ํ๋กฌํํธ๋ก ์กฐ์ ํ๋ ๋ฐ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์ ๊ณต๋์ง ์์ผ๋ฉด, ์ ๊ณต๋ ๋๋ค generator๋ฅผ ์ฌ์ฉํ์ฌ ์ํ๋งํ์ฌ latents ํ
์๊ฐ ์์ฑ๋ฉ๋๋ค.
output_type (str, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ "pil") : ์ด๋ฏธ์ง ์์ฑ์ ์ถ๋ ฅ ํ์์
๋๋ค. ๋ค์ ์ค ํ๋๋ฅผ ์ ํํฉ๋๋ค: "pil" (PIL.Image.Image), "np" (np.array) ๋๋ "pt" (torch.Tensor).
return_dict (bool, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ True) : ์ผ๋ฐ ํํ ๋์ ImagePipelineOutput์ ๋ฐํํ ์ง ์ฌ๋ถ.
callback_on_step_end (Callable, ์ ํ ์ฌํญ) : ์ถ๋ก ์ค ๊ฐ ๋๋
ธ์ด์ง ๋จ๊ณ์ ๋์์ ํธ์ถ๋๋ ํจ์์
๋๋ค. ์ด ํจ์๋ ๋ค์ ์ธ์๋ฅผ ๋ฐ์ ํธ์ถ๋ฉ๋๋ค: callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict). callback_kwargs์๋ callback_on_step_end_tensor_inputs๋ก ์ง์ ๋ ๋ชจ๋ ํ
์ ๋ชฉ๋ก์ด ํฌํจ๋ฉ๋๋ค.
callback_on_step_end_tensor_inputs (list, ์ ํ ์ฌํญ) : callback_on_step_end ํจ์์ ํ
์ ์
๋ ฅ ๋ชฉ๋ก์
๋๋ค. ๋ชฉ๋ก์ ์ง์ ๋ ํ
์๋ callback_kwargs ์ธ์๋ก ์ ๋ฌ๋ฉ๋๋ค. ํ์ดํ๋ผ์ธ ํด๋์ค์ ._callback_tensor_inputs ์์ฑ์ ๋์ด๋ ๋ณ์๋ง ํฌํจํ ์ ์์ต๋๋ค.
๋ฐํ๊ฐ: ImagePipelineOutput ๋๋ tuple
์์ฑ์ ์ํด ํ์ดํ๋ผ์ธ์ ํธ์ถํ ๋ ํธ์ถ๋๋ ํจ์.
์:
KandinskyV22InpaintCombinedPipeline[[diffusers.KandinskyV22InpaintCombinedPipeline]]
diffusers.KandinskyV22InpaintCombinedPipeline[[diffusers.KandinskyV22InpaintCombinedPipeline]]
diffusers.KandinskyV22InpaintCombinedPipeline(unet: UNet2DConditionModel, scheduler: DDPMScheduler, movq: VQModel, prior_prior: PriorTransformer, prior_image_encoder: CLIPVisionModelWithProjection, prior_text_encoder: CLIPTextModelWithProjection, prior_tokenizer: CLIPTokenizer, prior_scheduler: UnCLIPScheduler, prior_image_processor: CLIPImageProcessorPil)
๋งค๊ฐ๋ณ์:
scheduler (DDIMScheduler | DDPMScheduler) : unet์ ํจ๊ป ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง latents๋ฅผ ์์ฑํ๋ ๋ฐ ์ฌ์ฉ๋๋ ์ค์ผ์ค๋ฌ.
unet (UNet2DConditionModel) : ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ ๋ ธ์ด์ฆ๋ฅผ ์ ๊ฑฐํ๊ธฐ ์ํ ์กฐ๊ฑด๋ถ U-Net ์ํคํ ์ฒ.
movq (VQModel) : latents์์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๊ธฐ ์ํ MoVQ Decoder์ ๋๋ค.
prior_prior (PriorTransformer) : ํ ์คํธ ์๋ฒ ๋ฉ์์ ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ ๊ทผ์ฌํ๊ธฐ ์ํ unCLIP์ ํ์ค ์ฌ์ ๋ถํฌ ๋ชจ๋ธ.
prior_image_encoder (CLIPVisionModelWithProjection) : ๊ณ ์ ๋ ์ด๋ฏธ์ง ์ธ์ฝ๋.
prior_text_encoder (CLIPTextModelWithProjection) : ๊ณ ์ ๋ ํ
์คํธ ์ธ์ฝ๋.
prior_tokenizer (CLIPTokenizer) : CLIPTokenizer ํด๋์ค์ ํ ํฌ๋์ด์ .
prior_scheduler (UnCLIPScheduler) : prior์ ํจ๊ป ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง ์๋ฒ ๋ฉ์ ์์ฑํ๋ ์ค์ผ์ค๋ฌ์
๋๋ค.
prior_image_processor (CLIPImageProcessor) : clip์์ ์ด๋ฏธ์ง๋ฅผ ์ ์ฒ๋ฆฌํ๋ ๋ฐ ์ฌ์ฉ๋๋ image_processor์
๋๋ค.
Kandinsky๋ฅผ ์ฌ์ฉํ ์ธํ์ธํ ์์ฑ์ ์ํ ํตํฉ ํ์ดํ๋ผ์ธ
์ด ๋ชจ๋ธ์ DiffusionPipeline์์ ์์๋ฉ๋๋ค. ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ๋ชจ๋ ํ์ดํ๋ผ์ธ์ ๋ํด ๊ตฌํํ๋ ์ผ๋ฐ์ ๋ฉ์๋(๋ค์ด๋ก๋ ๋๋ ์ ์ฅ, ํน์ ๋๋ฐ์ด์ค์์ ์คํ ๋ฑ)์ ๋ํด์๋ ์์ ํด๋์ค ๋ฌธ์๋ฅผ ํ์ธํ์ธ์.
ํธ์ถ[[diffusers.KandinskyV22InpaintCombinedPipeline.call]]
__call__(prompt: str | list[str], image: typing.Union[torch.Tensor, list[torch.Tensor], PIL.Image.Image, list[PIL.Image.Image]], mask_image: typing.Union[torch.Tensor, list[torch.Tensor], PIL.Image.Image, list[PIL.Image.Image]], negative_prompt: str | list[str] | None = None, num_inference_steps: int = 100, guidance_scale: float = 4.0, num_images_per_prompt: int = 1, height: int = 512, width: int = 512, prior_guidance_scale: float = 4.0, prior_num_inference_steps: int = 25, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, prior_callback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = None, prior_callback_on_step_end_tensor_inputs: list[str] = ['latents'], callback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], **kwargs)
๋งค๊ฐ๋ณ์:
prompt (str ๋๋ list[str]) : ์ด๋ฏธ์ง ์์ฑ์ ์๋ดํ๋ ํ๋กฌํํธ ๋๋ ํ๋กฌํํธ ๋ชฉ๋ก์
๋๋ค.
image (torch.Tensor, PIL.Image.Image, np.ndarray, list[torch.Tensor], list[PIL.Image.Image], ๋๋ list[np.ndarray]) : Image ๋๋ ์ด๋ฏธ์ง ๋ฐฐ์น ํ
์๋ก, ํ๋ก์ธ์ค์ ์์์ ์ผ๋ก ์ฌ์ฉ๋ฉ๋๋ค. image๋ก ์ด๋ฏธ์ง ๋ ์ดํดํธ๋ฅผ ์ง์ ์ ๋ฌํ๋ ๊ฒฝ์ฐ์๋ ์ด๋ฅผ ๋ฐ์๋ค์ด๋ฉฐ, ์ด ๊ฒฝ์ฐ ๋ค์ ์ธ์ฝ๋ฉํ์ง ์์ต๋๋ค.
mask_image (np.array) : image๋ฅผ ๋ง์คํนํ ์ด๋ฏธ์ง ๋ฐฐ์น ํ
์. ๋ง์คํฌ์ ํฐ์ ํฝ์
์ ๋ค์ ์ฑ์์ง๊ณ , ๊ฒ์์ ํฝ์
์ ์ ์ง๋ฉ๋๋ค. mask_image๊ฐ PIL ์ด๋ฏธ์ง์ธ ๊ฒฝ์ฐ, ์ฌ์ฉ ์ ์ ๋จ์ผ ์ฑ๋(ํ๋)๋ก ๋ณํ๋ฉ๋๋ค. ํ
์์ธ ๊ฒฝ์ฐ 3๊ฐ ๋์ ํ๋์ ์์ ์ฑ๋(L)์ ํฌํจํด์ผ ํ๋ฏ๋ก, ์์๋๋ ๋ชจ์์ (B, H, W, 1)์
๋๋ค.
negative_prompt (str ๋๋ list[str], ์ ํ ์ฌํญ) : ์ด๋ฏธ์ง ์์ฑ์ ์๋ดํ์ง ์์ ํ๋กฌํํธ์
๋๋ค. ๊ฐ์ด๋์ค๋ฅผ ์ฌ์ฉํ์ง ์๋ ๊ฒฝ์ฐ ๋ฌด์๋ฉ๋๋ค(์ฆ, guidance_scale์ด 1๋ณด๋ค ์์ ๊ฒฝ์ฐ ๋ฌด์๋ฉ๋๋ค).
num_images_per_prompt (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 1) : ํ๋กฌํํธ๋น ์์ฑํ ์ด๋ฏธ์ง์ ์.
guidance_scale (float, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 4.0) : Classifier-Free Diffusion Guidance์์ ์ ์ํ ๊ฐ์ด๋์ค ์ค์ผ์ผ์
๋๋ค. guidance_scale์ Imagen Paper์ 2๋ฒ ์์ w๋ก ์ ์๋ฉ๋๋ค. guidance_scale > 1๋ก ์ค์ ํ๋ฉด ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ํ์ฑํ๋ฉ๋๋ค. ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ๋์์๋ก prompt ํ
์คํธ์ ๋ฐ์ ํ๊ฒ ์ฐ๊ฒฐ๋ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋๋ก ์ฅ๋ คํ์ง๋ง, ์ผ๋ฐ์ ์ผ๋ก ์ด๋ฏธ์ง ํ์ง์ด ๋ฎ์์ง๋ ๋๊ฐ๋ฅผ ์น๋ฆ
๋๋ค.
num_inference_steps (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 100) : ๋๋
ธ์ด์ง ๋จ๊ณ์ ์์
๋๋ค. ๋๋
ธ์ด์ง ๋จ๊ณ๊ฐ ๋ง์์๋ก ์ผ๋ฐ์ ์ผ๋ก ์ถ๋ก ์๋๊ฐ ๋๋ ค์ง๋ ๋์ ๋ ๋์ ํ์ง์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํฉ๋๋ค.
height (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 512) : ์์ฑ๋ ์ด๋ฏธ์ง์ ํฝ์
๋จ์ ๋์ด์
๋๋ค.
width (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 512) : ์์ฑ๋ ์ด๋ฏธ์ง์ ํฝ์
๋จ์ ๋๋น์
๋๋ค.
prior_guidance_scale (float, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 4.0) : Classifier-Free Diffusion Guidance์์ ์ ์ํ ๊ฐ์ด๋์ค ์ค์ผ์ผ์
๋๋ค. guidance_scale์ Imagen Paper์ 2๋ฒ ์์ w๋ก ์ ์๋ฉ๋๋ค. guidance_scale > 1๋ก ์ค์ ํ๋ฉด ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ํ์ฑํ๋ฉ๋๋ค. ๊ฐ์ด๋์ค ์ค์ผ์ผ์ด ๋์์๋ก prompt ํ
์คํธ์ ๋ฐ์ ํ๊ฒ ์ฐ๊ฒฐ๋ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋๋ก ์ฅ๋ คํ์ง๋ง, ์ผ๋ฐ์ ์ผ๋ก ์ด๋ฏธ์ง ํ์ง์ด ๋ฎ์์ง๋ ๋๊ฐ๋ฅผ ์น๋ฆ
๋๋ค.
prior_num_inference_steps (int, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ 100) : ๋๋
ธ์ด์ง ๋จ๊ณ์ ์์
๋๋ค. ๋๋
ธ์ด์ง ๋จ๊ณ๊ฐ ๋ง์์๋ก ์ผ๋ฐ์ ์ผ๋ก ์ถ๋ก ์๋๊ฐ ๋๋ ค์ง๋ ๋์ ๋ ๋์ ํ์ง์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํฉ๋๋ค.
generator (torch.Generator ๋๋ list[torch.Generator], ์ ํ ์ฌํญ) : ์์ฑ์ ๊ฒฐ์ ์ ์ผ๋ก ๋ง๋ค๊ธฐ ์ํ torch generator ํ๋ ๋๋ ๋ชฉ๋ก.
latents (torch.Tensor, ์ ํ ์ฌํญ) : ์ด๋ฏธ์ง ์์ฑ์ ์
๋ ฅ์ผ๋ก ์ฌ์ฉํ ๊ฐ์ฐ์์ ๋ถํฌ์์ ์ํ๋ง๋ ์ฌ์ ์์ฑ๋ ๋
ธ์ด์ฆ๋ latents์
๋๋ค. ๋์ผํ ์์ฑ์ ๋ค๋ฅธ ํ๋กฌํํธ๋ก ์กฐ์ ํ๋ ๋ฐ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์ ๊ณต๋์ง ์์ผ๋ฉด, ์ ๊ณต๋ ๋๋ค generator๋ฅผ ์ฌ์ฉํ์ฌ ์ํ๋งํ์ฌ latents ํ
์๊ฐ ์์ฑ๋ฉ๋๋ค.
output_type (str, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ "pil") : ์ด๋ฏธ์ง ์์ฑ์ ์ถ๋ ฅ ํ์์
๋๋ค. ๋ค์ ์ค ํ๋๋ฅผ ์ ํํฉ๋๋ค: "pil" (PIL.Image.Image), "np" (np.array) ๋๋ "pt" (torch.Tensor).
return_dict (bool, ์ ํ ์ฌํญ, ๊ธฐ๋ณธ๊ฐ True) : ์ผ๋ฐ ํํ ๋์ ImagePipelineOutput์ ๋ฐํํ ์ง ์ฌ๋ถ.
prior_callback_on_step_end (Callable, ์ ํ ์ฌํญ) : ์ถ๋ก ์ค ๊ฐ ๋๋
ธ์ด์ง ๋จ๊ณ์ ๋์์ ํธ์ถ๋๋ ํจ์์
๋๋ค. ์ด ํจ์๋ ๋ค์ ์ธ์๋ฅผ ๋ฐ์ ํธ์ถ๋ฉ๋๋ค: prior_callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict).
prior_callback_on_step_end_tensor_inputs (list, ์ ํ ์ฌํญ) : prior_callback_on_step_end ํจ์์ ํ
์ ์
๋ ฅ ๋ชฉ๋ก์
๋๋ค. ๋ชฉ๋ก์ ์ง์ ๋ ํ
์๋ callback_kwargs ์ธ์๋ก ์ ๋ฌ๋ฉ๋๋ค. ํ์ดํ๋ผ์ธ ํด๋์ค์ ._callback_tensor_inputs ์์ฑ์ ๋์ด๋ ๋ณ์๋ง ํฌํจํ ์ ์์ต๋๋ค.
callback_on_step_end (Callable, ์ ํ ์ฌํญ) : ์ถ๋ก ์ค ๊ฐ ๋๋
ธ์ด์ง ๋จ๊ณ์ ๋์์ ํธ์ถ๋๋ ํจ์์
๋๋ค. ์ด ํจ์๋ ๋ค์ ์ธ์๋ฅผ ๋ฐ์ ํธ์ถ๋ฉ๋๋ค: callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict). callback_kwargs์๋ callback_on_step_end_tensor_inputs๋ก ์ง์ ๋ ๋ชจ๋ ํ
์ ๋ชฉ๋ก์ด ํฌํจ๋ฉ๋๋ค.
callback_on_step_end_tensor_inputs (list, ์ ํ ์ฌํญ) : callback_on_step_end ํจ์์ ํ
์ ์
๋ ฅ ๋ชฉ๋ก์
๋๋ค. ๋ชฉ๋ก์ ์ง์ ๋ ํ
์๋ callback_kwargs ์ธ์๋ก ์ ๋ฌ๋ฉ๋๋ค. ํ์ดํ๋ผ์ธ ํด๋์ค์ ._callback_tensor_inputs ์์ฑ์ ๋์ด๋ ๋ณ์๋ง ํฌํจํ ์ ์์ต๋๋ค.
๋ฐํ๊ฐ: ImagePipelineOutput ๋๋ tuple
์์ฑ์ ์ํด ํ์ดํ๋ผ์ธ์ ํธ์ถํ ๋ ํธ์ถ๋๋ ํจ์.
์:
from diffusers import AutoPipelineForInpainting
from diffusers.utils import load_image
import torch
import numpy as np
pipe = AutoPipelineForInpainting.from_pretrained(
"kandinsky-community/kandinsky-2-2-decoder-inpaint", torch_dtype=torch.float16
)
pipe.enable_model_cpu_offload()
prompt = "A fantasy landscape, Cinematic lighting"
negative_prompt = "low quality, bad quality"
original_image = load_image(
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/kandinsky/cat.png"
)
mask = np.zeros((768, 768), dtype=np.float32)
# Let's mask out an area above the cat's head
mask[:250, 250:-250] = 1
image = pipe(prompt=prompt, image=original_image, mask_image=mask, num_inference_steps=25).images[0]
enable_sequential_cpu_offload[[diffusers.KandinskyV22InpaintCombinedPipeline.enable_sequential_cpu_offload]]
enable_sequential_cpu_offload(gpu_id: int | None = None, device: typing.Union[torch.device, str] = None)
Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet, text_encoder, vae and safety checker have their state dicts saved to CPU and then are moved to a torch.device('meta') and loaded to GPU only when their specific submodule has its forwardmethod called. Note that offloading happens on a submodule basis. Memory savings are higher than withenable_model_cpu_offload`, but performance is lower.
Xet Storage Details
- Size:
- 87.5 kB
- Xet hash:
- 5d49904a2c541faa2056dbcb87de669d6c816c736e606386de796b81c2b7171e
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.