Buckets:

hf-doc-build/doc / diffusers /main /ja /api /pipelines /kandinsky_v22.md
mishig's picture
|
download
raw
93.9 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 は、より強力な新しい画像エンコーダーである CLIP-ViT-G と ControlNet のサポートを導入することで、先行バージョンである Kandinsky 2.1 に対して大幅な改善をもたらしました。画像エンコーダーを 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/ja/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) の Tokenizer。 scheduler (`UnCLIPScheduler`) : `prior` と組み合わせて使用し、画像埋め込みを生成するためのスケジューラ。 image_processor (`CLIPImageProcessor`) : clip の画像を前処理するために使用される image_processor。 Kandinsky用の画像事前分布を生成するためのPipeline このモデルは [DiffusionPipeline](/docs/diffusers/main/ja/api/pipelines/overview#diffusers.DiffusionPipeline) を継承しています。ライブラリがすべてのパイプラインに対して実装している汎用的なメソッド(ダウンロードや保存、特定のデバイスでの実行など)については、スーパークラスのドキュメントを参照してください。 #### __call__[[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`、*optional*、デフォルト値は 100) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。 generator (`torch.Generator` または `list[torch.Generator]`、*任意*) : 生成を決定論的にするための [torch ジェネレーター](https://pytorch.org/docs/stable/generated/torch.Generator.html) 1 つまたはそのリスト。 latents (`torch.Tensor`, *任意*) : イメージ生成の入力として使用される、ガウス分布からサンプリングされた事前生成されたノイジー・ラテンツ。異なるプロンプトで同じ生成を調整するために使用できます。指定されない場合、指定されたランダムな`generator`を使用してサンプリングを行い、ラテンツのテンソルが生成されます。 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/ja/api/pipelines/consistency_models#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`、*optional*、デフォルト値は 100) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。 generator (`torch.Generator` または `list[torch.Generator]`、*任意*) : 生成を決定論的にするための [torch ジェネレーター](https://pytorch.org/docs/stable/generated/torch.Generator.html) 1 つまたはそのリスト。 latents (`torch.Tensor`, *任意*) : イメージ生成の入力として使用される、ガウス分布からサンプリングされた事前生成されたノイジー・ラテンツ。異なるプロンプトで同じ生成を調整するために使用できます。指定されない場合、指定されたランダムな`generator`を使用してサンプリングを行い、ラテンツのテンソルが生成されます。 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` 補間のために先行パイプラインを使用する際に呼び出される関数。 例: ```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` と組み合わせて使用し、画像の潜在変数を生成するためのスケジューラ。 unet ([UNet2DConditionModel](/docs/diffusers/main/ja/api/models/unet2d-cond#diffusers.UNet2DConditionModel)) : 画像埋め込みのノイズ除去を行う条件付き U-Net アーキテクチャ。 movq ([VQModel](/docs/diffusers/main/ja/api/models/vq#diffusers.VQModel)) : 潜在変数から画像を生成するための MoVQ デコーダー。 Kandinsky を使用したテキストから画像への生成パイプライン このモデルは [DiffusionPipeline](/docs/diffusers/main/ja/api/pipelines/overview#diffusers.DiffusionPipeline) を継承しています。ライブラリがすべてのパイプラインに対して実装している汎用的なメソッド(ダウンロードや保存、特定のデバイスでの実行など)については、スーパークラスのドキュメントを参照してください。 #### __call__[[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`、*optional*、デフォルトは 512) : 生成される画像の幅(ピクセル単位)。 num_inference_steps (`int`、*optional*、デフォルト値は 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 ジェネレーター](https://pytorch.org/docs/stable/generated/torch.Generator.html) 1 つまたはそのリスト。 latents (`torch.Tensor`, *任意*) : イメージ生成の入力として使用される、ガウス分布からサンプリングされた事前生成されたノイジー・ラテンツ。異なるプロンプトで同じ生成を調整するために使用できます。指定されない場合、指定されたランダムな`generator`を使用してサンプリングを行い、ラテンツのテンソルが生成されます。 output_type (`str`、*任意*、デフォルトは `"pil"`) : 生成画像の出力形式。以下のいずれかを選択します: `"pil"` (`PIL.Image.Image`)、`"np"` (`np.array`)、または `"pt"` (`torch.Tensor`)。 return_dict (`bool`、*任意*、デフォルトは`True`) : プレーンなタプルではなく、[ImagePipelineOutput](/docs/diffusers/main/ja/api/pipelines/consistency_models#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/ja/api/pipelines/consistency_models#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` と組み合わせて使用し、画像の潜在変数を生成するためのスケジューラ。 unet ([UNet2DConditionModel](/docs/diffusers/main/ja/api/models/unet2d-cond#diffusers.UNet2DConditionModel)) : 画像埋め込みのノイズ除去を行う条件付き U-Net アーキテクチャ。 movq ([VQModel](/docs/diffusers/main/ja/api/models/vq#diffusers.VQModel)) : 潜在変数から画像を生成するための MoVQ デコーダー。 prior_prior ([PriorTransformer](/docs/diffusers/main/ja/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) の Tokenizer。 prior_scheduler (`UnCLIPScheduler`) : `prior` と組み合わせて使用し、画像埋め込みを生成するためのスケジューラ。 prior_image_processor (`CLIPImageProcessor`) : clip の画像を前処理するために使用される image_processor。 Kandinsky を使用したテキストから画像への生成を行う統合 Pipeline このモデルは [DiffusionPipeline](/docs/diffusers/main/ja/api/pipelines/overview#diffusers.DiffusionPipeline) を継承しています。ライブラリがすべてのパイプラインに対して実装している汎用的なメソッド(ダウンロードや保存、特定のデバイスでの実行など)については、スーパークラスのドキュメントを参照してください。 #### __call__[[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`、*optional*、デフォルト値は 100) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。 height (`int`、*任意*、デフォルト値は 512) : 生成される画像のピクセル単位の縦幅。 width (`int`、*optional*、デフォルトは 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`、*optional*、デフォルト値は 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 ジェネレーター](https://pytorch.org/docs/stable/generated/torch.Generator.html) 1 つまたはそのリスト。 latents (`torch.Tensor`, *任意*) : イメージ生成の入力として使用される、ガウス分布からサンプリングされた事前生成されたノイジー・ラテンツ。異なるプロンプトで同じ生成を調整するために使用できます。指定されない場合、指定されたランダムな`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`、*optional*、デフォルトは 1) : `callback` 関数が呼び出される頻度です。指定しない場合、callback はすべてのステップで呼び出されます。 return_dict (`bool`、*任意*、デフォルトは`True`) : プレーンなタプルではなく、[ImagePipelineOutput](/docs/diffusers/main/ja/api/pipelines/consistency_models#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/ja/api/pipelines/consistency_models#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/ja/api/schedulers/ddim#diffusers.DDIMScheduler)) : `unet`と組み合わせて使用し、画像の潜在変数を生成するためのスケジューラ。 unet ([UNet2DConditionModel](/docs/diffusers/main/ja/api/models/unet2d-cond#diffusers.UNet2DConditionModel)) : 画像埋め込みのノイズ除去を行う条件付き U-Net アーキテクチャ。 movq ([VQModel](/docs/diffusers/main/ja/api/models/vq#diffusers.VQModel)) : 潜在変数から画像を生成するための MoVQ デコーダー。 Kandinsky を使用したテキストから画像への生成パイプライン このモデルは [DiffusionPipeline](/docs/diffusers/main/ja/api/pipelines/overview#diffusers.DiffusionPipeline) を継承しています。ライブラリがすべてのパイプラインに対して実装している汎用的なメソッド(ダウンロードや保存、特定のデバイスでの実行など)については、スーパークラスのドキュメントを参照してください。 #### __call__[[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`、*optional*、デフォルトは 512) : 生成される画像の幅(ピクセル単位)。 num_inference_steps (`int`、*optional*、デフォルト値は 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 ジェネレーター](https://pytorch.org/docs/stable/generated/torch.Generator.html) 1 つまたはそのリスト。 latents (`torch.Tensor`, *任意*) : イメージ生成の入力として使用される、ガウス分布からサンプリングされた事前生成されたノイジー・ラテンツ。異なるプロンプトで同じ生成を調整するために使用できます。指定されない場合、指定されたランダムな`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`、*optional*、デフォルトは 1) : `callback` 関数が呼び出される頻度です。指定しない場合、callback はすべてのステップで呼び出されます。 return_dict (`bool`、*任意*、デフォルトは`True`) : プレーンなタプルではなく、[ImagePipelineOutput](/docs/diffusers/main/ja/api/pipelines/consistency_models#diffusers.ImagePipelineOutput)を返すかどうか。 **戻り値:** [ImagePipelineOutput](/docs/diffusers/main/ja/api/pipelines/consistency_models#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/ja/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) の Tokenizer。 scheduler (`UnCLIPScheduler`) : `prior` と組み合わせて使用し、画像埋め込みを生成するためのスケジューラ。 Kandinsky用の画像事前分布を生成するためのPipeline このモデルは [DiffusionPipeline](/docs/diffusers/main/ja/api/pipelines/overview#diffusers.DiffusionPipeline) を継承しています。ライブラリがすべてのパイプラインに対して実装している汎用的なメソッド(ダウンロードや保存、特定のデバイスでの実行など)については、スーパークラスのドキュメントを参照してください。 #### __call__[[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` として画像潜在変数(image latents)を直接渡すことも可能で、その場合は再度エンコードされません。 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`、*optional*、デフォルト値は 100) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。 generator (`torch.Generator` または `list[torch.Generator]`、*任意*) : 生成を決定論的にするための [torch ジェネレーター](https://pytorch.org/docs/stable/generated/torch.Generator.html) 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` のテキストと密接に関連した画像の生成が促されますが、通常は画像の品質が低下する傾向があります。 output_type (`str`、*任意*、デフォルトは`"pt"`) : 生成画像の出力形式。`"np"` (`np.array`) または `"pt"` (`torch.Tensor`) から選択します。 return_dict (`bool`、*任意*、デフォルトは`True`) : プレーンなタプルではなく、[ImagePipelineOutput](/docs/diffusers/main/ja/api/pipelines/consistency_models#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`、*optional*、デフォルト値は 100) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。 generator (`torch.Generator` または `list[torch.Generator]`、*任意*) : 生成を決定論的にするための [torch ジェネレーター](https://pytorch.org/docs/stable/generated/torch.Generator.html) 1 つまたはそのリスト。 latents (`torch.Tensor`, *任意*) : イメージ生成の入力として使用される、ガウス分布からサンプリングされた事前生成されたノイジー・ラテンツ。異なるプロンプトで同じ生成を調整するために使用できます。指定されない場合、指定されたランダムな`generator`を使用してサンプリングを行い、ラテンツのテンソルが生成されます。 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` 補間のために先行パイプラインを使用する際に呼び出される関数。 例: ```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/ja/api/schedulers/ddim#diffusers.DDIMScheduler)) : `unet`と組み合わせて使用し、画像の潜在変数を生成するためのスケジューラ。 unet ([UNet2DConditionModel](/docs/diffusers/main/ja/api/models/unet2d-cond#diffusers.UNet2DConditionModel)) : 画像埋め込みのノイズ除去を行う条件付き U-Net アーキテクチャ。 movq ([VQModel](/docs/diffusers/main/ja/api/models/vq#diffusers.VQModel)) : 潜在変数から画像を生成するための MoVQ デコーダー。 Kandinsky を使用した画像から画像への生成のための Pipeline このモデルは [DiffusionPipeline](/docs/diffusers/main/ja/api/pipelines/overview#diffusers.DiffusionPipeline) を継承しています。ライブラリがすべてのパイプラインに対して実装している汎用的なメソッド(ダウンロードや保存、特定のデバイスでの実行など)については、スーパークラスのドキュメントを参照してください。 #### __call__[[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` として画像の潜在変数(latents)を直接渡すことも可能で、その場合は再度エンコードされません。 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`、*optional*、デフォルトは 512) : 生成される画像の幅(ピクセル単位)。 num_inference_steps (`int`、*optional*、デフォルト値は 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 ジェネレーター](https://pytorch.org/docs/stable/generated/torch.Generator.html) 1 つまたはそのリスト。 output_type (`str`、*任意*、デフォルトは `"pil"`) : 生成画像の出力形式。以下のいずれかを選択します: `"pil"` (`PIL.Image.Image`)、`"np"` (`np.array`)、または `"pt"` (`torch.Tensor`)。 return_dict (`bool`、*任意*、デフォルトは`True`) : プレーンなタプルではなく、[ImagePipelineOutput](/docs/diffusers/main/ja/api/pipelines/consistency_models#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/ja/api/pipelines/consistency_models#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` と組み合わせて使用し、画像の潜在変数を生成するためのスケジューラ。 unet ([UNet2DConditionModel](/docs/diffusers/main/ja/api/models/unet2d-cond#diffusers.UNet2DConditionModel)) : 画像埋め込みのノイズ除去を行う条件付き U-Net アーキテクチャ。 movq ([VQModel](/docs/diffusers/main/ja/api/models/vq#diffusers.VQModel)) : 潜在変数から画像を生成するための MoVQ デコーダー。 prior_prior ([PriorTransformer](/docs/diffusers/main/ja/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) の Tokenizer。 prior_scheduler (`UnCLIPScheduler`) : `prior` と組み合わせて使用し、画像埋め込みを生成するためのスケジューラ。 prior_image_processor (`CLIPImageProcessor`) : clip の画像を前処理するために使用される image_processor。 Kandinsky を用いた画像から画像への生成のための統合 Pipeline このモデルは [DiffusionPipeline](/docs/diffusers/main/ja/api/pipelines/overview#diffusers.DiffusionPipeline) を継承しています。ライブラリがすべてのパイプラインに対して実装している汎用的なメソッド(ダウンロードや保存、特定のデバイスでの実行など)については、スーパークラスのドキュメントを参照してください。 #### __call__[[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` として画像の潜在変数(latents)を直接渡すことも可能で、その場合は再度エンコードされません。 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`, *optional*, デフォルト値は 0.3) : 概念的には、参照となる `image` をどの程度変換するかを示します。0 から 1 の間の値である必要があります。 `image` は開始点として使用され、 `strength` が大きいほど、それに加えられるノイズ量が増えます。デノイジングのステップ数は、最初に追加されるノイズ量に依存します。 `strength` が 1 の場合、追加されるノイズは最大となり、デノイジングプロセスは `num_inference_steps` で指定された全イテレーション数分実行されます。したがって、値が 1 である場合、 `image` は実質的に無視されます。 num_inference_steps (`int`、*optional*、デフォルト値は 100) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。 height (`int`、*任意*、デフォルト値は 512) : 生成される画像のピクセル単位の縦幅。 width (`int`、*optional*、デフォルトは 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`、*optional*、デフォルト値は 100) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。 generator (`torch.Generator` または `list[torch.Generator]`、*任意*) : 生成を決定論的にするための [torch ジェネレーター](https://pytorch.org/docs/stable/generated/torch.Generator.html) 1 つまたはそのリスト。 latents (`torch.Tensor`, *任意*) : イメージ生成の入力として使用される、ガウス分布からサンプリングされた事前生成されたノイジー・ラテンツ。異なるプロンプトで同じ生成を調整するために使用できます。指定されない場合、指定されたランダムな`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`、*optional*、デフォルトは 1) : `callback` 関数が呼び出される頻度です。指定しない場合、callback はすべてのステップで呼び出されます。 return_dict (`bool`、*任意*、デフォルトは`True`) : プレーンなタプルではなく、[ImagePipelineOutput](/docs/diffusers/main/ja/api/pipelines/consistency_models#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/ja/api/pipelines/consistency_models#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` メソッドが呼び出されたときに、一度に 1 つのモデル全体を 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/ja/api/schedulers/ddim#diffusers.DDIMScheduler)) : `unet`と組み合わせて使用し、画像の潜在変数を生成するためのスケジューラ。 unet ([UNet2DConditionModel](/docs/diffusers/main/ja/api/models/unet2d-cond#diffusers.UNet2DConditionModel)) : 画像埋め込みのノイズ除去を行う条件付き U-Net アーキテクチャ。 movq ([VQModel](/docs/diffusers/main/ja/api/models/vq#diffusers.VQModel)) : 潜在変数から画像を生成するための MoVQ デコーダー。 Kandinsky を使用した画像から画像への生成のための Pipeline このモデルは [DiffusionPipeline](/docs/diffusers/main/ja/api/pipelines/overview#diffusers.DiffusionPipeline) を継承しています。ライブラリがすべてのパイプラインに対して実装している汎用的なメソッド(ダウンロードや保存、特定のデバイスでの実行など)については、スーパークラスのドキュメントを参照してください。 #### __call__[[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` として画像の潜在変数(latents)を直接渡すことも可能で、その場合は再度エンコードされません。 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`、*optional*、デフォルトは 512) : 生成される画像の幅(ピクセル単位)。 num_inference_steps (`int`、*optional*、デフォルト値は 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 ジェネレーター](https://pytorch.org/docs/stable/generated/torch.Generator.html) 1 つまたはそのリスト。 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`、*optional*、デフォルトは 1) : `callback` 関数が呼び出される頻度です。指定しない場合、callback はすべてのステップで呼び出されます。 return_dict (`bool`、*任意*、デフォルトは`True`) : プレーンなタプルではなく、[ImagePipelineOutput](/docs/diffusers/main/ja/api/pipelines/consistency_models#diffusers.ImagePipelineOutput)を返すかどうか。 **戻り値:** [ImagePipelineOutput](/docs/diffusers/main/ja/api/pipelines/consistency_models#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/ja/api/schedulers/ddim#diffusers.DDIMScheduler)) : `unet`と組み合わせて使用し、画像の潜在変数を生成するためのスケジューラ。 unet ([UNet2DConditionModel](/docs/diffusers/main/ja/api/models/unet2d-cond#diffusers.UNet2DConditionModel)) : 画像埋め込みのノイズ除去を行う条件付き U-Net アーキテクチャ。 movq ([VQModel](/docs/diffusers/main/ja/api/models/vq#diffusers.VQModel)) : 潜在変数から画像を生成するための MoVQ デコーダー。 Kandinsky2.1 を用いたテキストガイド型画像インペインティングのパイプライン このモデルは [DiffusionPipeline](/docs/diffusers/main/ja/api/pipelines/overview#diffusers.DiffusionPipeline) を継承しています。ライブラリがすべてのパイプラインに対して実装している汎用的なメソッド(ダウンロードや保存、特定のデバイスでの実行など)については、スーパークラスのドキュメントを参照してください。 #### __call__[[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`、またはインペイント対象の画像バッチを表すテンソル。*つまり*、画像の一部が`mask_image`でマスクされ、`prompt`に従って再描画されます。 mask_image (`np.array`) : `image` をマスクするための、画像バッチを表す Tensor。マスク内の白いピクセルは再描画され、黒いピクセルは保持されます。`mask_image` が PIL 画像の場合、使用の前に単一チャネル(輝度)に変換されます。テンソルの場合は、3 つのチャネルではなく 1 つの色チャネル(L)を含む必要があるため、期待される形状は `(B, H, W, 1)` になります。 negative_image_embeds (`torch.Tensor` または `list[torch.Tensor]`) : 負のテキストプロンプトに対するクリップ画像埋め込み。画像生成の条件付けに使用されます。 height (`int`、*任意*、デフォルト値は 512) : 生成される画像のピクセル単位の縦幅。 width (`int`、*optional*、デフォルトは 512) : 生成される画像の幅(ピクセル単位)。 num_inference_steps (`int`、*optional*、デフォルト値は 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 ジェネレーター](https://pytorch.org/docs/stable/generated/torch.Generator.html) 1 つまたはそのリスト。 latents (`torch.Tensor`, *任意*) : イメージ生成の入力として使用される、ガウス分布からサンプリングされた事前生成されたノイジー・ラテンツ。異なるプロンプトで同じ生成を調整するために使用できます。指定されない場合、指定されたランダムな`generator`を使用してサンプリングを行い、ラテンツのテンソルが生成されます。 output_type (`str`、*任意*、デフォルトは `"pil"`) : 生成画像の出力形式。以下のいずれかを選択します: `"pil"` (`PIL.Image.Image`)、`"np"` (`np.array`)、または `"pt"` (`torch.Tensor`)。 return_dict (`bool`、*任意*、デフォルトは`True`) : プレーンなタプルではなく、[ImagePipelineOutput](/docs/diffusers/main/ja/api/pipelines/consistency_models#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/ja/api/pipelines/consistency_models#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` と組み合わせて使用し、画像の潜在変数を生成するためのスケジューラ。 unet ([UNet2DConditionModel](/docs/diffusers/main/ja/api/models/unet2d-cond#diffusers.UNet2DConditionModel)) : 画像埋め込みのノイズ除去を行う条件付き U-Net アーキテクチャ。 movq ([VQModel](/docs/diffusers/main/ja/api/models/vq#diffusers.VQModel)) : 潜在変数から画像を生成するための MoVQ デコーダー。 prior_prior ([PriorTransformer](/docs/diffusers/main/ja/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) の Tokenizer。 prior_scheduler (`UnCLIPScheduler`) : `prior` と組み合わせて使用し、画像埋め込みを生成するためのスケジューラ。 prior_image_processor (`CLIPImageProcessor`) : clip の画像を前処理するために使用される image_processor。 Kandinsky を用いたインペインティング生成のための統合パイプライン このモデルは [DiffusionPipeline](/docs/diffusers/main/ja/api/pipelines/overview#diffusers.DiffusionPipeline) を継承しています。ライブラリがすべてのパイプラインに対して実装している汎用的なメソッド(ダウンロードや保存、特定のデバイスでの実行など)については、スーパークラスのドキュメントを参照してください。 #### __call__[[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` として画像の潜在変数(latents)を直接渡すことも可能で、その場合は再度エンコードされません。 mask_image (`np.array`) : `image` をマスクするための、画像バッチを表す Tensor。マスク内の白いピクセルは再描画され、黒いピクセルは保持されます。`mask_image` が PIL 画像の場合、使用の前に単一チャネル(輝度)に変換されます。テンソルの場合は、3 つのチャネルではなく 1 つの色チャネル(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`、*optional*、デフォルト値は 100) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。 height (`int`、*任意*、デフォルト値は 512) : 生成される画像のピクセル単位の縦幅。 width (`int`、*optional*、デフォルトは 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`、*optional*、デフォルト値は 100) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。 generator (`torch.Generator` または `list[torch.Generator]`、*任意*) : 生成を決定論的にするための [torch ジェネレーター](https://pytorch.org/docs/stable/generated/torch.Generator.html) 1 つまたはそのリスト。 latents (`torch.Tensor`, *任意*) : イメージ生成の入力として使用される、ガウス分布からサンプリングされた事前生成されたノイジー・ラテンツ。異なるプロンプトで同じ生成を調整するために使用できます。指定されない場合、指定されたランダムな`generator`を使用してサンプリングを行い、ラテンツのテンソルが生成されます。 output_type (`str`、*任意*、デフォルトは `"pil"`) : 生成画像の出力形式。以下のいずれかを選択します: `"pil"` (`PIL.Image.Image`)、`"np"` (`np.array`)、または `"pt"` (`torch.Tensor`)。 return_dict (`bool`、*任意*、デフォルトは`True`) : プレーンなタプルではなく、[ImagePipelineOutput](/docs/diffusers/main/ja/api/pipelines/consistency_models#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/ja/api/pipelines/consistency_models#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 は、より強力な新しい画像エンコーダーである CLIP-ViT-G と ControlNet のサポートを導入することで、先行バージョンである Kandinsky 2.1 に対して大幅な改善をもたらしました。画像エンコーダーを 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/ja/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) の Tokenizer。
scheduler (`UnCLIPScheduler`) : `prior` と組み合わせて使用し、画像埋め込みを生成するためのスケジューラ。
image_processor (`CLIPImageProcessor`) : clip の画像を前処理するために使用される image_processor。
Kandinsky用の画像事前分布を生成するためのPipeline
このモデルは [DiffusionPipeline](/docs/diffusers/main/ja/api/pipelines/overview#diffusers.DiffusionPipeline) を継承しています。ライブラリがすべてのパイプラインに対して実装している汎用的なメソッド(ダウンロードや保存、特定のデバイスでの実行など)については、スーパークラスのドキュメントを参照してください。
#### __call__[[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`、*optional*、デフォルト値は 100) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。
generator (`torch.Generator` または `list[torch.Generator]`、*任意*) : 生成を決定論的にするための [torch ジェネレーター](https://pytorch.org/docs/stable/generated/torch.Generator.html) 1 つまたはそのリスト。
latents (`torch.Tensor`, *任意*) : イメージ生成の入力として使用される、ガウス分布からサンプリングされた事前生成されたノイジー・ラテンツ。異なるプロンプトで同じ生成を調整するために使用できます。指定されない場合、指定されたランダムな`generator`を使用してサンプリングを行い、ラテンツのテンソルが生成されます。
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/ja/api/pipelines/consistency_models#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:
93.9 kB
·
Xet hash:
ef7af8a467a95904994594ef273ee69af98fb5dad38eaebf0f3c86d805959c89

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.