Buckets:

hf-doc-build/doc / diffusers /main /ko /api /pipelines /kandinsky_v22.md
mishig's picture
|
download
raw
87.5 kB
# Kandinsky 2.2 Kandinsky 2.2는 [Arseniy Shakhmatov](https://github.com/cene555), [Anton Razzhigaev](https://github.com/razzant), [Aleksandr Nikolich](https://github.com/AlexWortega), [Vladimir Arkhipkin](https://github.com/oriBetelgeuse), [Igor Pavlov](https://github.com/boomb0om), [Andrey Kuznetsov](https://github.com/kuznetsoffandrey), [Denis Dimitrov](https://github.com/denndimitrov)에 의해 개발되었습니다. GitHub 페이지의 설명은 다음과 같습니다: *Kandinsky 2.2는 이전 버전인 Kandinsky 2.1에 비해 새로운 이미지 인코더인 CLIP-ViT-G와 ControlNet 지원을 도입함으로써 상당한 성능 향상을 가져왔습니다. 이미지 인코더를 CLIP-ViT-G로 전환한 것은 모델이 더 미학적인 이미지를 생성하고 텍스트를 더 잘 이해하는 능력을 크게 향상시켜 모델의 전반적인 성능을 높였습니다. ControlNet 메커니즘의 추가는 모델이 이미지 생성 과정을 효과적으로 제어할 수 있게 합니다. 이를 통해 더 정확하고 시각적으로 매력적인 출력이 가능해지며, 텍스트 기반 이미지 조작에 대한 새로운 가능성을 열어줍니다.* 원본 코드베이스는 [ai-forever/Kandinsky-2](https://github.com/ai-forever/Kandinsky-2)에서 찾을 수 있습니다. > [!TIP] > Hub의 [Kandinsky Community](https://huggingface.co/kandinsky-community) 조직에서 텍스트-이미지, 이미지-이미지, 인페인팅과 같은 작업에 대한 공식 모델 체크포인트를 확인해 보세요. > [!TIP] > 스케줄러의 [가이드](../../using-diffusers/schedulers)를 확인하여 스케줄러의 속도와 품질 사이의 트레이드오프를 탐색하는 방법을 배우고, [파이프라인 간 구성 요소 재사용](../../using-diffusers/loading#reusing-models-in-multiple-pipelines) 섹션을 확인하여 동일한 구성 요소를 여러 파이프라인에 효율적으로 로드하는 방법을 배워보세요. ## KandinskyV22PriorPipeline[[diffusers.KandinskyV22PriorPipeline]] #### diffusers.KandinskyV22PriorPipeline[[diffusers.KandinskyV22PriorPipeline]] ```python diffusers.KandinskyV22PriorPipeline(prior: PriorTransformer, image_encoder: CLIPVisionModelWithProjection, text_encoder: CLIPTextModelWithProjection, tokenizer: CLIPTokenizer, scheduler: UnCLIPScheduler, image_processor: CLIPImageProcessorPil) ``` [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior.py#L88) **매개변수:** prior ([PriorTransformer](/docs/diffusers/main/ko/api/models/prior_transformer#diffusers.PriorTransformer)) : 텍스트 임베딩에서 이미지 임베딩을 근사하기 위한 unCLIP의 표준 사전 분포 모델. image_encoder (`CLIPVisionModelWithProjection`) : 고정된 이미지 인코더. text_encoder (`CLIPTextModelWithProjection`) : 고정된 텍스트 인코더. tokenizer (`CLIPTokenizer`) : [CLIPTokenizer](https://huggingface.co/docs/transformers/v4.21.0/en/model_doc/clip#transformers.CLIPTokenizer) 클래스의 토크나이저. scheduler (`UnCLIPScheduler`) : `prior`와 함께 사용하여 이미지 임베딩을 생성하는 스케줄러입니다. image_processor (`CLIPImageProcessor`) : clip에서 이미지를 전처리하는 데 사용되는 image_processor입니다. Kandinsky의 이미지 prior를 생성하는 Pipeline 이 모델은 [DiffusionPipeline](/docs/diffusers/main/ko/api/pipelines/overview#diffusers.DiffusionPipeline)에서 상속됩니다. 라이브러리가 모든 파이프라인에 대해 구현하는 일반적 메서드(다운로드 또는 저장, 특정 디바이스에서 실행 등)에 대해서는 상위 클래스 문서를 확인하세요. #### __호출__[[diffusers.KandinskyV22PriorPipeline.__call__]] ```python __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']) ``` [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior.py#L374) **매개변수:** 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](https://pytorch.org/docs/stable/generated/torch.Generator.html) 하나 또는 목록. latents (`torch.Tensor`, *선택 사항*) : 이미지 생성의 입력으로 사용할 가우시안 분포에서 샘플링된 사전 생성된 노이즈된 latents입니다. 동일한 생성을 다른 프롬프트로 조정하는 데 사용할 수 있습니다. 제공되지 않으면, 제공된 랜덤 `generator`를 사용하여 샘플링하여 latents 텐서가 생성됩니다. guidance_scale (`float`, *선택 사항*, 기본값 4.0) : [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598)에서 정의한 가이던스 스케일입니다. `guidance_scale`은 [Imagen Paper](https://huggingface.co/papers/2205.11487)의 2번 식의 `w`로 정의됩니다. `guidance_scale > 1`로 설정하면 가이던스 스케일이 활성화됩니다. 가이던스 스케일이 높을수록 `prompt` 텍스트와 밀접하게 연결된 이미지를 생성하도록 장려하지만, 일반적으로 이미지 품질이 낮아지는 대가를 치릅니다. output_type (`str`, *선택 사항*, 기본값 `"pt"`) : 이미지 생성의 출력 형식입니다. 다음 중 하나를 선택합니다: `"np"` (`np.array`) 또는 `"pt"` (`torch.Tensor`). return_dict (`bool`, *선택 사항*, 기본값 `True`) : 일반 튜플 대신 [ImagePipelineOutput](/docs/diffusers/main/ko/api/pipelines/stable_unclip#diffusers.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` 생성을 위해 파이프라인을 호출할 때 호출되는 함수. 예: ```py >>> 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]] ```python 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) ``` [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior.py#L135) **매개변수:** 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](https://pytorch.org/docs/stable/generated/torch.Generator.html) 하나 또는 목록. 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](https://huggingface.co/papers/2207.12598)에서 정의한 가이던스 스케일입니다. `guidance_scale`은 [Imagen Paper](https://huggingface.co/papers/2205.11487)의 2번 식의 `w`로 정의됩니다. `guidance_scale > 1`로 설정하면 가이던스 스케일이 활성화됩니다. 가이던스 스케일이 높을수록 `prompt` 텍스트와 밀접하게 연결된 이미지를 생성하도록 장려하지만, 일반적으로 이미지 품질이 낮아지는 대가를 치릅니다. **반환값:** `KandinskyPriorPipelineOutput` 또는 `tuple` interpolation에 pipeline을 사용할 때 호출되는 함수입니다. 예: ```py >>> 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]] ```python diffusers.KandinskyV22Pipeline(unet: UNet2DConditionModel, scheduler: DDPMScheduler, movq: VQModel) ``` [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2.py#L72) **매개변수:** scheduler (`DDIMScheduler` | `DDPMScheduler`) : `unet`와 함께 사용하여 이미지 latents를 생성하는 데 사용되는 스케줄러. unet ([UNet2DConditionModel](/docs/diffusers/main/ko/api/models/unet2d-cond#diffusers.UNet2DConditionModel)) : 이미지 임베딩의 노이즈를 제거하기 위한 조건부 U-Net 아키텍처. movq ([VQModel](/docs/diffusers/main/ko/api/models/vq#diffusers.VQModel)) : latents에서 이미지를 생성하기 위한 MoVQ Decoder입니다. Kandinsky를 사용한 텍스트-이미지 생성을 위한 Pipeline 이 모델은 [DiffusionPipeline](/docs/diffusers/main/ko/api/pipelines/overview#diffusers.DiffusionPipeline)에서 상속됩니다. 라이브러리가 모든 파이프라인에 대해 구현하는 일반적 메서드(다운로드 또는 저장, 특정 디바이스에서 실행 등)에 대해서는 상위 클래스 문서를 확인하세요. #### __호출__[[diffusers.KandinskyV22Pipeline.__call__]] ```python __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) ``` [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2.py#L130) **매개변수:** 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](https://huggingface.co/papers/2207.12598)에서 정의한 가이던스 스케일입니다. `guidance_scale`은 [Imagen Paper](https://huggingface.co/papers/2205.11487)의 2번 식의 `w`로 정의됩니다. `guidance_scale > 1`로 설정하면 가이던스 스케일이 활성화됩니다. 가이던스 스케일이 높을수록 `prompt` 텍스트와 밀접하게 연결된 이미지를 생성하도록 장려하지만, 일반적으로 이미지 품질이 낮아지는 대가를 치릅니다. num_images_per_prompt (`int`, *선택 사항*, 기본값 1) : 프롬프트당 생성할 이미지의 수. generator (`torch.Generator` 또는 `list[torch.Generator]`, *선택 사항*) : 생성을 결정적으로 만들기 위한 [torch generator](https://pytorch.org/docs/stable/generated/torch.Generator.html) 하나 또는 목록. 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](/docs/diffusers/main/ko/api/pipelines/stable_unclip#diffusers.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](/docs/diffusers/main/ko/api/pipelines/stable_unclip#diffusers.ImagePipelineOutput) 또는 `tuple` 생성을 위해 파이프라인을 호출할 때 호출되는 함수. 예: ```py >>> 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]] ```python 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) ``` [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py#L107) **매개변수:** scheduler (`DDIMScheduler` | `DDPMScheduler`) : `unet`와 함께 사용하여 이미지 latents를 생성하는 데 사용되는 스케줄러. unet ([UNet2DConditionModel](/docs/diffusers/main/ko/api/models/unet2d-cond#diffusers.UNet2DConditionModel)) : 이미지 임베딩의 노이즈를 제거하기 위한 조건부 U-Net 아키텍처. movq ([VQModel](/docs/diffusers/main/ko/api/models/vq#diffusers.VQModel)) : latents에서 이미지를 생성하기 위한 MoVQ Decoder입니다. prior_prior ([PriorTransformer](/docs/diffusers/main/ko/api/models/prior_transformer#diffusers.PriorTransformer)) : 텍스트 임베딩에서 이미지 임베딩을 근사하기 위한 unCLIP의 표준 사전 분포 모델. prior_image_encoder (`CLIPVisionModelWithProjection`) : 고정된 이미지 인코더. prior_text_encoder (`CLIPTextModelWithProjection`) : 고정된 텍스트 인코더. prior_tokenizer (`CLIPTokenizer`) : [CLIPTokenizer](https://huggingface.co/docs/transformers/v4.21.0/en/model_doc/clip#transformers.CLIPTokenizer) 클래스의 토크나이저. prior_scheduler (`UnCLIPScheduler`) : `prior`와 함께 사용하여 이미지 임베딩을 생성하는 스케줄러입니다. prior_image_processor (`CLIPImageProcessor`) : clip에서 이미지를 전처리하는 데 사용되는 image_processor입니다. Kandinsky를 사용한 텍스트-이미지 생성을 위한 통합 Pipeline 이 모델은 [DiffusionPipeline](/docs/diffusers/main/ko/api/pipelines/overview#diffusers.DiffusionPipeline)에서 상속됩니다. 라이브러리가 모든 파이프라인에 대해 구현하는 일반적 메서드(다운로드 또는 저장, 특정 디바이스에서 실행 등)에 대해서는 상위 클래스 문서를 확인하세요. #### __호출__[[diffusers.KandinskyV22CombinedPipeline.__call__]] ```python __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']) ``` [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py#L202) **매개변수:** 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](https://huggingface.co/papers/2207.12598)에서 정의한 가이던스 스케일입니다. `guidance_scale`은 [Imagen Paper](https://huggingface.co/papers/2205.11487)의 2번 식의 `w`로 정의됩니다. `guidance_scale > 1`로 설정하면 가이던스 스케일이 활성화됩니다. 가이던스 스케일이 높을수록 `prompt` 텍스트와 밀접하게 연결된 이미지를 생성하도록 장려하지만, 일반적으로 이미지 품질이 낮아지는 대가를 치릅니다. prior_num_inference_steps (`int`, *선택 사항*, 기본값 100) : 디노이징 단계의 수입니다. 디노이징 단계가 많을수록 일반적으로 추론 속도가 느려지는 대신 더 높은 품질의 이미지를 생성합니다. guidance_scale (`float`, *선택 사항*, 기본값 4.0) : [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598)에서 정의한 가이던스 스케일입니다. `guidance_scale`은 [Imagen Paper](https://huggingface.co/papers/2205.11487)의 2번 식의 `w`로 정의됩니다. `guidance_scale > 1`로 설정하면 가이던스 스케일이 활성화됩니다. 가이던스 스케일이 높을수록 `prompt` 텍스트와 밀접하게 연결된 이미지를 생성하도록 장려하지만, 일반적으로 이미지 품질이 낮아지는 대가를 치릅니다. generator (`torch.Generator` 또는 `list[torch.Generator]`, *선택 사항*) : 생성을 결정적으로 만들기 위한 [torch generator](https://pytorch.org/docs/stable/generated/torch.Generator.html) 하나 또는 목록. 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](/docs/diffusers/main/ko/api/pipelines/stable_unclip#diffusers.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](/docs/diffusers/main/ko/api/pipelines/stable_unclip#diffusers.ImagePipelineOutput) 또는 `tuple` 생성을 위해 파이프라인을 호출할 때 호출되는 함수. 예: ```py 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]] ```python enable_sequential_cpu_offload(gpu_id: int | None = None, device: typing.Union[torch.device, str] = None) ``` [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py#L182) 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 `forward` method called. Note that offloading happens on a submodule basis. Memory savings are higher than with `enable_model_cpu_offload`, but performance is lower. ## KandinskyV22ControlnetPipeline[[diffusers.KandinskyV22ControlnetPipeline]] #### diffusers.KandinskyV22ControlnetPipeline[[diffusers.KandinskyV22ControlnetPipeline]] ```python diffusers.KandinskyV22ControlnetPipeline(unet: UNet2DConditionModel, scheduler: DDPMScheduler, movq: VQModel) ``` [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet.py#L114) **매개변수:** scheduler ([DDIMScheduler](/docs/diffusers/main/ko/api/schedulers/ddim#diffusers.DDIMScheduler)) : `unet`와 함께 사용하여 이미지 latents를 생성하는 스케줄러입니다. unet ([UNet2DConditionModel](/docs/diffusers/main/ko/api/models/unet2d-cond#diffusers.UNet2DConditionModel)) : 이미지 임베딩의 노이즈를 제거하기 위한 조건부 U-Net 아키텍처. movq ([VQModel](/docs/diffusers/main/ko/api/models/vq#diffusers.VQModel)) : latents에서 이미지를 생성하기 위한 MoVQ Decoder입니다. Kandinsky를 사용한 텍스트-이미지 생성을 위한 Pipeline 이 모델은 [DiffusionPipeline](/docs/diffusers/main/ko/api/pipelines/overview#diffusers.DiffusionPipeline)에서 상속됩니다. 라이브러리가 모든 파이프라인에 대해 구현하는 일반적 메서드(다운로드 또는 저장, 특정 디바이스에서 실행 등)에 대해서는 상위 클래스 문서를 확인하세요. #### __호출__[[diffusers.KandinskyV22ControlnetPipeline.__call__]] ```python __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) ``` [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet.py#L159) **매개변수:** 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](https://huggingface.co/papers/2207.12598)에서 정의한 가이던스 스케일입니다. `guidance_scale`은 [Imagen Paper](https://huggingface.co/papers/2205.11487)의 2번 식의 `w`로 정의됩니다. `guidance_scale > 1`로 설정하면 가이던스 스케일이 활성화됩니다. 가이던스 스케일이 높을수록 `prompt` 텍스트와 밀접하게 연결된 이미지를 생성하도록 장려하지만, 일반적으로 이미지 품질이 낮아지는 대가를 치릅니다. num_images_per_prompt (`int`, *선택 사항*, 기본값 1) : 프롬프트당 생성할 이미지의 수. generator (`torch.Generator` 또는 `list[torch.Generator]`, *선택 사항*) : 생성을 결정적으로 만들기 위한 [torch generator](https://pytorch.org/docs/stable/generated/torch.Generator.html) 하나 또는 목록. 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](/docs/diffusers/main/ko/api/pipelines/stable_unclip#diffusers.ImagePipelineOutput)을 반환할지 여부. **반환값:** [ImagePipelineOutput](/docs/diffusers/main/ko/api/pipelines/stable_unclip#diffusers.ImagePipelineOutput) 또는 `tuple` 생성을 위해 파이프라인을 호출할 때 호출되는 함수. 예: ## KandinskyV22PriorEmb2EmbPipeline[[diffusers.KandinskyV22PriorEmb2EmbPipeline]] #### diffusers.KandinskyV22PriorEmb2EmbPipeline[[diffusers.KandinskyV22PriorEmb2EmbPipeline]] ```python diffusers.KandinskyV22PriorEmb2EmbPipeline(prior: PriorTransformer, image_encoder: CLIPVisionModelWithProjection, text_encoder: CLIPTextModelWithProjection, tokenizer: CLIPTokenizer, scheduler: UnCLIPScheduler, image_processor: CLIPImageProcessorPil) ``` [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior_emb2emb.py#L103) **매개변수:** prior ([PriorTransformer](/docs/diffusers/main/ko/api/models/prior_transformer#diffusers.PriorTransformer)) : 텍스트 임베딩에서 이미지 임베딩을 근사하기 위한 unCLIP의 표준 사전 분포 모델. image_encoder (`CLIPVisionModelWithProjection`) : 고정된 이미지 인코더. text_encoder (`CLIPTextModelWithProjection`) : 고정된 텍스트 인코더. tokenizer (`CLIPTokenizer`) : [CLIPTokenizer](https://huggingface.co/docs/transformers/v4.21.0/en/model_doc/clip#transformers.CLIPTokenizer) 클래스의 토크나이저. scheduler (`UnCLIPScheduler`) : `prior`와 함께 사용하여 이미지 임베딩을 생성하는 스케줄러입니다. Kandinsky의 이미지 prior를 생성하는 Pipeline 이 모델은 [DiffusionPipeline](/docs/diffusers/main/ko/api/pipelines/overview#diffusers.DiffusionPipeline)에서 상속됩니다. 라이브러리가 모든 파이프라인에 대해 구현하는 일반적 메서드(다운로드 또는 저장, 특정 디바이스에서 실행 등)에 대해서는 상위 클래스 문서를 확인하세요. #### __호출__[[diffusers.KandinskyV22PriorEmb2EmbPipeline.__call__]] ```python __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) ``` [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior_emb2emb.py#L397) **매개변수:** 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](https://pytorch.org/docs/stable/generated/torch.Generator.html) 하나 또는 목록. guidance_scale (`float`, *선택 사항*, 기본값 4.0) : [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598)에서 정의한 가이던스 스케일입니다. `guidance_scale`은 [Imagen Paper](https://huggingface.co/papers/2205.11487)의 2번 식의 `w`로 정의됩니다. `guidance_scale > 1`로 설정하면 가이던스 스케일이 활성화됩니다. 가이던스 스케일이 높을수록 `prompt` 텍스트와 밀접하게 연결된 이미지를 생성하도록 장려하지만, 일반적으로 이미지 품질이 낮아지는 대가를 치릅니다. output_type (`str`, *선택 사항*, 기본값 `"pt"`) : 이미지 생성의 출력 형식입니다. 다음 중 하나를 선택합니다: `"np"` (`np.array`) 또는 `"pt"` (`torch.Tensor`). return_dict (`bool`, *선택 사항*, 기본값 `True`) : 일반 튜플 대신 [ImagePipelineOutput](/docs/diffusers/main/ko/api/pipelines/stable_unclip#diffusers.ImagePipelineOutput)을 반환할지 여부. **반환값:** `KandinskyPriorPipelineOutput` 또는 `tuple` 생성을 위해 파이프라인을 호출할 때 호출되는 함수. 예: ```py >>> 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]] ```python 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) ``` [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior_emb2emb.py#L156) **매개변수:** 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](https://pytorch.org/docs/stable/generated/torch.Generator.html) 하나 또는 목록. 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](https://huggingface.co/papers/2207.12598)에서 정의한 가이던스 스케일입니다. `guidance_scale`은 [Imagen Paper](https://huggingface.co/papers/2205.11487)의 2번 식의 `w`로 정의됩니다. `guidance_scale > 1`로 설정하면 가이던스 스케일이 활성화됩니다. 가이던스 스케일이 높을수록 `prompt` 텍스트와 밀접하게 연결된 이미지를 생성하도록 장려하지만, 일반적으로 이미지 품질이 낮아지는 대가를 치릅니다. **반환값:** `KandinskyPriorPipelineOutput` 또는 `tuple` interpolation에 pipeline을 사용할 때 호출되는 함수입니다. 예: ```py >>> 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]] ```python diffusers.KandinskyV22Img2ImgPipeline(unet: UNet2DConditionModel, scheduler: DDPMScheduler, movq: VQModel) ``` [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_img2img.py#L77) **매개변수:** scheduler ([DDIMScheduler](/docs/diffusers/main/ko/api/schedulers/ddim#diffusers.DDIMScheduler)) : `unet`와 함께 사용하여 이미지 latents를 생성하는 스케줄러입니다. unet ([UNet2DConditionModel](/docs/diffusers/main/ko/api/models/unet2d-cond#diffusers.UNet2DConditionModel)) : 이미지 임베딩의 노이즈를 제거하기 위한 조건부 U-Net 아키텍처. movq ([VQModel](/docs/diffusers/main/ko/api/models/vq#diffusers.VQModel)) : latents에서 이미지를 생성하기 위한 MoVQ Decoder입니다. Kandinsky를 사용한 이미지-이미지 생성을 위한 Pipeline 이 모델은 [DiffusionPipeline](/docs/diffusers/main/ko/api/pipelines/overview#diffusers.DiffusionPipeline)에서 상속됩니다. 라이브러리가 모든 파이프라인에 대해 구현하는 일반적 메서드(다운로드 또는 저장, 특정 디바이스에서 실행 등)에 대해서는 상위 클래스 문서를 확인하세요. #### __호출__[[diffusers.KandinskyV22Img2ImgPipeline.__call__]] ```python __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) ``` [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_img2img.py#L182) **매개변수:** 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](https://huggingface.co/papers/2207.12598)에서 정의한 가이던스 스케일입니다. `guidance_scale`은 [Imagen Paper](https://huggingface.co/papers/2205.11487)의 2번 식의 `w`로 정의됩니다. `guidance_scale > 1`로 설정하면 가이던스 스케일이 활성화됩니다. 가이던스 스케일이 높을수록 `prompt` 텍스트와 밀접하게 연결된 이미지를 생성하도록 장려하지만, 일반적으로 이미지 품질이 낮아지는 대가를 치릅니다. num_images_per_prompt (`int`, *선택 사항*, 기본값 1) : 프롬프트당 생성할 이미지의 수. generator (`torch.Generator` 또는 `list[torch.Generator]`, *선택 사항*) : 생성을 결정적으로 만들기 위한 [torch generator](https://pytorch.org/docs/stable/generated/torch.Generator.html) 하나 또는 목록. output_type (`str`, *선택 사항*, 기본값 `"pil"`) : 이미지 생성의 출력 형식입니다. 다음 중 하나를 선택합니다: `"pil"` (`PIL.Image.Image`), `"np"` (`np.array`) 또는 `"pt"` (`torch.Tensor`). return_dict (`bool`, *선택 사항*, 기본값 `True`) : 일반 튜플 대신 [ImagePipelineOutput](/docs/diffusers/main/ko/api/pipelines/stable_unclip#diffusers.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](/docs/diffusers/main/ko/api/pipelines/stable_unclip#diffusers.ImagePipelineOutput) 또는 `tuple` 생성을 위해 파이프라인을 호출할 때 호출되는 함수. 예: ## KandinskyV22Img2ImgCombinedPipeline[[diffusers.KandinskyV22Img2ImgCombinedPipeline]] #### diffusers.KandinskyV22Img2ImgCombinedPipeline[[diffusers.KandinskyV22Img2ImgCombinedPipeline]] ```python 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) ``` [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py#L341) **매개변수:** scheduler (`DDIMScheduler` | `DDPMScheduler`) : `unet`와 함께 사용하여 이미지 latents를 생성하는 데 사용되는 스케줄러. unet ([UNet2DConditionModel](/docs/diffusers/main/ko/api/models/unet2d-cond#diffusers.UNet2DConditionModel)) : 이미지 임베딩의 노이즈를 제거하기 위한 조건부 U-Net 아키텍처. movq ([VQModel](/docs/diffusers/main/ko/api/models/vq#diffusers.VQModel)) : latents에서 이미지를 생성하기 위한 MoVQ Decoder입니다. prior_prior ([PriorTransformer](/docs/diffusers/main/ko/api/models/prior_transformer#diffusers.PriorTransformer)) : 텍스트 임베딩에서 이미지 임베딩을 근사하기 위한 unCLIP의 표준 사전 분포 모델. prior_image_encoder (`CLIPVisionModelWithProjection`) : 고정된 이미지 인코더. prior_text_encoder (`CLIPTextModelWithProjection`) : 고정된 텍스트 인코더. prior_tokenizer (`CLIPTokenizer`) : [CLIPTokenizer](https://huggingface.co/docs/transformers/v4.21.0/en/model_doc/clip#transformers.CLIPTokenizer) 클래스의 토크나이저. prior_scheduler (`UnCLIPScheduler`) : `prior`와 함께 사용하여 이미지 임베딩을 생성하는 스케줄러입니다. prior_image_processor (`CLIPImageProcessor`) : clip에서 이미지를 전처리하는 데 사용되는 image_processor입니다. Kandinsky를 사용한 이미지-이미지 생성을 위한 통합 Pipeline 이 모델은 [DiffusionPipeline](/docs/diffusers/main/ko/api/pipelines/overview#diffusers.DiffusionPipeline)에서 상속됩니다. 라이브러리가 모든 파이프라인에 대해 구현하는 일반적 메서드(다운로드 또는 저장, 특정 디바이스에서 실행 등)에 대해서는 상위 클래스 문서를 확인하세요. #### __호출__[[diffusers.KandinskyV22Img2ImgCombinedPipeline.__call__]] ```python __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']) ``` [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py#L446) **매개변수:** 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](https://huggingface.co/papers/2207.12598)에서 정의한 가이던스 스케일입니다. `guidance_scale`은 [Imagen Paper](https://huggingface.co/papers/2205.11487)의 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](https://huggingface.co/papers/2207.12598)에서 정의한 가이던스 스케일입니다. `guidance_scale`은 [Imagen Paper](https://huggingface.co/papers/2205.11487)의 2번 식의 `w`로 정의됩니다. `guidance_scale > 1`로 설정하면 가이던스 스케일이 활성화됩니다. 가이던스 스케일이 높을수록 `prompt` 텍스트와 밀접하게 연결된 이미지를 생성하도록 장려하지만, 일반적으로 이미지 품질이 낮아지는 대가를 치릅니다. prior_num_inference_steps (`int`, *선택 사항*, 기본값 100) : 디노이징 단계의 수입니다. 디노이징 단계가 많을수록 일반적으로 추론 속도가 느려지는 대신 더 높은 품질의 이미지를 생성합니다. generator (`torch.Generator` 또는 `list[torch.Generator]`, *선택 사항*) : 생성을 결정적으로 만들기 위한 [torch generator](https://pytorch.org/docs/stable/generated/torch.Generator.html) 하나 또는 목록. 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](/docs/diffusers/main/ko/api/pipelines/stable_unclip#diffusers.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](/docs/diffusers/main/ko/api/pipelines/stable_unclip#diffusers.ImagePipelineOutput) 또는 `tuple` 생성을 위해 파이프라인을 호출할 때 호출되는 함수. 예: ```py 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]] ```python enable_model_cpu_offload(gpu_id: int | None = None, device: typing.Union[torch.device, str] = None) ``` [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py#L416) accelerate를 사용하여 모든 모델을 CPU로 오프로드하여 성능에 미치는 영향은 적으면서 메모리 사용량을 줄입니다. `enable_sequential_cpu_offload`와 비교하면, 이 메서드는 `forward` 메서드가 호출될 때 한 번에 하나의 모델을 GPU로 이동하며, 다음 모델이 실행될 때까지 해당 모델은 GPU에 유지됩니다. `enable_sequential_cpu_offload`를 사용할 때보다 메모리 절감 효과는 낮지만, `unet`의 반복적 실행 덕분에 성능이 훨씬 좋습니다. #### enable_sequential_cpu_offload[[diffusers.KandinskyV22Img2ImgCombinedPipeline.enable_sequential_cpu_offload]] ```python enable_sequential_cpu_offload(gpu_id: int | None = None, device: typing.Union[torch.device, str] = None) ``` [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py#L426) 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 `forward` method called. Note that offloading happens on a submodule basis. Memory savings are higher than with `enable_model_cpu_offload`, but performance is lower. ## KandinskyV22ControlnetImg2ImgPipeline[[diffusers.KandinskyV22ControlnetImg2ImgPipeline]] #### diffusers.KandinskyV22ControlnetImg2ImgPipeline[[diffusers.KandinskyV22ControlnetImg2ImgPipeline]] ```python diffusers.KandinskyV22ControlnetImg2ImgPipeline(unet: UNet2DConditionModel, scheduler: DDPMScheduler, movq: VQModel) ``` [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet_img2img.py#L106) **매개변수:** scheduler ([DDIMScheduler](/docs/diffusers/main/ko/api/schedulers/ddim#diffusers.DDIMScheduler)) : `unet`와 함께 사용하여 이미지 latents를 생성하는 스케줄러입니다. unet ([UNet2DConditionModel](/docs/diffusers/main/ko/api/models/unet2d-cond#diffusers.UNet2DConditionModel)) : 이미지 임베딩의 노이즈를 제거하기 위한 조건부 U-Net 아키텍처. movq ([VQModel](/docs/diffusers/main/ko/api/models/vq#diffusers.VQModel)) : latents에서 이미지를 생성하기 위한 MoVQ Decoder입니다. Kandinsky를 사용한 이미지-이미지 생성을 위한 Pipeline 이 모델은 [DiffusionPipeline](/docs/diffusers/main/ko/api/pipelines/overview#diffusers.DiffusionPipeline)에서 상속됩니다. 라이브러리가 모든 파이프라인에 대해 구현하는 일반적 메서드(다운로드 또는 저장, 특정 디바이스에서 실행 등)에 대해서는 상위 클래스 문서를 확인하세요. #### __호출__[[diffusers.KandinskyV22ControlnetImg2ImgPipeline.__call__]] ```python __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) ``` [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet_img2img.py#L199) **매개변수:** 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](https://huggingface.co/papers/2207.12598)에서 정의한 가이던스 스케일입니다. `guidance_scale`은 [Imagen Paper](https://huggingface.co/papers/2205.11487)의 2번 식의 `w`로 정의됩니다. `guidance_scale > 1`로 설정하면 가이던스 스케일이 활성화됩니다. 가이던스 스케일이 높을수록 `prompt` 텍스트와 밀접하게 연결된 이미지를 생성하도록 장려하지만, 일반적으로 이미지 품질이 낮아지는 대가를 치릅니다. num_images_per_prompt (`int`, *선택 사항*, 기본값 1) : 프롬프트당 생성할 이미지의 수. generator (`torch.Generator` 또는 `list[torch.Generator]`, *선택 사항*) : 생성을 결정적으로 만들기 위한 [torch generator](https://pytorch.org/docs/stable/generated/torch.Generator.html) 하나 또는 목록. 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](/docs/diffusers/main/ko/api/pipelines/stable_unclip#diffusers.ImagePipelineOutput)을 반환할지 여부. **반환값:** [ImagePipelineOutput](/docs/diffusers/main/ko/api/pipelines/stable_unclip#diffusers.ImagePipelineOutput) 또는 `tuple` 생성을 위해 파이프라인을 호출할 때 호출되는 함수. 예: ## KandinskyV22InpaintPipeline[[diffusers.KandinskyV22InpaintPipeline]] #### diffusers.KandinskyV22InpaintPipeline[[diffusers.KandinskyV22InpaintPipeline]] ```python diffusers.KandinskyV22InpaintPipeline(unet: UNet2DConditionModel, scheduler: DDPMScheduler, movq: VQModel) ``` [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_inpainting.py#L242) **매개변수:** scheduler ([DDIMScheduler](/docs/diffusers/main/ko/api/schedulers/ddim#diffusers.DDIMScheduler)) : `unet`와 함께 사용하여 이미지 latents를 생성하는 스케줄러입니다. unet ([UNet2DConditionModel](/docs/diffusers/main/ko/api/models/unet2d-cond#diffusers.UNet2DConditionModel)) : 이미지 임베딩의 노이즈를 제거하기 위한 조건부 U-Net 아키텍처. movq ([VQModel](/docs/diffusers/main/ko/api/models/vq#diffusers.VQModel)) : latents에서 이미지를 생성하기 위한 MoVQ Decoder입니다. Kandinsky2.1을 사용한 텍스트 기반 이미지 인페인팅을 위한 Pipeline 이 모델은 [DiffusionPipeline](/docs/diffusers/main/ko/api/pipelines/overview#diffusers.DiffusionPipeline)에서 상속됩니다. 라이브러리가 모든 파이프라인에 대해 구현하는 일반적 메서드(다운로드 또는 저장, 특정 디바이스에서 실행 등)에 대해서는 상위 클래스 문서를 확인하세요. #### __호출__[[diffusers.KandinskyV22InpaintPipeline.__call__]] ```python __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) ``` [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_inpainting.py#L301) **매개변수:** 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](https://huggingface.co/papers/2207.12598)에서 정의한 가이던스 스케일입니다. `guidance_scale`은 [Imagen Paper](https://huggingface.co/papers/2205.11487)의 2번 식의 `w`로 정의됩니다. `guidance_scale > 1`로 설정하면 가이던스 스케일이 활성화됩니다. 가이던스 스케일이 높을수록 `prompt` 텍스트와 밀접하게 연결된 이미지를 생성하도록 장려하지만, 일반적으로 이미지 품질이 낮아지는 대가를 치릅니다. num_images_per_prompt (`int`, *선택 사항*, 기본값 1) : 프롬프트당 생성할 이미지의 수. generator (`torch.Generator` 또는 `list[torch.Generator]`, *선택 사항*) : 생성을 결정적으로 만들기 위한 [torch generator](https://pytorch.org/docs/stable/generated/torch.Generator.html) 하나 또는 목록. 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](/docs/diffusers/main/ko/api/pipelines/stable_unclip#diffusers.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](/docs/diffusers/main/ko/api/pipelines/stable_unclip#diffusers.ImagePipelineOutput) 또는 `tuple` 생성을 위해 파이프라인을 호출할 때 호출되는 함수. 예: ## KandinskyV22InpaintCombinedPipeline[[diffusers.KandinskyV22InpaintCombinedPipeline]] #### diffusers.KandinskyV22InpaintCombinedPipeline[[diffusers.KandinskyV22InpaintCombinedPipeline]] ```python 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) ``` [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py#L607) **매개변수:** scheduler (`DDIMScheduler` | `DDPMScheduler`) : `unet`와 함께 사용하여 이미지 latents를 생성하는 데 사용되는 스케줄러. unet ([UNet2DConditionModel](/docs/diffusers/main/ko/api/models/unet2d-cond#diffusers.UNet2DConditionModel)) : 이미지 임베딩의 노이즈를 제거하기 위한 조건부 U-Net 아키텍처. movq ([VQModel](/docs/diffusers/main/ko/api/models/vq#diffusers.VQModel)) : latents에서 이미지를 생성하기 위한 MoVQ Decoder입니다. prior_prior ([PriorTransformer](/docs/diffusers/main/ko/api/models/prior_transformer#diffusers.PriorTransformer)) : 텍스트 임베딩에서 이미지 임베딩을 근사하기 위한 unCLIP의 표준 사전 분포 모델. prior_image_encoder (`CLIPVisionModelWithProjection`) : 고정된 이미지 인코더. prior_text_encoder (`CLIPTextModelWithProjection`) : 고정된 텍스트 인코더. prior_tokenizer (`CLIPTokenizer`) : [CLIPTokenizer](https://huggingface.co/docs/transformers/v4.21.0/en/model_doc/clip#transformers.CLIPTokenizer) 클래스의 토크나이저. prior_scheduler (`UnCLIPScheduler`) : `prior`와 함께 사용하여 이미지 임베딩을 생성하는 스케줄러입니다. prior_image_processor (`CLIPImageProcessor`) : clip에서 이미지를 전처리하는 데 사용되는 image_processor입니다. Kandinsky를 사용한 인페인팅 생성을 위한 통합 파이프라인 이 모델은 [DiffusionPipeline](/docs/diffusers/main/ko/api/pipelines/overview#diffusers.DiffusionPipeline)에서 상속됩니다. 라이브러리가 모든 파이프라인에 대해 구현하는 일반적 메서드(다운로드 또는 저장, 특정 디바이스에서 실행 등)에 대해서는 상위 클래스 문서를 확인하세요. #### __호출__[[diffusers.KandinskyV22InpaintCombinedPipeline.__call__]] ```python __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) ``` [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py#L702) **매개변수:** 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](https://huggingface.co/papers/2207.12598)에서 정의한 가이던스 스케일입니다. `guidance_scale`은 [Imagen Paper](https://huggingface.co/papers/2205.11487)의 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](https://huggingface.co/papers/2207.12598)에서 정의한 가이던스 스케일입니다. `guidance_scale`은 [Imagen Paper](https://huggingface.co/papers/2205.11487)의 2번 식의 `w`로 정의됩니다. `guidance_scale > 1`로 설정하면 가이던스 스케일이 활성화됩니다. 가이던스 스케일이 높을수록 `prompt` 텍스트와 밀접하게 연결된 이미지를 생성하도록 장려하지만, 일반적으로 이미지 품질이 낮아지는 대가를 치릅니다. prior_num_inference_steps (`int`, *선택 사항*, 기본값 100) : 디노이징 단계의 수입니다. 디노이징 단계가 많을수록 일반적으로 추론 속도가 느려지는 대신 더 높은 품질의 이미지를 생성합니다. generator (`torch.Generator` 또는 `list[torch.Generator]`, *선택 사항*) : 생성을 결정적으로 만들기 위한 [torch generator](https://pytorch.org/docs/stable/generated/torch.Generator.html) 하나 또는 목록. 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](/docs/diffusers/main/ko/api/pipelines/stable_unclip#diffusers.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](/docs/diffusers/main/ko/api/pipelines/stable_unclip#diffusers.ImagePipelineOutput) 또는 `tuple` 생성을 위해 파이프라인을 호출할 때 호출되는 함수. 예: ```py 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]] ```python enable_sequential_cpu_offload(gpu_id: int | None = None, device: typing.Union[torch.device, str] = None) ``` [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py#L682) 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 `forward` method called. Note that offloading happens on a submodule basis. Memory savings are higher than with `enable_model_cpu_offload`, but performance is lower.
# Kandinsky 2.2
Kandinsky 2.2는 [Arseniy Shakhmatov](https://github.com/cene555), [Anton Razzhigaev](https://github.com/razzant), [Aleksandr Nikolich](https://github.com/AlexWortega), [Vladimir Arkhipkin](https://github.com/oriBetelgeuse), [Igor Pavlov](https://github.com/boomb0om), [Andrey Kuznetsov](https://github.com/kuznetsoffandrey), [Denis Dimitrov](https://github.com/denndimitrov)에 의해 개발되었습니다.
GitHub 페이지의 설명은 다음과 같습니다:
*Kandinsky 2.2는 이전 버전인 Kandinsky 2.1에 비해 새로운 이미지 인코더인 CLIP-ViT-G와 ControlNet 지원을 도입함으로써 상당한 성능 향상을 가져왔습니다. 이미지 인코더를 CLIP-ViT-G로 전환한 것은 모델이 더 미학적인 이미지를 생성하고 텍스트를 더 잘 이해하는 능력을 크게 향상시켜 모델의 전반적인 성능을 높였습니다. ControlNet 메커니즘의 추가는 모델이 이미지 생성 과정을 효과적으로 제어할 수 있게 합니다. 이를 통해 더 정확하고 시각적으로 매력적인 출력이 가능해지며, 텍스트 기반 이미지 조작에 대한 새로운 가능성을 열어줍니다.*
원본 코드베이스는 [ai-forever/Kandinsky-2](https://github.com/ai-forever/Kandinsky-2)에서 찾을 수 있습니다.
> [!TIP]
> Hub의 [Kandinsky Community](https://huggingface.co/kandinsky-community) 조직에서 텍스트-이미지, 이미지-이미지, 인페인팅과 같은 작업에 대한 공식 모델 체크포인트를 확인해 보세요.
> [!TIP]
> 스케줄러의 [가이드](../../using-diffusers/schedulers)를 확인하여 스케줄러의 속도와 품질 사이의 트레이드오프를 탐색하는 방법을 배우고, [파이프라인 간 구성 요소 재사용](../../using-diffusers/loading#reusing-models-in-multiple-pipelines) 섹션을 확인하여 동일한 구성 요소를 여러 파이프라인에 효율적으로 로드하는 방법을 배워보세요.
## KandinskyV22PriorPipeline[[diffusers.KandinskyV22PriorPipeline]]
#### diffusers.KandinskyV22PriorPipeline[[diffusers.KandinskyV22PriorPipeline]]
```python
diffusers.KandinskyV22PriorPipeline(prior: PriorTransformer, image_encoder: CLIPVisionModelWithProjection, text_encoder: CLIPTextModelWithProjection, tokenizer: CLIPTokenizer, scheduler: UnCLIPScheduler, image_processor: CLIPImageProcessorPil)
```
[소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior.py#L88)
**매개변수:**
prior ([PriorTransformer](/docs/diffusers/main/ko/api/models/prior_transformer#diffusers.PriorTransformer)) : 텍스트 임베딩에서 이미지 임베딩을 근사하기 위한 unCLIP의 표준 사전 분포 모델.
image_encoder (`CLIPVisionModelWithProjection`) : 고정된 이미지 인코더.
text_encoder (`CLIPTextModelWithProjection`) : 고정된 텍스트 인코더.
tokenizer (`CLIPTokenizer`) : [CLIPTokenizer](https://huggingface.co/docs/transformers/v4.21.0/en/model_doc/clip#transformers.CLIPTokenizer) 클래스의 토크나이저.
scheduler (`UnCLIPScheduler`) : `prior`와 함께 사용하여 이미지 임베딩을 생성하는 스케줄러입니다.
image_processor (`CLIPImageProcessor`) : clip에서 이미지를 전처리하는 데 사용되는 image_processor입니다.
Kandinsky의 이미지 prior를 생성하는 Pipeline
이 모델은 [DiffusionPipeline](/docs/diffusers/main/ko/api/pipelines/overview#diffusers.DiffusionPipeline)에서 상속됩니다. 라이브러리가 모든 파이프라인에 대해 구현하는 일반적 메서드(다운로드 또는 저장, 특정 디바이스에서 실행 등)에 대해서는 상위 클래스 문서를 확인하세요.
#### __호출__[[diffusers.KandinskyV22PriorPipeline.__call__]]
```python
__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'])
```
[소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior.py#L374)
**매개변수:**
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](https://pytorch.org/docs/stable/generated/torch.Generator.html) 하나 또는 목록.
latents (`torch.Tensor`, *선택 사항*) : 이미지 생성의 입력으로 사용할 가우시안 분포에서 샘플링된 사전 생성된 노이즈된 latents입니다. 동일한 생성을 다른 프롬프트로 조정하는 데 사용할 수 있습니다. 제공되지 않으면, 제공된 랜덤 `generator`를 사용하여 샘플링하여 latents 텐서가 생성됩니다.
guidance_scale (`float`, *선택 사항*, 기본값 4.0) : [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598)에서 정의한 가이던스 스케일입니다. `guidance_scale`은 [Imagen Paper](https://huggingface.co/papers/2205.11487)의 2번 식의 `w`로 정의됩니다. `guidance_scale > 1`로 설정하면 가이던스 스케일이 활성화됩니다. 가이던스 스케일이 높을수록 `prompt` 텍스트와 밀접하게 연결된 이미지를 생성하도록 장려하지만, 일반적으로 이미지 품질이 낮아지는 대가를 치릅니다.
output_type (`str`, *선택 사항*, 기본값 `"pt"`) : 이미지 생성의 출력 형식입니다. 다음 중 하나를 선택합니다: `"np"` (`np.array`) 또는 `"pt"` (`torch.Tensor`).
return_dict (`bool`, *선택 사항*, 기본값 `True`) : 일반 튜플 대신 [ImagePipelineOutput](/docs/diffusers/main/ko/api/pipelines/stable_unclip#diffusers.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`
생성을 위해 파이프라인을 호출할 때 호출되는 함수.
예:
```py
>>> 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")

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.