Buckets:
| # Stable Cascade | |
| このモデルは[Würstchen](https://openreview.net/forum?id=gU58d5QeGv)アーキテクチャを基盤として構築されており、Stable Diffusionなどの他のモデルとの主な違いは、はるかに小さい潜在空間で動作することです。なぜこれが重要なのでしょうか。潜在空間が小さいほど、推論は**高速**になり、トレーニングのコストは**安価**になります。潜在空間はどの程度小さいのでしょうか。Stable Diffusionは圧縮率8を使用しており、1024x1024の画像は128x128にエンコードされます。Stable Cascadeは圧縮率42を実現しており、シャープな再構成を維持しながら、1024x1024の画像を24x24にエンコードすることが可能です。その後、テキスト条件付きモデルは、この高圧縮された潜在空間内でトレーニングされます。このアーキテクチャの以前のバージョンでは、Stable Diffusion 1.5と比較して16倍のコスト削減を達成しました。 | |
| したがって、この種のモデルは、効率性が重要な用途に適しています。さらに、ファインチューニング、LoRA、ControlNet、IP-Adapter、LCMなどの既知の拡張機能も、この手法ではすべて可能です。 | |
| 元のコードベースは[Stability-AI/StableCascade](https://github.com/Stability-AI/StableCascade)で確認できます。 | |
| ## モデル概要 | |
| Stable Cascadeは、Stage A、Stage B、Stage Cの3つのモデルで構成されています。これらは画像生成のためのカスケードを形成しており、そのため「Stable Cascade」という名称が付けられています。 | |
| Stage A & B は、Stable Diffusion における VAE の役割と同様に、画像の圧縮に使用されます。ただし、この構成により、はるかに高い圧縮率の画像エンコーディングを実現できます。Stable Diffusion モデルは空間圧縮係数が 8 であり、1024 x 1024 の解像度の画像を 128 x 128 にエンコードするのに対し、Stable Cascade は圧縮係数 42 を達成します。これにより、1024 x 1024 の画像を 24 x 24 にエンコードしながら、画像を正確にデコードすることが可能です。これにより、トレーニングと推論のコストが安くなるという大きな利点があります。さらに、Stage C は、テキストプロンプトが与えられた際に、小さな 24 x 24 の潜在変数(latents)を生成する役割を担います。 | |
| Stage C モデルは、小さな 24 x 24 の潜在変数 (latents) を処理し、テキストプロンプトを条件として潜在変数のノイズ除去を行います。このモデルは Cascade パイプラインの中で最も大きなコンポーネントであり、`StableCascadePriorPipeline` と組み合わせて使用することを想定しています。 | |
| Stage B と Stage A のモデルは `StableCascadeDecoderPipeline` と組み合わせて使用され、小さな 24 x 24 の潜在変数から最終的な画像を生成する役割を担います。 | |
| > [!WARNING] | |
| > Stable Cascade モデルで使用できるデータ型にはいくつかの制限があります。`StableCascadePriorPipeline` の公式チェックポイントは `torch.float16` データ型をサポートしていません。代わりに `torch.bfloat16` を使用してください。 | |
| > | |
| > `StableCascadeDecoderPipeline` で `torch.bfloat16` データ型を使用するには、PyTorch 2.2.0 以降のインストールが必要です。`StableCascadeCombinedPipeline` は内部で `StableCascadeDecoderPipeline` を呼び出すため、`StableCascadeCombinedPipeline` で `torch.bfloat16` を使用する場合も、PyTorch 2.2.0 以降が必要です。 | |
| > | |
| > お使いの環境で PyTorch 2.2.0 以上をインストールできない場合、`StableCascadeDecoderPipeline` は `torch.float16` データ型を単独で使用できます。パイプライン用のフルプレシジョンまたは `bf16` 版の重みをダウンロードし、重みを `torch.float16` にキャストしてください。 | |
| ## 使用例 | |
| ```python | |
| import torch | |
| from diffusers import StableCascadeDecoderPipeline, StableCascadePriorPipeline | |
| prompt = "an image of a shiba inu, donning a spacesuit and helmet" | |
| negative_prompt = "" | |
| prior = StableCascadePriorPipeline.from_pretrained("stabilityai/stable-cascade-prior", variant="bf16", dtype=torch.bfloat16) | |
| decoder = StableCascadeDecoderPipeline.from_pretrained("stabilityai/stable-cascade", variant="bf16", dtype=torch.float16) | |
| prior.enable_model_cpu_offload() | |
| prior_output = prior( | |
| prompt=prompt, | |
| height=1024, | |
| width=1024, | |
| negative_prompt=negative_prompt, | |
| guidance_scale=4.0, | |
| num_images_per_prompt=1, | |
| num_inference_steps=20 | |
| ) | |
| decoder.enable_model_cpu_offload() | |
| decoder_output = decoder( | |
| image_embeddings=prior_output.image_embeddings.to(torch.float16), | |
| prompt=prompt, | |
| negative_prompt=negative_prompt, | |
| guidance_scale=0.0, | |
| output_type="pil", | |
| num_inference_steps=10 | |
| ).images[0] | |
| decoder_output.save("cascade.png") | |
| ``` | |
| ## ステージBおよびステージCモデルのLiteバージョンを使用する | |
| ```python | |
| import torch | |
| from diffusers import ( | |
| StableCascadeDecoderPipeline, | |
| StableCascadePriorPipeline, | |
| StableCascadeUNet, | |
| ) | |
| prompt = "an image of a shiba inu, donning a spacesuit and helmet" | |
| negative_prompt = "" | |
| prior_unet = StableCascadeUNet.from_pretrained("stabilityai/stable-cascade-prior", subfolder="prior_lite") | |
| decoder_unet = StableCascadeUNet.from_pretrained("stabilityai/stable-cascade", subfolder="decoder_lite") | |
| prior = StableCascadePriorPipeline.from_pretrained("stabilityai/stable-cascade-prior", prior=prior_unet) | |
| decoder = StableCascadeDecoderPipeline.from_pretrained("stabilityai/stable-cascade", decoder=decoder_unet) | |
| prior.enable_model_cpu_offload() | |
| prior_output = prior( | |
| prompt=prompt, | |
| height=1024, | |
| width=1024, | |
| negative_prompt=negative_prompt, | |
| guidance_scale=4.0, | |
| num_images_per_prompt=1, | |
| num_inference_steps=20 | |
| ) | |
| decoder.enable_model_cpu_offload() | |
| decoder_output = decoder( | |
| image_embeddings=prior_output.image_embeddings, | |
| prompt=prompt, | |
| negative_prompt=negative_prompt, | |
| guidance_scale=0.0, | |
| output_type="pil", | |
| num_inference_steps=10 | |
| ).images[0] | |
| decoder_output.save("cascade.png") | |
| ``` | |
| ## `from_single_file`で元のチェックポイントをロードする | |
| `from_single_file` メソッドを通じて、StableCascadeUNet でのオリジナル形式のチェックポイントの読み込みがサポートされています。 | |
| ```python | |
| import torch | |
| from diffusers import ( | |
| StableCascadeDecoderPipeline, | |
| StableCascadePriorPipeline, | |
| StableCascadeUNet, | |
| ) | |
| prompt = "an image of a shiba inu, donning a spacesuit and helmet" | |
| negative_prompt = "" | |
| prior_unet = StableCascadeUNet.from_single_file( | |
| "https://huggingface.co/stabilityai/stable-cascade/resolve/main/stage_c_bf16.safetensors", | |
| dtype=torch.bfloat16 | |
| ) | |
| decoder_unet = StableCascadeUNet.from_single_file( | |
| "https://huggingface.co/stabilityai/stable-cascade/blob/main/stage_b_bf16.safetensors", | |
| dtype=torch.bfloat16 | |
| ) | |
| prior = StableCascadePriorPipeline.from_pretrained("stabilityai/stable-cascade-prior", prior=prior_unet, dtype=torch.bfloat16) | |
| decoder = StableCascadeDecoderPipeline.from_pretrained("stabilityai/stable-cascade", decoder=decoder_unet, dtype=torch.bfloat16) | |
| prior.enable_model_cpu_offload() | |
| prior_output = prior( | |
| prompt=prompt, | |
| height=1024, | |
| width=1024, | |
| negative_prompt=negative_prompt, | |
| guidance_scale=4.0, | |
| num_images_per_prompt=1, | |
| num_inference_steps=20 | |
| ) | |
| decoder.enable_model_cpu_offload() | |
| decoder_output = decoder( | |
| image_embeddings=prior_output.image_embeddings, | |
| prompt=prompt, | |
| negative_prompt=negative_prompt, | |
| guidance_scale=0.0, | |
| output_type="pil", | |
| num_inference_steps=10 | |
| ).images[0] | |
| decoder_output.save("cascade-single-file.png") | |
| ``` | |
| ## 用途 | |
| ### 直接利用 | |
| このモデルは、現時点では研究目的での利用を想定しています。研究対象となり得る分野やタスクには、以下が含まれます | |
| - 生成モデルに関する研究。 | |
| - 有害なコンテンツを生成する可能性のあるモデルの安全なデプロイ。 | |
| - 生成モデルの限界やバイアスを探査し、理解すること。 | |
| - アート作品の生成、およびデザインやその他の芸術的プロセスにおける利用。 | |
| - 教育ツールやクリエイティブツールへの応用。 | |
| 除外対象の用途については、以下に説明します。 | |
| ### 範囲外の使用 | |
| このモデルは、人物や事象の事実的かつ真実的な表現として学習されておらず、そのため、このモデルを使用してそのようなコンテンツを生成することは、このモデルの能力の範囲外です。このモデルは、Stability AIの[適正利用ポリシー](https://stability.ai/use-policy)に違反するいかなる方法でも使用しないでください。 | |
| ## 制約とバイアス | |
| ### 制約事項 | |
| - 顔や人物が正しく生成されない場合があります。 | |
| - モデルのオートエンコーディング部分は、損失を伴います。 | |
| ## StableCascadeCombinedPipeline[[diffusers.StableCascadeCombinedPipeline]] | |
| #### diffusers.StableCascadeCombinedPipeline[[diffusers.StableCascadeCombinedPipeline]] | |
| ```python | |
| diffusers.StableCascadeCombinedPipeline(tokenizer: CLIPTokenizer, text_encoder: CLIPTextModelWithProjection, decoder: StableCascadeUNet, scheduler: DDPMWuerstchenScheduler, vqgan: PaellaVQModel, prior_prior: StableCascadeUNet, prior_text_encoder: CLIPTextModelWithProjection, prior_tokenizer: CLIPTokenizer, prior_scheduler: DDPMWuerstchenScheduler, prior_feature_extractor: transformers.models.clip.image_processing_pil_clip.CLIPImageProcessorPil | None = None, prior_image_encoder: transformers.models.clip.modeling_clip.CLIPVisionModelWithProjection | None = None) | |
| ``` | |
| [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_cascade/pipeline_stable_cascade_combined.py#L46) | |
| **パラメータ:** | |
| tokenizer (`CLIPTokenizer`) : テキスト入力に使用するデコーダのトークナイザ。 | |
| text_encoder (`CLIPTextModelWithProjection`) : テキスト入力に使用されるデコーダーテキストエンコーダー。 | |
| decoder (`StableCascadeUNet`) : デコーダー画像生成パイプラインで使用されるデコーダーモデル。 | |
| scheduler (`DDPMWuerstchenScheduler`) : デコーダー画像生成パイプラインで使用するスケジューラー。 | |
| vqgan (`PaellaVQModel`) : デコーダー画像生成パイプラインで使用する VQGAN モデル。 | |
| prior_prior (`StableCascadeUNet`) : prior パイプラインで使用される事前モデル。 | |
| prior_text_encoder (`CLIPTextModelWithProjection`) : テキスト入力に使用される先行テキストエンコーダー。 | |
| prior_tokenizer (`CLIPTokenizer`) : テキスト入力に使用される従来のトークナイザー。 | |
| prior_scheduler (`DDPMWuerstchenScheduler`) : 事前パイプラインで使用するスケジューラー。 | |
| prior_feature_extractor ([CLIPImageProcessor](https://huggingface.co/docs/transformers/main/en/model_doc/clip#transformers.CLIPImageProcessor)) : 生成された画像から特徴を抽出し、`image_encoder` の入力として使用するモデル。 | |
| prior_image_encoder (`CLIPVisionModelWithProjection`) : 凍結された CLIP 画像エンコーダー ([clip-vit-large-patch14](https://huggingface.co/openai/clip-vit-large-patch14))。 | |
| Stable Cascade を使用したテキストから画像への生成を行う統合 Pipeline。 | |
| このモデルは [DiffusionPipeline](/docs/diffusers/main/ja/api/pipelines/overview#diffusers.DiffusionPipeline) を継承しています。ライブラリがすべてのパイプラインに対して実装している汎用的なメソッド(ダウンロードや保存、特定のデバイスでの実行など)については、スーパークラスのドキュメントを参照してください。 | |
| #### __call__[[diffusers.StableCascadeCombinedPipeline.__call__]] | |
| ```python | |
| __call__(prompt: str | list[str] | None = None, images: typing.Union[torch.Tensor, list[torch.Tensor], PIL.Image.Image, list[PIL.Image.Image]] = None, height: int = 512, width: int = 512, prior_num_inference_steps: int = 60, prior_guidance_scale: float = 4.0, num_inference_steps: int = 12, decoder_guidance_scale: float = 0.0, negative_prompt: str | list[str] | None = None, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_embeds_pooled: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds_pooled: typing.Optional[torch.Tensor] = None, 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, 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/stable_cascade/pipeline_stable_cascade_combined.py#L159) | |
| **パラメータ:** | |
| prompt (`str` または `list[str]`) : prior と decoder の画像生成をガイドするためのプロンプト、またはプロンプトのリスト。 | |
| images (`torch.Tensor`、`PIL.Image.Image`、`list[torch.Tensor]`、`list[PIL.Image.Image]`、*任意*) : prior の画像生成をガイドするための画像です。 | |
| negative_prompt (`str` または `list[str]`、*省略可能*) : 画像生成をガイドしないプロンプト、またはプロンプトのリスト。`guidance_scale` が `1` 未満の場合、無視されます(ガイドを使用していない場合、無視されます)。 | |
| prompt_embeds (`torch.Tensor`, *任意*) : 事前のテキスト埋め込み。テキスト入力を簡単に調整するために使用できます。*例えば*、プロンプトの重み付けなどです。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。 | |
| prompt_embeds_pooled (`torch.Tensor`, *任意*) : 事前のテキスト埋め込み。テキスト入力を簡単に調整するために使用できます。*例えば*、プロンプトの重み付けなどです。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。 | |
| negative_prompt_embeds (`torch.Tensor`, *任意*) : 事前分布用の事前生成されたネガティブテキスト埋め込み。プロンプトの重み付けなど、*例えば*テキスト入力の調整を容易に行うために使用できます。指定されない場合、`negative_prompt` 入力引数から negative_prompt_embeds が生成されます。 | |
| negative_prompt_embeds_pooled (`torch.Tensor`, *任意*) : 事前分布用の事前生成されたネガティブテキスト埋め込み。プロンプトの重み付けなど、*例えば*テキスト入力の調整を容易に行うために使用できます。指定されない場合、`negative_prompt` 入力引数から negative_prompt_embeds が生成されます。 | |
| num_images_per_prompt (`int`、*任意*、デフォルトは 1) : プロンプトごとに生成する画像の数。 | |
| height (`int`、*任意*、デフォルト値は 512) : 生成される画像のピクセル単位の縦幅。 | |
| width (`int`、*optional*、デフォルトは 512) : 生成される画像の幅(ピクセル単位)。 | |
| prior_guidance_scale (`float`、*任意*、デフォルト値は 4.0) : [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598)で定義されているガイダンススケールです。`prior_guidance_scale` は、[Imagen Paper](https://huggingface.co/papers/2205.11487)の式 2 の `w` として定義されています。`prior_guidance_scale > 1` を設定することで、ガイダンススケールが有効になります。ガイダンススケールを高くすると、`prompt` のテキストと密接に関連する画像の生成が促されますが、通常は画像の品質が低下する傾向があります。 | |
| prior_num_inference_steps (`int | dict[float, int]`, *任意*、デフォルトは 60) : 事前のデノイジングステップ数。デノイジングステップ数を増やすと、推論速度が遅くなる代わりに、通常、より高品質な画像が得られます。より具体的なタイムステップの間隔を指定するには、カスタマイズした `prior_timesteps` を渡すことができます。 | |
| num_inference_steps (`int`、*任意*、デフォルト値は 12) : デコーダーのデノイジングステップ数です。デノイジングステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。より具体的なタイムステップの間隔を指定するには、カスタマイズした`timesteps`を渡すことができます。 | |
| decoder_guidance_scale (`float`、*任意*、デフォルト値は 0.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`)。 | |
| 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` 属性に列挙された変数のみを、リストに含めることができます。 | |
| **戻り値:** | |
| `return_dict` が True の場合は [ImagePipelineOutput](/docs/diffusers/main/ja/api/pipelines/consistency_models#diffusers.ImagePipelineOutput) または `tuple` [ImagePipelineOutput](/docs/diffusers/main/ja/api/pipelines/consistency_models#diffusers.ImagePipelineOutput)、それ以外の場合は `tuple` を返します。タプルを返す場合、最初の要素は生成された画像のリストです。 | |
| 生成用のパイプラインを呼び出したときに実行される関数。 | |
| 例: | |
| ```py | |
| >>> import torch | |
| >>> from diffusers import StableCascadeCombinedPipeline | |
| >>> pipe = StableCascadeCombinedPipeline.from_pretrained( | |
| ... "stabilityai/stable-cascade", variant="bf16", torch_dtype=torch.bfloat16 | |
| ... ) | |
| >>> pipe.enable_model_cpu_offload() | |
| >>> prompt = "an image of a shiba inu, donning a spacesuit and helmet" | |
| >>> images = pipe(prompt=prompt) | |
| ``` | |
| #### enable_model_cpu_offload[[diffusers.StableCascadeCombinedPipeline.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/stable_cascade/pipeline_stable_cascade_combined.py#L131) | |
| accelerate を使用してすべてのモデルを CPU にオフロードし、パフォーマンスへの影響を抑えながらメモリ使用量を削減します。`enable_sequential_cpu_offload` と比較すると、このメソッドは `forward` メソッドが呼び出されたときに、一度に 1 つのモデル全体を GPU に移動し、次のモデルが実行されるまでそのモデルは GPU に保持されます。`enable_sequential_cpu_offload` を使用する場合よりもメモリ削減効果は低くなりますが、`unet` の反復的な実行により、パフォーマンスは大幅に向上します。 | |
| #### enable_sequential_cpu_offload[[diffusers.StableCascadeCombinedPipeline.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/stable_cascade/pipeline_stable_cascade_combined.py#L141) | |
| 🤗 Accelerate を使用して、すべてのモデル(`unet`、`text_encoder`、`vae`、および `safety checker` の state dict)を CPU にオフロードし、メモリ使用量を大幅に削減します。モデルは `torch.device('meta')` に移動され、特定のサブモジュールの `forward` メソッドが呼び出されたときにのみ GPU にロードされます。オフロードはサブモジュール単位で行われます。`enable_model_cpu_offload` を使用する場合よりもメモリ削減効果は高いですが、パフォーマンスは低くなります。 | |
| ## StableCascadePriorPipeline[[diffusers.StableCascadePriorPipeline]] | |
| #### diffusers.StableCascadePriorPipeline[[diffusers.StableCascadePriorPipeline]] | |
| ```python | |
| diffusers.StableCascadePriorPipeline(tokenizer: CLIPTokenizer, text_encoder: CLIPTextModelWithProjection, prior: StableCascadeUNet, scheduler: DDPMWuerstchenScheduler, resolution_multiple: float = 42.67, feature_extractor: transformers.models.clip.image_processing_pil_clip.CLIPImageProcessorPil | None = None, image_encoder: transformers.models.clip.modeling_clip.CLIPVisionModelWithProjection | None = None) | |
| ``` | |
| [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_cascade/pipeline_stable_cascade_prior.py#L80) | |
| **パラメータ:** | |
| prior (`StableCascadeUNet`) : テキストおよび/または画像の埋め込みから、画像の埋め込みを近似する Stable Cascade の事前モデルです。 | |
| text_encoder (`CLIPTextModelWithProjection`) : 凍結されたテキストエンコーダー ([laion/CLIP-ViT-bigG-14-laion2B-39B-b160k](https://huggingface.co/laion/CLIP-ViT-bigG-14-laion2B-39B-b160k))。 | |
| feature_extractor ([CLIPImageProcessor](https://huggingface.co/docs/transformers/main/en/model_doc/clip#transformers.CLIPImageProcessor)) : 生成された画像から特徴を抽出し、`image_encoder` の入力として使用するモデル。 | |
| image_encoder (`CLIPVisionModelWithProjection`) : 凍結された CLIP 画像エンコーダー ([clip-vit-large-patch14](https://huggingface.co/openai/clip-vit-large-patch14))。 | |
| tokenizer (`CLIPTokenizer`) : クラス [CLIPTokenizer](https://huggingface.co/docs/transformers/v4.21.0/en/model_doc/clip#transformers.CLIPTokenizer) の Tokenizer。 | |
| scheduler (`DDPMWuerstchenScheduler`) : `prior` と組み合わせて画像埋め込みを生成するために使用するスケジューラー。 | |
| resolution_multiple ('float', *任意*、デフォルト値は 42.67) : 複数画像を生成する際のデフォルトの解像度。 | |
| Stable Cascade用のイメージ・プライヤーを生成するためのPipeline。 | |
| このモデルは [DiffusionPipeline](/docs/diffusers/main/ja/api/pipelines/overview#diffusers.DiffusionPipeline) を継承しています。ライブラリがすべてのパイプラインに対して実装している汎用的なメソッド(ダウンロードや保存、特定のデバイスでの実行など)については、スーパークラスのドキュメントを参照してください。 | |
| #### __call__[[diffusers.StableCascadePriorPipeline.__call__]] | |
| ```python | |
| __call__(prompt: str | list[str] | None = None, images: typing.Union[torch.Tensor, list[torch.Tensor], PIL.Image.Image, list[PIL.Image.Image]] = None, height: int = 1024, width: int = 1024, num_inference_steps: int = 20, timesteps: list[float] = None, guidance_scale: float = 4.0, negative_prompt: str | list[str] | None = None, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_embeds_pooled: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds_pooled: typing.Optional[torch.Tensor] = None, image_embeds: typing.Optional[torch.Tensor] = None, num_images_per_prompt: int | None = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, 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/stable_cascade/pipeline_stable_cascade_prior.py#L375) | |
| **パラメータ:** | |
| prompt (`str` または `list[str]`) : 画像生成をガイドするためのプロンプト、またはプロンプトのリスト。 | |
| images (`torch.Tensor`、`PIL.Image.Image`、`list[torch.Tensor]` または `list[PIL.Image.Image]`、*任意*) : 事前生成を条件付けするために使用される参照画像です。指定された場合、画像から画像埋め込みが導出され、テキストプロンプトと結合されます。 | |
| height (`int`、*optional*、デフォルト値は 1024) : 生成される画像のピクセル単位の縦幅。 | |
| width (`int`、*任意*、デフォルトは 1024) : 生成される画像の幅(ピクセル単位)。 | |
| num_inference_steps (`int`、*optional*、デフォルトは 60) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。 | |
| timesteps (`list[float]`, *任意*) : `set_timesteps` メソッドで `timesteps` 引数をサポートするスケジューラーにおいて、デノイジングプロセスに使用するカスタムタイムステップ。未定義の場合、`num_inference_steps` が渡された際のデフォルトの動作が使用されます。降順で指定する必要があります。 | |
| guidance_scale (`float`、*任意*、デフォルト値は 8.0) : [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598) で定義されているガイダンススケールです。`decoder_guidance_scale` は、[Imagen Paper](https://huggingface.co/papers/2205.11487) の数式 2 の `w` として定義されています。`decoder_guidance_scale > 1` を設定することで、ガイダンススケールが有効になります。ガイダンススケールを高くすると、`prompt` のテキストと密接に関連する画像の生成が促されますが、通常は画像の品質が低下する傾向があります。 | |
| negative_prompt (`str` または `list[str]`、*省略可能*) : 画像生成をガイドしないプロンプト、またはプロンプトのリスト。`decoder_guidance_scale` が `1` 未満の場合(つまり、ガイダンスを使用していない場合)は無視されます。 | |
| prompt_embeds (`torch.Tensor`, *任意*) : 事前生成されたテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。 | |
| prompt_embeds_pooled (`torch.Tensor`, *任意*) : 事前に生成されたプーリング済みテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`prompt` 入力引数からプーリング済みテキスト埋め込みが生成されます。 | |
| negative_prompt_embeds (`torch.Tensor`, *任意*) : 事前に生成されたネガティブなテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`negative_prompt` 入力引数から negative_prompt_embeds が生成されます。 | |
| negative_prompt_embeds_pooled (`torch.Tensor`, *任意*) : 事前に生成されたネガティブなプーリング済みテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`negative_prompt` 入力引数から negative_prompt_embeds_pooled が生成されます。 | |
| image_embeds (`torch.Tensor`, *任意*) : 事前に生成された画像エンベディング。画像入力の調整、*例えば*プロンプトの重み付けなどを簡単に実行できます。指定されない場合、`image` 引数が存在する場合は、そこから画像エンベディングが生成されます。 | |
| 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` 属性に列挙された変数のみを、リストに含めることができます。 | |
| **戻り値:** | |
| `StableCascadePriorPipelineOutput` または `tuple`。 `return_dict` が True の場合は `StableCascadePriorPipelineOutput`、それ以外の場合は `tuple` が返されます。タプルを返す場合、最初の要素は生成された画像の埋め込みのリストです。 | |
| 生成用のパイプラインを呼び出したときに実行される関数。 | |
| 例: | |
| ```py | |
| >>> import torch | |
| >>> from diffusers import StableCascadePriorPipeline | |
| >>> prior_pipe = StableCascadePriorPipeline.from_pretrained( | |
| ... "stabilityai/stable-cascade-prior", torch_dtype=torch.bfloat16 | |
| ... ).to("cuda") | |
| >>> prompt = "an image of a shiba inu, donning a spacesuit and helmet" | |
| >>> prior_output = pipe(prompt) | |
| ``` | |
| ## StableCascadePriorPipelineOutput[[diffusers.pipelines.stable_cascade.pipeline_stable_cascade_prior.StableCascadePriorPipelineOutput]] | |
| #### diffusers.pipelines.stable_cascade.pipeline_stable_cascade_prior.StableCascadePriorPipelineOutput[[diffusers.pipelines.stable_cascade.pipeline_stable_cascade_prior.StableCascadePriorPipelineOutput]] | |
| ```python | |
| diffusers.pipelines.stable_cascade.pipeline_stable_cascade_prior.StableCascadePriorPipelineOutput(image_embeddings: typing.Union[torch.Tensor, numpy.ndarray], prompt_embeds: typing.Union[torch.Tensor, numpy.ndarray], prompt_embeds_pooled: typing.Union[torch.Tensor, numpy.ndarray], negative_prompt_embeds: typing.Union[torch.Tensor, numpy.ndarray], negative_prompt_embeds_pooled: typing.Union[torch.Tensor, numpy.ndarray]) | |
| ``` | |
| [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_cascade/pipeline_stable_cascade_prior.py#L60) | |
| **パラメータ:** | |
| image_embeddings (`torch.Tensor` または `np.ndarray`) : テキストプロンプト用の事前画像埋め込み | |
| prompt_embeds (`torch.Tensor`) : プロンプトのテキスト埋め込み。 | |
| negative_prompt_embeds (`torch.Tensor`) : 負のプロンプトのテキスト埋め込み。 | |
| WuerstchenPriorPipelineの出力クラスです。 | |
| ## StableCascadeDecoderPipeline[[diffusers.StableCascadeDecoderPipeline]] | |
| #### diffusers.StableCascadeDecoderPipeline[[diffusers.StableCascadeDecoderPipeline]] | |
| ```python | |
| diffusers.StableCascadeDecoderPipeline(decoder: StableCascadeUNet, tokenizer: CLIPTokenizer, text_encoder: CLIPTextModelWithProjection, scheduler: DDPMWuerstchenScheduler, vqgan: PaellaVQModel, latent_dim_scale: float = 10.67) | |
| ``` | |
| [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_cascade/pipeline_stable_cascade.py#L60) | |
| **パラメータ:** | |
| tokenizer (`CLIPTokenizer`) : CLIPのトークナイザー。 | |
| text_encoder (`CLIPTextModelWithProjection`) : CLIPのテキストエンコーダーです。 | |
| decoder (`StableCascadeUNet`) : Stable Cascade のデコーダー unet。 | |
| vqgan (`PaellaVQModel`) : VQGANモデルです。 | |
| scheduler (`DDPMWuerstchenScheduler`) : `prior` と組み合わせて画像埋め込みを生成するために使用するスケジューラー。 | |
| latent_dim_scale (float, `optional`, デフォルト値は 10.67) : 画像埋め込みから VQ 潜在空間のサイズを決定するための倍率です。画像埋め込みが height=24、width=24 の場合、トレーニング条件に一致させるために、VQ 潜在形状は height=int(24*10.67)=256、width=int(24*10.67)=256 である必要があります。 | |
| Stable Cascadeモデルから画像を生成するためのPipelineです。 | |
| このモデルは [DiffusionPipeline](/docs/diffusers/main/ja/api/pipelines/overview#diffusers.DiffusionPipeline) を継承しています。ライブラリがすべてのパイプラインに対して実装している汎用的なメソッド(ダウンロードや保存、特定のデバイスでの実行など)については、スーパークラスのドキュメントを参照してください。 | |
| #### __call__[[diffusers.StableCascadeDecoderPipeline.__call__]] | |
| ```python | |
| __call__(image_embeddings: typing.Union[torch.Tensor, list[torch.Tensor]], prompt: str | list[str] = None, num_inference_steps: int = 10, guidance_scale: float = 0.0, negative_prompt: str | list[str] | None = None, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_embeds_pooled: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds_pooled: typing.Optional[torch.Tensor] = None, 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']) | |
| ``` | |
| [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_cascade/pipeline_stable_cascade.py#L306) | |
| **パラメータ:** | |
| image_embeddings (`torch.Tensor` または `list[torch.Tensor]`) : 画像から抽出された、または Prior Model によって生成された Image Embeddings。 | |
| prompt (`str` または `list[str]`) : 画像生成をガイドするためのプロンプト、またはプロンプトのリスト。 | |
| num_inference_steps (`int`、*optional*、デフォルト値は 12) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。 | |
| guidance_scale (`float`、*任意*、デフォルト値は 0.0) : [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598)で定義されているガイダンススケールです。`decoder_guidance_scale` は、[Imagen Paper](https://huggingface.co/papers/2205.11487)の式 2 の `w` として定義されています。`decoder_guidance_scale > 1` を設定することで、ガイダンススケールが有効になります。ガイダンススケールを高くすると、`prompt` のテキストと密接に関連する画像の生成が促されますが、通常は画像の品質が低下する傾向があります。 | |
| negative_prompt (`str` または `list[str]`、*省略可能*) : 画像生成をガイドしないプロンプト、またはプロンプトのリスト。`decoder_guidance_scale` が `1` 未満の場合(つまり、ガイダンスを使用していない場合)は無視されます。 | |
| prompt_embeds (`torch.Tensor`, *任意*) : 事前生成されたテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。 | |
| prompt_embeds_pooled (`torch.Tensor`, *任意*) : 事前に生成されたプーリング済みテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`prompt` 入力引数からプーリング済みテキスト埋め込みが生成されます。 | |
| negative_prompt_embeds (`torch.Tensor`, *任意*) : 事前に生成されたネガティブなテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`negative_prompt` 入力引数から negative_prompt_embeds が生成されます。 | |
| negative_prompt_embeds_pooled (`torch.Tensor`, *任意*) : 事前に生成されたネガティブなプーリング済みテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`negative_prompt` 入力引数から negative_prompt_embeds_pooled が生成されます。 | |
| 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` 属性に列挙された変数のみを、リストに含めることができます。 | |
| **戻り値:** | |
| `return_dict` が True の場合は [ImagePipelineOutput](/docs/diffusers/main/ja/api/pipelines/consistency_models#diffusers.ImagePipelineOutput) または `tuple` [ImagePipelineOutput](/docs/diffusers/main/ja/api/pipelines/consistency_models#diffusers.ImagePipelineOutput)、それ以外の場合は `tuple` を返します。タプルを返す場合、最初の要素は生成された画像の埋め込みのリストです。 | |
| 生成用のパイプラインを呼び出したときに実行される関数。 | |
| 例: | |
| ```py | |
| >>> import torch | |
| >>> from diffusers import StableCascadePriorPipeline, StableCascadeDecoderPipeline | |
| >>> prior_pipe = StableCascadePriorPipeline.from_pretrained( | |
| ... "stabilityai/stable-cascade-prior", torch_dtype=torch.bfloat16 | |
| ... ).to("cuda") | |
| >>> gen_pipe = StableCascadeDecoderPipeline.from_pretrain( | |
| ... "stabilityai/stable-cascade", torch_dtype=torch.float16 | |
| ... ).to("cuda") | |
| >>> prompt = "an image of a shiba inu, donning a spacesuit and helmet" | |
| >>> prior_output = pipe(prompt) | |
| >>> images = gen_pipe(prior_output.image_embeddings, prompt=prompt) | |
| ``` | |
Xet Storage Details
- Size:
- 44.6 kB
- Xet hash:
- 83846ad4ed5b3f1eb6df0a021ebbd85f5c2daebdda9accf665d3c83d7d406f71
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.