Buckets:

mishig's picture
|
download
raw
120 kB
# # Apache License, Version 2.0(「ライセンス」)の下でライセンスされています。 # このファイルは、ライセンスに準拠した場合にのみ使用できます。 # ライセンスのコピーは以下から入手できます # # http://www.apache.org/licenses/LICENSE-2.0 # # 適用される法律で要求される場合、または書面による合意がある場合を除き、ソフトウェア # ライセンスに基づき配布される本ソフトウェアは、「現状のまま」 # 明示的または黙示的を問わず、いかなる種類の保証や条件も付随しません。 # 権限を管理する特定の言語については、ライセンスを参照してください。 # ライセンスの下での制限。--> # QwenImage QwenチームによるQwen-Imageは、Qwenシリーズの画像生成基盤モデルであり、複雑なテキストレンダリングと精密な画像編集において大きな進歩を遂げています。実験により、画像生成および編集の両方で優れた汎用性が示されており、特に中国語におけるテキストレンダリングで卓越したパフォーマンスを発揮しています。 Qwen-Imageには、以下のバリエーションがあります。 | モデルタイプ | モデルID | |:----------:|:--------:| | Qwen-Image | [`Qwen/Qwen-Image`](https://huggingface.co/Qwen/Qwen-Image) | | Qwen-Image-Edit | [`Qwen/Qwen-Image-Edit`](https://huggingface.co/Qwen/Qwen-Image-Edit) | | Qwen-Image-Edit Plus | [Qwen/Qwen-Image-Edit-2509](https://huggingface.co/Qwen/Qwen-Image-Edit-2509) | > [!TIP] > [Caching](../../optimization/cache)ガイドを参照し、中間出力を保存して再利用することで推論を高速化できます。 ## より高速な推論のためのLoRA `lightx2v/Qwen-Image-Lightning` の LoRA を使用して、ステップ数を減らし、推論を高速化します。以下のコードスニペットを参照してください。 コード ```py from diffusers import DiffusionPipeline, FlowMatchEulerDiscreteScheduler import torch import math ckpt_id = "Qwen/Qwen-Image" # From # https://github.com/ModelTC/Qwen-Image-Lightning/blob/342260e8f5468d2f24d084ce04f55e101007118b/generate_with_diffusers.py#L82C9-L97C10 scheduler_config = { "base_image_seq_len": 256, "base_shift": math.log(3), # We use shift=3 in distillation "invert_sigmas": False, "max_image_seq_len": 8192, "max_shift": math.log(3), # We use shift=3 in distillation "num_train_timesteps": 1000, "shift": 1.0, "shift_terminal": None, # set shift_terminal to None "stochastic_sampling": False, "time_shift_type": "exponential", "use_beta_sigmas": False, "use_dynamic_shifting": True, "use_exponential_sigmas": False, "use_karras_sigmas": False, } scheduler = FlowMatchEulerDiscreteScheduler.from_config(scheduler_config) pipe = DiffusionPipeline.from_pretrained( ckpt_id, scheduler=scheduler, dtype=torch.bfloat16 ).to("cuda") # or "mps", "xpu", "cpu" pipe.load_lora_weights( "lightx2v/Qwen-Image-Lightning", weight_name="Qwen-Image-Lightning-8steps-V1.0.safetensors" ) prompt = "a tiny astronaut hatching from an egg on the moon, Ultra HD, 4K, cinematic composition." negative_prompt = " " image = pipe( prompt=prompt, negative_prompt=negative_prompt, width=1024, height=1024, num_inference_steps=8, true_cfg_scale=1.0, generator=torch.manual_seed(0), ).images[0] image.save("qwen_fewsteps.png") ``` > [!TIP] > パイプラインの `guidance_scale` パラメータは、将来リリースされるガイダンス蒸留モデルをサポートするために用意されています。なお、パイプラインに `guidance_scale` を渡しても効果はありません。Classifier-free guidance を有効にするには、`true_cfg_scale` と `negative_prompt` を渡してください(" " のような空の negative prompt でも、classifier-free guidance の計算は有効になります)。 ## QwenImageEditPlusPipelineによる複数画像参照 [QwenImageEditPlusPipeline](/docs/diffusers/main/ja/api/pipelines/qwenimage#diffusers.QwenImageEditPlusPipeline)では、複数の画像を入力リファレンスとして指定できます。 ```py import torch from PIL import Image from diffusers import QwenImageEditPlusPipeline from diffusers.utils import load_image pipe = QwenImageEditPlusPipeline.from_pretrained( "Qwen/Qwen-Image-Edit-2509", dtype=torch.bfloat16 ).to("cuda") # or "mps", "xpu", "cpu" image_1 = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/grumpy.jpg") image_2 = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/peng.png") image = pipe( image=[image_1, image_2], prompt='''put the penguin and the cat at a game show called "Qwen Edit Plus Games"''', num_inference_steps=50 ).images[0] ``` ## パフォーマンス ### torch.compile transformer に `torch.compile` を適用すると、約 2.4 倍の高速化が得られます(A100 80GB: 4.70s → 1.93s): ```python import torch from diffusers import QwenImagePipeline pipe = QwenImagePipeline.from_pretrained("Qwen/Qwen-Image", dtype=torch.bfloat16).to("cuda") # or "mps", "xpu", "cpu" pipe.transformer = torch.compile(pipe.transformer) # First call triggers compilation (~7s overhead) # Subsequent calls run at ~2.4x faster image = pipe("a cat", num_inference_steps=50).images[0] ``` ### 可変長のプロンプトを用いたバッチ推論 プロンプトの長さが異なる場合にclassifier-free guidance (CFG)を使用すると、パイプラインはアテンションマスキングを通じてパディングを適切に処理します。これにより、パディングトークンが生成された出力に影響を与えないことが保証されます。 ```python # CFG with different prompt lengths works correctly image = pipe( prompt="A cat", negative_prompt="blurry, low quality, distorted", true_cfg_scale=3.5, num_inference_steps=50, ).images[0] ``` 詳細なベンチマークスクリプトと結果については、[この gist](https://gist.github.com/cdutr/bea337e4680268168550292d7819dc2f)を参照してください。 ## QwenImagePipeline[[diffusers.QwenImagePipeline]] #### diffusers.QwenImagePipeline[[diffusers.QwenImagePipeline]] ```python diffusers.QwenImagePipeline(scheduler: FlowMatchEulerDiscreteScheduler, vae: AutoencoderKLQwenImage, text_encoder: Qwen2_5_VLForConditionalGeneration, tokenizer: Qwen2Tokenizer, transformer: QwenImageTransformer2DModel) ``` [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage/pipeline_qwenimage.py#L132) **パラメータ:** transformer ([QwenImageTransformer2DModel](/docs/diffusers/main/ja/api/models/qwenimage_transformer2d#diffusers.QwenImageTransformer2DModel)) : エンコードされた画像潜在変数をデノイズするための条件付き Transformer (MMDiT) アーキテクチャ。 scheduler ([FlowMatchEulerDiscreteScheduler](/docs/diffusers/main/ja/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler)) : `transformer` と組み合わせて、エンコードされた画像の潜在変数をデノイズするために使用するスケジューラー。 vae ([AutoencoderKL](/docs/diffusers/main/ja/api/models/autoencoderkl#diffusers.AutoencoderKL)) : 画像を潜在表現にエンコードし、潜在表現からデコードするための変分オートエンコーダ(VAE)モデル。 text_encoder (`Qwen2.5-VL-7B-Instruct`) : [Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct)、具体的には [Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct) バリアントです。 tokenizer (`Qwen2Tokenizer`) : クラス https://huggingface.co/docs/transformers/en/model_doc/qwen2#transformers.Qwen2Tokenizer の Tokenizer テキストから画像を生成するためのQwenImageパイプライン。 #### __call__[[diffusers.QwenImagePipeline.__call__]] ```python __call__(prompt: str | list[str] = None, negative_prompt: str | list[str] = None, true_cfg_scale: float = 4.0, height: int | None = None, width: int | None = None, num_inference_steps: int = 50, sigmas: list[float] | None = None, guidance_scale: float | None = None, num_images_per_prompt: int = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_embeds_mask: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds_mask: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, attention_kwargs: dict[str, typing.Any] | None = None, callback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], max_sequence_length: int = 512) ``` [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage/pipeline_qwenimage.py#L408) **パラメータ:** prompt (`str` または `list[str]`、*省略可*) : 画像生成をガイドするためのプロンプトです。未定義の場合、代わりに `prompt_embeds` を渡す必要があります。 negative_prompt (`str` または `list[str]`、*省略可能*) : 画像生成をガイドしないプロンプトです。未定義の場合、代わりに `negative_prompt_embeds` を渡す必要があります。ガイダンスを使用していない場合は無視されます(`true_cfg_scale` が `1` 以下の場合に無視されます)。 true_cfg_scale (`float`、*任意*、デフォルト値は 1.0) : [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598)で定義されているガイダンススケールです。`true_cfg_scale`は、[Imagen Paper](https://huggingface.co/papers/2205.11487)の式 2 の `w` として定義されています。`true_cfg_scale > 1`を設定し、`negative_prompt`を指定することで、classifier-free guidance が有効になります。ガイダンススケールを高くすると、`prompt`のテキストと密接に関連する画像の生成が促されますが、通常は画像の品質低下を伴います。 height (`int`、*任意*、デフォルトは self.unet.config.sample_size * self.vae_scale_factor) : 生成される画像のピクセル単位の縦幅。最適な結果を得るため、デフォルトでは 1024 に設定されています。 width (`int`、*任意*、デフォルトは self.unet.config.sample_size * self.vae_scale_factor) : 生成される画像の幅(ピクセル単位)。最適な結果を得るため、デフォルトでは 1024 に設定されています。 num_inference_steps (`int`、*任意*、デフォルト値は 50) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。 sigmas (`list[float]`, *任意*) : `set_timesteps` メソッドで `sigmas` 引数をサポートするスケジューラーにおいて、デノイジングプロセスに使用するカスタムシグマ。`num_inference_steps` が渡された場合のデフォルトの動作が使用されます。 guidance_scale (`float`、*任意*、デフォルトは None) : ガイダンス蒸留モデル用のガイダンススケール値です。従来の classifier-free guidance では、推論時にノイズ予測の再スケーリングを通じてガイダンススケールが適用されますが、ガイダンス蒸留モデルでは、フォワードパス中にガイダンススケールを直接入力パラメータとして受け取ります。`guidance_scale > 1` を設定することでガイダンススケールが有効になります。ガイダンススケールを高くすると、`prompt` のテキストと密接に関連した画像の生成が促されますが、通常は画像品質の低下を伴います。このパラメータは、将来登場するガイダンス蒸留モデルをサポートするためにパイプラインに用意されています。ガイダンス蒸留モデルを使用しない場合は無視されます。従来の classifier-free guidance を有効にするには、`true_cfg_scale > 1.0` と `negative_prompt`(" " のような空の negative prompt でも classifier-free guidance の計算を有効にします)を渡してください。 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`を使用してサンプリングを行い、ラテンツのテンソルが生成されます。 prompt_embeds (`torch.Tensor`, *任意*) : 事前生成されたテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。 prompt_embeds_mask (`torch.Tensor`, *任意*) : `prompt_embeds`用のアテンションマスク。 negative_prompt_embeds (`torch.Tensor`, *任意*) : 事前に生成されたネガティブなテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`negative_prompt` 入力引数から negative_prompt_embeds が生成されます。 negative_prompt_embeds_mask (`torch.Tensor`, *任意*) : `negative_prompt_embeds` 用のアテンションマスク。 output_type (`str`、*任意*、デフォルトは `"pil"`) : 生成画像の出力形式。[PIL](https://pillow.readthedocs.io/en/stable/)(`PIL.Image.Image`)または `np.array` から選択します。 return_dict (`bool`、*任意*、デフォルトは`True`) : プレーンなタプルではなく`~pipelines.qwenimage.QwenImagePipelineOutput`を返すかどうか。 attention_kwargs (`dict`, *任意*) : 指定された場合、[diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py) の `self.processor` で定義されている `AttentionProcessor` に渡される kwargs の辞書です。 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` 属性に列挙された変数のみを、リストに含めることができます。 max_sequence_length (`int`、デフォルトは 512) : `prompt` に使用する最大シーケンス長。 **戻り値:** `~pipelines.qwenimage.QwenImagePipelineOutput` または `tuple` `return_dict` が True の場合は `~pipelines.qwenimage.QwenImagePipelineOutput`、それ以外の場合は `tuple` を返します。tuple を返す場合、最初の要素は生成された画像のリストです。 生成用のパイプラインを呼び出したときに実行される関数。 例: ```py >>> import torch >>> from diffusers import QwenImagePipeline >>> pipe = QwenImagePipeline.from_pretrained("Qwen/Qwen-Image", torch_dtype=torch.bfloat16) >>> pipe.to("cuda") >>> prompt = "A cat holding a sign that says hello world" >>> # Depending on the variant being used, the pipeline call will slightly vary. >>> # Refer to the pipeline documentation for more details. >>> image = pipe(prompt, num_inference_steps=50).images[0] >>> image.save("qwenimage.png") ``` #### encode_prompt[[diffusers.QwenImagePipeline.encode_prompt]] ```python encode_prompt(prompt: str | list[str], device: typing.Optional[torch.device] = None, num_images_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_embeds_mask: typing.Optional[torch.Tensor] = None, max_sequence_length: int = 1024) ``` [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage/pipeline_qwenimage.py#L225) **パラメータ:** prompt (`str` または `list[str]`、*省略可能*) : エンコードするプロンプト device : (`torch.device`): torch デバイス num_images_per_prompt (`int`) : プロンプトごとに生成すべき画像の数 prompt_embeds (`torch.Tensor`, *任意*) : 事前生成されたテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。 ## QwenImageImg2ImgPipeline[[diffusers.QwenImageImg2ImgPipeline]] #### diffusers.QwenImageImg2ImgPipeline[[diffusers.QwenImageImg2ImgPipeline]] ```python diffusers.QwenImageImg2ImgPipeline(scheduler: FlowMatchEulerDiscreteScheduler, vae: AutoencoderKLQwenImage, text_encoder: Qwen2_5_VLForConditionalGeneration, tokenizer: Qwen2Tokenizer, transformer: QwenImageTransformer2DModel) ``` [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage/pipeline_qwenimage_img2img.py#L134) **パラメータ:** transformer ([QwenImageTransformer2DModel](/docs/diffusers/main/ja/api/models/qwenimage_transformer2d#diffusers.QwenImageTransformer2DModel)) : エンコードされた画像潜在変数をデノイズするための条件付き Transformer (MMDiT) アーキテクチャ。 scheduler ([FlowMatchEulerDiscreteScheduler](/docs/diffusers/main/ja/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler)) : `transformer` と組み合わせて、エンコードされた画像の潜在変数をデノイズするために使用するスケジューラー。 vae ([AutoencoderKL](/docs/diffusers/main/ja/api/models/autoencoderkl#diffusers.AutoencoderKL)) : 画像を潜在表現にエンコードし、潜在表現からデコードするための変分オートエンコーダ(VAE)モデル。 text_encoder (`Qwen2.5-VL-7B-Instruct`) : [Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct)、具体的には [Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct) バリアントです。 tokenizer (`Qwen2Tokenizer`) : クラス https://huggingface.co/docs/transformers/en/model_doc/qwen2#transformers.Qwen2Tokenizer の Tokenizer テキストから画像を生成するためのQwenImageパイプライン。 #### __call__[[diffusers.QwenImageImg2ImgPipeline.__call__]] ```python __call__(prompt: str | list[str] = None, negative_prompt: str | list[str] = None, true_cfg_scale: float = 4.0, image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]] = None, height: int | None = None, width: int | None = None, strength: float = 0.6, num_inference_steps: int = 50, sigmas: list[float] | None = None, guidance_scale: float | None = None, num_images_per_prompt: int = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_embeds_mask: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds_mask: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, attention_kwargs: dict[str, typing.Any] | None = None, callback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], max_sequence_length: int = 512) ``` [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage/pipeline_qwenimage_img2img.py#L482) **パラメータ:** prompt (`str` または `list[str]`、*省略可*) : 画像生成をガイドするためのプロンプトです。未定義の場合、代わりに `prompt_embeds` を渡す必要があります。 negative_prompt (`str` または `list[str]`、*省略可能*) : 画像生成をガイドしないプロンプトです。未定義の場合、代わりに `negative_prompt_embeds` を渡す必要があります。ガイダンスを使用していない場合は無視されます(`true_cfg_scale` が `1` 以下の場合に無視されます)。 image (`torch.Tensor`、`PIL.Image.Image`、`np.ndarray`、`list[torch.Tensor]`、`list[PIL.Image.Image]`、または `list[np.ndarray]`) : `Image`、numpy 配列、またはテンソル。開始点として使用される画像バッチを表します。numpy 配列および PyTorch テンソルの場合、想定される値の範囲は `[0, 1]` です。テンソルまたはテンソルのリストの場合、想定される形状は `(B, C, H, W)` または `(C, H, W)` です。numpy 配列または配列のリストの場合、想定される形状は `(B, H, W, C)` または `(H, W, C)` です。`image` として画像の潜在変数(latents)を受け取ることもできますが、潜在変数を直接渡す場合は、再度エンコードされません。 true_cfg_scale (`float`、*任意*、デフォルト値は 1.0) : [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598)で定義されているガイダンススケールです。`true_cfg_scale`は、[Imagen Paper](https://huggingface.co/papers/2205.11487)の式 2 の `w` として定義されています。`true_cfg_scale > 1`を設定し、`negative_prompt`を指定することで、classifier-free guidance が有効になります。ガイダンススケールを高くすると、`prompt`のテキストと密接に関連する画像の生成が促されますが、通常は画像の品質低下を伴います。 height (`int`、*任意*、デフォルトは self.unet.config.sample_size * self.vae_scale_factor) : 生成される画像のピクセル単位の縦幅。最適な結果を得るため、デフォルトでは 1024 に設定されています。 width (`int`、*任意*、デフォルトは self.unet.config.sample_size * self.vae_scale_factor) : 生成される画像の幅(ピクセル単位)。最適な結果を得るため、デフォルトでは 1024 に設定されています。 strength (`float`、*任意*、デフォルト値は 1.0) : 参照となる `image` を変換する度合いを示します。0 から 1 の間の値である必要があります。`image` が起点として使用され、`strength` の値が大きいほど、より多くのノイズが追加されます。デノイジングのステップ数は、最初に追加されるノイズの量に依存します。`strength` が 1 の場合、追加されるノイズは最大となり、`num_inference_steps` で指定された全イテレーション数にわたってデノイジングプロセスが実行されます。値が 1 である場合、`image` は実質的に無視されます。 num_inference_steps (`int`、*任意*、デフォルト値は 50) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。 sigmas (`list[float]`, *任意*) : `set_timesteps` メソッドで `sigmas` 引数をサポートするスケジューラーにおいて、デノイジングプロセスに使用するカスタムシグマ。`num_inference_steps` が渡された場合のデフォルトの動作が使用されます。 guidance_scale (`float`、*任意*、デフォルトは None) : ガイダンス蒸留モデル用のガイダンススケール値です。従来の classifier-free guidance では、推論時にノイズ予測の再スケーリングを通じてガイダンススケールが適用されますが、ガイダンス蒸留モデルでは、フォワードパス中にガイダンススケールを直接入力パラメータとして受け取ります。`guidance_scale > 1` を設定することでガイダンススケールが有効になります。ガイダンススケールを高くすると、`prompt` のテキストと密接に関連した画像の生成が促されますが、通常は画像品質の低下を伴います。このパラメータは、将来登場するガイダンス蒸留モデルをサポートするためにパイプラインに用意されています。ガイダンス蒸留モデルを使用しない場合は無視されます。従来の classifier-free guidance を有効にするには、`true_cfg_scale > 1.0` と `negative_prompt`(" " のような空の negative prompt でも classifier-free guidance の計算を有効にします)を渡してください。 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`を使用してサンプリングを行い、ラテンツのテンソルが生成されます。 prompt_embeds (`torch.Tensor`, *任意*) : 事前生成されたテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。 prompt_embeds_mask (`torch.Tensor`, *任意*) : `prompt_embeds`用のアテンションマスク。 negative_prompt_embeds (`torch.Tensor`, *任意*) : 事前に生成されたネガティブなテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`negative_prompt` 入力引数から negative_prompt_embeds が生成されます。 negative_prompt_embeds_mask (`torch.Tensor`, *任意*) : `negative_prompt_embeds` 用のアテンションマスク。 output_type (`str`、*任意*、デフォルトは `"pil"`) : 生成画像の出力形式。[PIL](https://pillow.readthedocs.io/en/stable/)(`PIL.Image.Image`)または `np.array` から選択します。 return_dict (`bool`、*任意*、デフォルトは`True`) : プレーンなタプルではなく`~pipelines.qwenimage.QwenImagePipelineOutput`を返すかどうか。 attention_kwargs (`dict`, *任意*) : 指定された場合、[diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py) の `self.processor` で定義されている `AttentionProcessor` に渡される kwargs の辞書です。 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` 属性に列挙された変数のみを、リストに含めることができます。 max_sequence_length (`int`、デフォルトは 512) : `prompt` に使用する最大シーケンス長。 **戻り値:** `~pipelines.qwenimage.QwenImagePipelineOutput` または `tuple` `return_dict` が True の場合は `~pipelines.qwenimage.QwenImagePipelineOutput`、それ以外の場合は `tuple` を返します。tuple を返す場合、最初の要素は生成された画像のリストです。 生成用のパイプラインを呼び出したときに実行される関数。 例: ```py >>> import torch >>> from diffusers import QwenImageImg2ImgPipeline >>> from diffusers.utils import load_image >>> pipe = QwenImageImg2ImgPipeline.from_pretrained("Qwen/Qwen-Image", torch_dtype=torch.bfloat16) >>> pipe = pipe.to("cuda") >>> url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg" >>> init_image = load_image(url).resize((1024, 1024)) >>> prompt = "cat wizard, gandalf, lord of the rings, detailed, fantasy, cute, adorable, Pixar, Disney" >>> images = pipe(prompt=prompt, negative_prompt=" ", image=init_image, strength=0.95).images[0] >>> images.save("qwenimage_img2img.png") ``` #### encode_prompt[[diffusers.QwenImageImg2ImgPipeline.encode_prompt]] ```python encode_prompt(prompt: str | list[str], device: typing.Optional[torch.device] = None, num_images_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_embeds_mask: typing.Optional[torch.Tensor] = None, max_sequence_length: int = 1024) ``` [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage/pipeline_qwenimage_img2img.py#L268) **パラメータ:** prompt (`str` または `list[str]`、*省略可能*) : エンコードするプロンプト device : (`torch.device`): torch デバイス num_images_per_prompt (`int`) : プロンプトごとに生成すべき画像の数 prompt_embeds (`torch.Tensor`, *任意*) : 事前生成されたテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。 ## QwenImageInpaintPipeline[[diffusers.QwenImageInpaintPipeline]] #### diffusers.QwenImageInpaintPipeline[[diffusers.QwenImageInpaintPipeline]] ```python diffusers.QwenImageInpaintPipeline(scheduler: FlowMatchEulerDiscreteScheduler, vae: AutoencoderKLQwenImage, text_encoder: Qwen2_5_VLForConditionalGeneration, tokenizer: Qwen2Tokenizer, transformer: QwenImageTransformer2DModel) ``` [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage/pipeline_qwenimage_inpaint.py#L137) **パラメータ:** transformer ([QwenImageTransformer2DModel](/docs/diffusers/main/ja/api/models/qwenimage_transformer2d#diffusers.QwenImageTransformer2DModel)) : エンコードされた画像潜在変数をデノイズするための条件付き Transformer (MMDiT) アーキテクチャ。 scheduler ([FlowMatchEulerDiscreteScheduler](/docs/diffusers/main/ja/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler)) : `transformer` と組み合わせて、エンコードされた画像の潜在変数をデノイズするために使用するスケジューラー。 vae ([AutoencoderKL](/docs/diffusers/main/ja/api/models/autoencoderkl#diffusers.AutoencoderKL)) : 画像を潜在表現にエンコードし、潜在表現からデコードするための変分オートエンコーダ(VAE)モデル。 text_encoder (`Qwen2.5-VL-7B-Instruct`) : [Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct)、具体的には [Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct) バリアントです。 tokenizer (`Qwen2Tokenizer`) : クラス https://huggingface.co/docs/transformers/en/model_doc/qwen2#transformers.Qwen2Tokenizer の Tokenizer テキストから画像を生成するためのQwenImageパイプライン。 #### __call__[[diffusers.QwenImageInpaintPipeline.__call__]] ```python __call__(prompt: str | list[str] = None, negative_prompt: str | list[str] = None, true_cfg_scale: float = 4.0, image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]] = None, mask_image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]] = None, masked_image_latents: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]] = None, height: int | None = None, width: int | None = None, padding_mask_crop: int | None = None, strength: float = 0.6, num_inference_steps: int = 50, sigmas: list[float] | None = None, guidance_scale: float | None = None, num_images_per_prompt: int = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_embeds_mask: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds_mask: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, attention_kwargs: dict[str, typing.Any] | None = None, callback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], max_sequence_length: int = 512) ``` [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage/pipeline_qwenimage_inpaint.py#L592) **パラメータ:** prompt (`str` または `list[str]`、*省略可*) : 画像生成をガイドするためのプロンプトです。未定義の場合、代わりに `prompt_embeds` を渡す必要があります。 negative_prompt (`str` または `list[str]`、*省略可能*) : 画像生成をガイドしないプロンプトです。未定義の場合、代わりに `negative_prompt_embeds` を渡す必要があります。ガイダンスを使用していない場合は無視されます(`true_cfg_scale` が `1` 以下の場合に無視されます)。 image (`torch.Tensor`、`PIL.Image.Image`、`np.ndarray`、`list[torch.Tensor]`、`list[PIL.Image.Image]`、または `list[np.ndarray]`) : `Image`、numpy 配列、またはテンソル。開始点として使用される画像バッチを表します。numpy 配列および PyTorch テンソルの場合、想定される値の範囲は `[0, 1]` です。テンソルまたはテンソルのリストの場合、想定される形状は `(B, C, H, W)` または `(C, H, W)` です。numpy 配列または配列のリストの場合、想定される形状は `(B, H, W, C)` または `(H, W, C)` です。`image` として画像の潜在変数(latents)を受け取ることもできますが、潜在変数を直接渡す場合は、再度エンコードされません。 true_cfg_scale (`float`、*任意*、デフォルト値は 1.0) : [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598)で定義されているガイダンススケールです。`true_cfg_scale`は、[Imagen Paper](https://huggingface.co/papers/2205.11487)の式 2 の `w` として定義されています。`true_cfg_scale > 1`を設定し、`negative_prompt`を指定することで、classifier-free guidance が有効になります。ガイダンススケールを高くすると、`prompt`のテキストと密接に関連する画像の生成が促されますが、通常は画像の品質低下を伴います。 mask_image (`torch.Tensor`、`PIL.Image.Image`、`np.ndarray`、`list[torch.Tensor]`、`list[PIL.Image.Image]`、または `list[np.ndarray]`) : `image` をマスクするための `Image`、numpy 配列、またはテンソル。マスク内の白いピクセルは再描画され、黒いピクセルは保持されます。`mask_image` が PIL イメージの場合、使用の前に単一チャネル(輝度)に変換されます。numpy 配列または PyTorch テンソルの場合は、3 チャネルではなく 1 つの色チャネル(L)を含む必要があります。そのため、PyTorch テンソルの想定される形状は `(B, 1, H, W)`、`(B, H, W)`、`(1, H, W)`、`(H, W)` となります。一方、numpy 配列の場合は `(B, H, W, 1)`、`(B, H, W)`、`(H, W, 1)`、または `(H, W)` となります。 masked_image_latents (`torch.Tensor`、`list[torch.Tensor]`) : VAEによって生成された`image`をマスクするための画像バッチを表す`Tensor`。指定されない場合、マスク用の潜変数テンソルは`mask_image`によって生成されます。 height (`int`、*任意*、デフォルトは self.unet.config.sample_size * self.vae_scale_factor) : 生成される画像のピクセル単位の縦幅。最適な結果を得るため、デフォルトでは 1024 に設定されています。 width (`int`、*任意*、デフォルトは self.unet.config.sample_size * self.vae_scale_factor) : 生成される画像の幅(ピクセル単位)。最適な結果を得るため、デフォルトでは 1024 に設定されています。 padding_mask_crop (`int`, *任意*、デフォルトは `None`) : 画像とマスクに適用するクロップの余白サイズ。`None` の場合、画像および mask_image にはクロップが適用されません。`padding_mask_crop` が `None` でない場合、まず画像と同じアスペクト比を持ち、すべてのマスク領域を含む長方形の領域を特定し、その後 `padding_mask_crop` に基づいてその領域を拡大します。その後、インペインティングのために元の画像サイズにリサイズする前に、拡大された領域に基づいて画像と mask_image がクロップされます。これは、マスク領域が小さく、画像が大きく、背景などインペインティングに関連しない情報が含まれている場合に有用です。 strength (`float`、*任意*、デフォルト値は 1.0) : 参照となる `image` を変換する度合いを示します。0 から 1 の間の値である必要があります。`image` が起点として使用され、`strength` の値が大きいほど、より多くのノイズが追加されます。デノイジングのステップ数は、最初に追加されるノイズの量に依存します。`strength` が 1 の場合、追加されるノイズは最大となり、`num_inference_steps` で指定された全イテレーション数にわたってデノイジングプロセスが実行されます。値が 1 である場合、`image` は実質的に無視されます。 num_inference_steps (`int`、*任意*、デフォルト値は 50) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。 sigmas (`list[float]`, *任意*) : `set_timesteps` メソッドで `sigmas` 引数をサポートするスケジューラーにおいて、デノイジングプロセスに使用するカスタムシグマ。`num_inference_steps` が渡された場合のデフォルトの動作が使用されます。 guidance_scale (`float`、*任意*、デフォルトは None) : ガイダンス蒸留モデル用のガイダンススケール値です。従来の classifier-free guidance では、推論時にノイズ予測の再スケーリングを通じてガイダンススケールが適用されますが、ガイダンス蒸留モデルでは、フォワードパス中にガイダンススケールを直接入力パラメータとして受け取ります。`guidance_scale > 1` を設定することでガイダンススケールが有効になります。ガイダンススケールを高くすると、`prompt` のテキストと密接に関連した画像の生成が促されますが、通常は画像品質の低下を伴います。このパラメータは、将来登場するガイダンス蒸留モデルをサポートするためにパイプラインに用意されています。ガイダンス蒸留モデルを使用しない場合は無視されます。従来の classifier-free guidance を有効にするには、`true_cfg_scale > 1.0` と `negative_prompt`(" " のような空の negative prompt でも classifier-free guidance の計算を有効にします)を渡してください。 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`を使用してサンプリングを行い、ラテンツのテンソルが生成されます。 prompt_embeds (`torch.Tensor`, *任意*) : 事前生成されたテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。 prompt_embeds_mask (`torch.Tensor`, *任意*) : `prompt_embeds`用のアテンションマスク。 negative_prompt_embeds (`torch.Tensor`, *任意*) : 事前に生成されたネガティブなテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`negative_prompt` 入力引数から negative_prompt_embeds が生成されます。 negative_prompt_embeds_mask (`torch.Tensor`, *任意*) : `negative_prompt_embeds` 用のアテンションマスク。 output_type (`str`、*任意*、デフォルトは `"pil"`) : 生成画像の出力形式。[PIL](https://pillow.readthedocs.io/en/stable/)(`PIL.Image.Image`)または `np.array` から選択します。 return_dict (`bool`、*任意*、デフォルトは`True`) : プレーンなタプルではなく`~pipelines.qwenimage.QwenImagePipelineOutput`を返すかどうか。 attention_kwargs (`dict`, *任意*) : 指定された場合、[diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py) の `self.processor` で定義されている `AttentionProcessor` に渡される kwargs の辞書です。 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` 属性に列挙された変数のみを、リストに含めることができます。 max_sequence_length (`int`、デフォルトは 512) : `prompt` に使用する最大シーケンス長。 **戻り値:** `~pipelines.qwenimage.QwenImagePipelineOutput` または `tuple` `return_dict` が True の場合は `~pipelines.qwenimage.QwenImagePipelineOutput`、それ以外の場合は `tuple` を返します。tuple を返す場合、最初の要素は生成された画像のリストです。 生成用のパイプラインを呼び出したときに実行される関数。 例: ```py >>> import torch >>> from diffusers import QwenImageInpaintPipeline >>> from diffusers.utils import load_image >>> pipe = QwenImageInpaintPipeline.from_pretrained("Qwen/Qwen-Image", torch_dtype=torch.bfloat16) >>> pipe.to("cuda") >>> prompt = "Face of a yellow cat, high resolution, sitting on a park bench" >>> img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png" >>> mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png" >>> source = load_image(img_url) >>> mask = load_image(mask_url) >>> image = pipe(prompt=prompt, negative_prompt=" ", image=source, mask_image=mask, strength=0.85).images[0] >>> image.save("qwenimage_inpainting.png") ``` #### encode_prompt[[diffusers.QwenImageInpaintPipeline.encode_prompt]] ```python encode_prompt(prompt: str | list[str], device: typing.Optional[torch.device] = None, num_images_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_embeds_mask: typing.Optional[torch.Tensor] = None, max_sequence_length: int = 1024) ``` [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage/pipeline_qwenimage_inpaint.py#L279) **パラメータ:** prompt (`str` または `list[str]`、*省略可能*) : エンコードするプロンプト device : (`torch.device`): torch デバイス num_images_per_prompt (`int`) : プロンプトごとに生成すべき画像の数 prompt_embeds (`torch.Tensor`, *任意*) : 事前生成されたテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。 ## QwenImageEditPipeline[[diffusers.QwenImageEditPipeline]] #### diffusers.QwenImageEditPipeline[[diffusers.QwenImageEditPipeline]] ```python diffusers.QwenImageEditPipeline(scheduler: FlowMatchEulerDiscreteScheduler, vae: AutoencoderKLQwenImage, text_encoder: Qwen2_5_VLForConditionalGeneration, tokenizer: Qwen2Tokenizer, processor: Qwen2VLProcessor, transformer: QwenImageTransformer2DModel) ``` [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage/pipeline_qwenimage_edit.py#L165) **パラメータ:** transformer ([QwenImageTransformer2DModel](/docs/diffusers/main/ja/api/models/qwenimage_transformer2d#diffusers.QwenImageTransformer2DModel)) : エンコードされた画像潜在変数をデノイズするための条件付き Transformer (MMDiT) アーキテクチャ。 scheduler ([FlowMatchEulerDiscreteScheduler](/docs/diffusers/main/ja/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler)) : `transformer` と組み合わせて、エンコードされた画像の潜在変数をデノイズするために使用するスケジューラー。 vae ([AutoencoderKL](/docs/diffusers/main/ja/api/models/autoencoderkl#diffusers.AutoencoderKL)) : 画像を潜在表現にエンコードし、潜在表現からデコードするための変分オートエンコーダ(VAE)モデル。 text_encoder (`Qwen2.5-VL-7B-Instruct`) : [Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct)、具体的には [Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct) バリアントです。 tokenizer (`Qwen2Tokenizer`) : クラス https://huggingface.co/docs/transformers/en/model_doc/qwen2#transformers.Qwen2Tokenizer の Tokenizer 画像編集用の Qwen-Image-Edit パイプライン。 #### __call__[[diffusers.QwenImageEditPipeline.__call__]] ```python __call__(image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor], NoneType] = None, prompt: str | list[str] = None, negative_prompt: str | list[str] = None, true_cfg_scale: float = 4.0, height: int | None = None, width: int | None = None, num_inference_steps: int = 50, sigmas: list[float] | None = None, guidance_scale: float | None = None, num_images_per_prompt: int = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_embeds_mask: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds_mask: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, attention_kwargs: dict[str, typing.Any] | None = None, callback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], max_sequence_length: int = 512) ``` [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage/pipeline_qwenimage_edit.py#L504) **パラメータ:** image (`torch.Tensor`、`PIL.Image.Image`、`np.ndarray`、`list[torch.Tensor]`、`list[PIL.Image.Image]`、または `list[np.ndarray]`) : `Image`、numpy 配列、またはテンソル。開始点として使用される画像バッチを表します。numpy 配列および PyTorch テンソルの場合、想定される値の範囲は `[0, 1]` です。テンソルまたはテンソルのリストの場合、想定される形状は `(B, C, H, W)` または `(C, H, W)` です。numpy 配列または配列のリストの場合、想定される形状は `(B, H, W, C)` または `(H, W, C)` です。`image` として画像の潜在変数(latents)を受け取ることもできますが、潜在変数を直接渡す場合は、再度エンコードされません。 prompt (`str` または `list[str]`、*省略可*) : 画像生成をガイドするためのプロンプトです。未定義の場合、代わりに `prompt_embeds` を渡す必要があります。 negative_prompt (`str` または `list[str]`、*省略可能*) : 画像生成をガイドしないプロンプトです。未定義の場合、代わりに `negative_prompt_embeds` を渡す必要があります。ガイダンスを使用していない場合は無視されます(`true_cfg_scale` が `1` 以下の場合に無視されます)。 true_cfg_scale (`float`、*任意*、デフォルト値は 1.0) : true_cfg_scale (`float`、*任意*、デフォルト値は 1.0): [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598) で定義されているガイダンススケールです。 `true_cfg_scale` は、[Imagen Paper](https://huggingface.co/papers/2205.11487) の数式 2 の `w` として定義されています。 `true_cfg_scale > 1` を設定し、`negative_prompt` を指定することで、classifier-free guidance が有効になります。ガイダンススケールを高くすると、テキスト `prompt` と密接に関連する画像の生成が促されますが、通常は画像品質の低下を伴います。 height (`int`、*任意*、デフォルトは self.unet.config.sample_size * self.vae_scale_factor) : 生成される画像のピクセル単位の縦幅。最適な結果を得るため、デフォルトでは 1024 に設定されています。 width (`int`、*任意*、デフォルトは self.unet.config.sample_size * self.vae_scale_factor) : 生成される画像の幅(ピクセル単位)。最適な結果を得るため、デフォルトでは 1024 に設定されています。 num_inference_steps (`int`、*任意*、デフォルト値は 50) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。 sigmas (`list[float]`, *任意*) : `set_timesteps` メソッドで `sigmas` 引数をサポートするスケジューラーにおいて、デノイジングプロセスに使用するカスタムシグマ。`num_inference_steps` が渡された場合のデフォルトの動作が使用されます。 guidance_scale (`float`、*任意*、デフォルトは None) : ガイダンス蒸留モデル用のガイダンススケール値です。従来の classifier-free guidance では、推論時にノイズ予測の再スケーリングを通じてガイダンススケールが適用されますが、ガイダンス蒸留モデルでは、フォワードパス中にガイダンススケールを直接入力パラメータとして受け取ります。`guidance_scale > 1` を設定することでガイダンススケールが有効になります。ガイダンススケールを高くすると、`prompt` のテキストと密接に関連した画像の生成が促されますが、通常は画像品質の低下を伴います。このパラメータは、将来登場するガイダンス蒸留モデルをサポートするためにパイプラインに用意されています。ガイダンス蒸留モデルを使用しない場合は無視されます。従来の classifier-free guidance を有効にするには、`true_cfg_scale > 1.0` と `negative_prompt`(" " のような空の negative prompt でも classifier-free guidance の計算を有効にします)を渡してください。 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`を使用してサンプリングを行い、ラテンツのテンソルが生成されます。 prompt_embeds (`torch.Tensor`, *任意*) : 事前生成されたテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。 prompt_embeds_mask (`torch.Tensor`, *任意*) : `prompt_embeds`用のアテンションマスク。 negative_prompt_embeds (`torch.Tensor`, *任意*) : 事前に生成されたネガティブなテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`negative_prompt` 入力引数から negative_prompt_embeds が生成されます。 negative_prompt_embeds_mask (`torch.Tensor`, *任意*) : `negative_prompt_embeds` 用のアテンションマスク。 output_type (`str`、*任意*、デフォルトは `"pil"`) : 生成画像の出力形式。[PIL](https://pillow.readthedocs.io/en/stable/)(`PIL.Image.Image`)または `np.array` から選択します。 return_dict (`bool`、*任意*、デフォルトは`True`) : プレーンなタプルではなく`~pipelines.qwenimage.QwenImagePipelineOutput`を返すかどうか。 attention_kwargs (`dict`, *任意*) : 指定された場合、[diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py) の `self.processor` で定義されている `AttentionProcessor` に渡される kwargs の辞書です。 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` 属性に列挙された変数のみを、リストに含めることができます。 max_sequence_length (`int`、デフォルトは 512) : `prompt` に使用する最大シーケンス長。 **戻り値:** `~pipelines.qwenimage.QwenImagePipelineOutput` または `tuple` `return_dict` が True の場合は `~pipelines.qwenimage.QwenImagePipelineOutput`、それ以外の場合は `tuple` を返します。tuple を返す場合、最初の要素は生成された画像のリストです。 生成用のパイプラインを呼び出したときに実行される関数。 例: ```py >>> import torch >>> from PIL import Image >>> from diffusers import QwenImageEditPipeline >>> from diffusers.utils import load_image >>> pipe = QwenImageEditPipeline.from_pretrained("Qwen/Qwen-Image-Edit", torch_dtype=torch.bfloat16) >>> pipe.to("cuda") >>> image = load_image( ... "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/yarn-art-pikachu.png" ... ).convert("RGB") >>> prompt = ( ... "Make Pikachu hold a sign that says 'Qwen Edit is awesome', yarn art style, detailed, vibrant colors" ... ) >>> # Depending on the variant being used, the pipeline call will slightly vary. >>> # Refer to the pipeline documentation for more details. >>> image = pipe(image, prompt, num_inference_steps=50).images[0] >>> image.save("qwenimage_edit.png") ``` #### encode_prompt[[diffusers.QwenImageEditPipeline.encode_prompt]] ```python encode_prompt(prompt: str | list[str], image: typing.Optional[torch.Tensor] = None, device: typing.Optional[torch.device] = None, num_images_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_embeds_mask: typing.Optional[torch.Tensor] = None, max_sequence_length: int = 1024) ``` [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage/pipeline_qwenimage_edit.py#L272) **パラメータ:** prompt (`str` または `list[str]`、*省略可能*) : エンコードするプロンプト image (`torch.Tensor`, *任意*) : エンコードする画像 device : (`torch.device`): torch デバイス num_images_per_prompt (`int`) : プロンプトごとに生成すべき画像の数 prompt_embeds (`torch.Tensor`, *任意*) : 事前生成されたテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。 ## QwenImageEditInpaintPipeline[[diffusers.QwenImageEditInpaintPipeline]] #### diffusers.QwenImageEditInpaintPipeline[[diffusers.QwenImageEditInpaintPipeline]] ```python diffusers.QwenImageEditInpaintPipeline(scheduler: FlowMatchEulerDiscreteScheduler, vae: AutoencoderKLQwenImage, text_encoder: Qwen2_5_VLForConditionalGeneration, tokenizer: Qwen2Tokenizer, processor: Qwen2VLProcessor, transformer: QwenImageTransformer2DModel) ``` [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage/pipeline_qwenimage_edit_inpaint.py#L167) **パラメータ:** transformer ([QwenImageTransformer2DModel](/docs/diffusers/main/ja/api/models/qwenimage_transformer2d#diffusers.QwenImageTransformer2DModel)) : エンコードされた画像潜在変数をデノイズするための条件付き Transformer (MMDiT) アーキテクチャ。 scheduler ([FlowMatchEulerDiscreteScheduler](/docs/diffusers/main/ja/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler)) : `transformer` と組み合わせて、エンコードされた画像の潜在変数をデノイズするために使用するスケジューラー。 vae ([AutoencoderKL](/docs/diffusers/main/ja/api/models/autoencoderkl#diffusers.AutoencoderKL)) : 画像を潜在表現にエンコードし、潜在表現からデコードするための変分オートエンコーダ(VAE)モデル。 text_encoder (`Qwen2.5-VL-7B-Instruct`) : [Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct)、具体的には [Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct) バリアントです。 tokenizer (`Qwen2Tokenizer`) : クラス https://huggingface.co/docs/transformers/en/model_doc/qwen2#transformers.Qwen2Tokenizer の Tokenizer 画像編集用の Qwen-Image-Edit パイプライン。 #### __call__[[diffusers.QwenImageEditInpaintPipeline.__call__]] ```python __call__(image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor], NoneType] = None, prompt: str | list[str] = None, negative_prompt: str | list[str] = None, mask_image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]] = None, masked_image_latents: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]] = None, true_cfg_scale: float = 4.0, height: int | None = None, width: int | None = None, padding_mask_crop: int | None = None, strength: float = 0.6, num_inference_steps: int = 50, sigmas: list[float] | None = None, guidance_scale: float | None = None, num_images_per_prompt: int = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_embeds_mask: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds_mask: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, attention_kwargs: dict[str, typing.Any] | None = None, callback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], max_sequence_length: int = 512) ``` [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage/pipeline_qwenimage_edit_inpaint.py#L637) **パラメータ:** image (`torch.Tensor`、`PIL.Image.Image`、`np.ndarray`、`list[torch.Tensor]`、`list[PIL.Image.Image]`、または `list[np.ndarray]`) : `Image`、numpy 配列、またはテンソル。開始点として使用される画像バッチを表します。numpy 配列および PyTorch テンソルの場合、想定される値の範囲は `[0, 1]` です。テンソルまたはテンソルのリストの場合、想定される形状は `(B, C, H, W)` または `(C, H, W)` です。numpy 配列または配列のリストの場合、想定される形状は `(B, H, W, C)` または `(H, W, C)` です。`image` として画像の潜在変数(latents)を受け取ることもできますが、潜在変数を直接渡す場合は、再度エンコードされません。 prompt (`str` または `list[str]`、*省略可*) : 画像生成をガイドするためのプロンプトです。未定義の場合、代わりに `prompt_embeds` を渡す必要があります。 negative_prompt (`str` または `list[str]`、*省略可能*) : 画像生成をガイドしないプロンプトです。未定義の場合、代わりに `negative_prompt_embeds` を渡す必要があります。ガイダンスを使用していない場合は無視されます(`true_cfg_scale` が `1` 以下の場合に無視されます)。 true_cfg_scale (`float`、*任意*、デフォルト値は 1.0) : true_cfg_scale (`float`、*任意*、デフォルト値は 1.0): [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598) で定義されているガイダンススケールです。 `true_cfg_scale` は、[Imagen Paper](https://huggingface.co/papers/2205.11487) の数式 2 の `w` として定義されています。 `true_cfg_scale > 1` を設定し、`negative_prompt` を指定することで、classifier-free guidance が有効になります。ガイダンススケールを高くすると、テキスト `prompt` と密接に関連する画像の生成が促されますが、通常は画像品質の低下を伴います。 mask_image (`torch.Tensor`、`PIL.Image.Image`、`np.ndarray`、`list[torch.Tensor]`、`list[PIL.Image.Image]`、または `list[np.ndarray]`) : `image` をマスクするための `Image`、numpy 配列、またはテンソル。マスク内の白いピクセルは再描画され、黒いピクセルは保持されます。`mask_image` が PIL イメージの場合、使用の前に単一チャネル(輝度)に変換されます。numpy 配列または PyTorch テンソルの場合は、3 チャネルではなく 1 つの色チャネル(L)を含む必要があります。そのため、PyTorch テンソルの想定される形状は `(B, 1, H, W)`、`(B, H, W)`、`(1, H, W)`、`(H, W)` となります。一方、numpy 配列の場合は `(B, H, W, 1)`、`(B, H, W)`、`(H, W, 1)`、または `(H, W)` となります。 masked_image_latents (`torch.Tensor`、`list[torch.Tensor]`) : VAE によって生成された `image` をマスクするための画像バッチを表す `Tensor`。指定されない場合、マスクの潜変数テンソルは `mask_image` によって生成されます。 height (`int`、*任意*、デフォルトは self.unet.config.sample_size * self.vae_scale_factor) : 生成される画像のピクセル単位の縦幅。最適な結果を得るため、デフォルトでは 1024 に設定されています。 width (`int`、*任意*、デフォルトは self.unet.config.sample_size * self.vae_scale_factor) : 生成される画像の幅(ピクセル単位)。最適な結果を得るため、デフォルトでは 1024 に設定されています。 padding_mask_crop (`int`, *任意*、デフォルトは `None`) : 画像とマスクに適用するクロップの余白サイズ。`None` の場合、画像および mask_image にはクロップが適用されません。`padding_mask_crop` が `None` でない場合、まず画像と同じアスペクト比を持ち、すべてのマスク領域を含む長方形の領域を特定し、その後 `padding_mask_crop` に基づいてその領域を拡大します。その後、インペインティングのために元の画像サイズにリサイズする前に、拡大された領域に基づいて画像と mask_image がクロップされます。これは、マスク領域が小さく、画像が大きく、背景などインペインティングに関連しない情報が含まれている場合に有用です。 strength (`float`、*任意*、デフォルト値は 1.0) : 参照となる `image` を変換する度合いを示します。0 から 1 の間の値である必要があります。`image` が起点として使用され、`strength` の値が大きいほど、より多くのノイズが追加されます。デノイジングのステップ数は、最初に追加されるノイズの量に依存します。`strength` が 1 の場合、追加されるノイズは最大となり、`num_inference_steps` で指定された全イテレーション数にわたってデノイジングプロセスが実行されます。値が 1 である場合、`image` は実質的に無視されます。 num_inference_steps (`int`、*任意*、デフォルト値は 50) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。 sigmas (`list[float]`, *任意*) : `set_timesteps` メソッドで `sigmas` 引数をサポートするスケジューラーにおいて、デノイジングプロセスに使用するカスタムシグマ。`num_inference_steps` が渡された場合のデフォルトの動作が使用されます。 guidance_scale (`float`、*任意*、デフォルトは None) : ガイダンス蒸留モデル用のガイダンススケール値です。従来の classifier-free guidance では、推論時にノイズ予測の再スケーリングを通じてガイダンススケールが適用されますが、ガイダンス蒸留モデルでは、フォワードパス中にガイダンススケールを直接入力パラメータとして受け取ります。`guidance_scale > 1` を設定することでガイダンススケールが有効になります。ガイダンススケールを高くすると、`prompt` のテキストと密接に関連した画像の生成が促されますが、通常は画像品質の低下を伴います。このパラメータは、将来登場するガイダンス蒸留モデルをサポートするためにパイプラインに用意されています。ガイダンス蒸留モデルを使用しない場合は無視されます。従来の classifier-free guidance を有効にするには、`true_cfg_scale > 1.0` と `negative_prompt`(" " のような空の negative prompt でも classifier-free guidance の計算を有効にします)を渡してください。 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`を使用してサンプリングを行い、ラテンツのテンソルが生成されます。 prompt_embeds (`torch.Tensor`, *任意*) : 事前生成されたテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。 prompt_embeds_mask (`torch.Tensor`, *任意*) : `prompt_embeds`用のアテンションマスク。 negative_prompt_embeds (`torch.Tensor`, *任意*) : 事前に生成されたネガティブなテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`negative_prompt` 入力引数から negative_prompt_embeds が生成されます。 negative_prompt_embeds_mask (`torch.Tensor`, *任意*) : `negative_prompt_embeds` 用のアテンションマスク。 output_type (`str`、*任意*、デフォルトは `"pil"`) : 生成画像の出力形式。[PIL](https://pillow.readthedocs.io/en/stable/)(`PIL.Image.Image`)または `np.array` から選択します。 return_dict (`bool`、*任意*、デフォルトは`True`) : プレーンなタプルではなく`~pipelines.qwenimage.QwenImagePipelineOutput`を返すかどうか。 attention_kwargs (`dict`, *任意*) : 指定された場合、[diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py) の `self.processor` で定義されている `AttentionProcessor` に渡される kwargs の辞書です。 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` 属性に列挙された変数のみを、リストに含めることができます。 max_sequence_length (`int`、デフォルトは 512) : `prompt` に使用する最大シーケンス長。 **戻り値:** `~pipelines.qwenimage.QwenImagePipelineOutput` または `tuple` `return_dict` が True の場合は `~pipelines.qwenimage.QwenImagePipelineOutput`、それ以外の場合は `tuple` を返します。tuple を返す場合、最初の要素は生成された画像のリストです。 生成用のパイプラインを呼び出したときに実行される関数。 例: ```py >>> import torch >>> from PIL import Image >>> from diffusers import QwenImageEditInpaintPipeline >>> from diffusers.utils import load_image >>> pipe = QwenImageEditInpaintPipeline.from_pretrained("Qwen/Qwen-Image-Edit", torch_dtype=torch.bfloat16) >>> pipe.to("cuda") >>> prompt = "Face of a yellow cat, high resolution, sitting on a park bench" >>> img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png" >>> mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png" >>> source = load_image(img_url) >>> mask = load_image(mask_url) >>> image = pipe( ... prompt=prompt, negative_prompt=" ", image=source, mask_image=mask, strength=1.0, num_inference_steps=50 ... ).images[0] >>> image.save("qwenimage_inpainting.png") ``` #### encode_prompt[[diffusers.QwenImageEditInpaintPipeline.encode_prompt]] ```python encode_prompt(prompt: str | list[str], image: typing.Optional[torch.Tensor] = None, device: typing.Optional[torch.device] = None, num_images_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_embeds_mask: typing.Optional[torch.Tensor] = None, max_sequence_length: int = 1024) ``` [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage/pipeline_qwenimage_edit_inpaint.py#L284) **パラメータ:** prompt (`str` または `list[str]`、*省略可能*) : エンコードするプロンプト image (`torch.Tensor`, *任意*) : エンコードする画像 device : (`torch.device`): torch デバイス num_images_per_prompt (`int`) : プロンプトごとに生成すべき画像の数 prompt_embeds (`torch.Tensor`, *任意*) : 事前生成されたテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。 ## QwenImageControlNetPipeline[[diffusers.QwenImageControlNetPipeline]] #### diffusers.QwenImageControlNetPipeline[[diffusers.QwenImageControlNetPipeline]] ```python diffusers.QwenImageControlNetPipeline(scheduler: FlowMatchEulerDiscreteScheduler, vae: AutoencoderKLQwenImage, text_encoder: Qwen2_5_VLForConditionalGeneration, tokenizer: Qwen2Tokenizer, transformer: QwenImageTransformer2DModel, controlnet: diffusers.models.controlnets.controlnet_qwenimage.QwenImageControlNetModel | diffusers.models.controlnets.controlnet_qwenimage.QwenImageMultiControlNetModel) ``` [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage/pipeline_qwenimage_controlnet.py#L192) **パラメータ:** transformer ([QwenImageTransformer2DModel](/docs/diffusers/main/ja/api/models/qwenimage_transformer2d#diffusers.QwenImageTransformer2DModel)) : エンコードされた画像潜在変数をデノイズするための条件付き Transformer (MMDiT) アーキテクチャ。 scheduler ([FlowMatchEulerDiscreteScheduler](/docs/diffusers/main/ja/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler)) : `transformer` と組み合わせて、エンコードされた画像の潜在変数をデノイズするために使用するスケジューラー。 vae ([AutoencoderKL](/docs/diffusers/main/ja/api/models/autoencoderkl#diffusers.AutoencoderKL)) : 画像を潜在表現にエンコードし、潜在表現からデコードするための変分オートエンコーダ(VAE)モデル。 text_encoder (`Qwen2.5-VL-7B-Instruct`) : [Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct)、具体的には [Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct) バリアントです。 tokenizer (`Qwen2Tokenizer`) : クラス https://huggingface.co/docs/transformers/en/model_doc/qwen2#transformers.Qwen2Tokenizer の Tokenizer テキストから画像を生成するためのQwenImageパイプライン。 #### __call__[[diffusers.QwenImageControlNetPipeline.__call__]] ```python __call__(prompt: str | list[str] = None, negative_prompt: str | list[str] = None, true_cfg_scale: float = 4.0, height: int | None = None, width: int | None = None, num_inference_steps: int = 50, sigmas: list[float] | None = None, guidance_scale: float | None = None, control_guidance_start: float | list[float] = 0.0, control_guidance_end: float | list[float] = 1.0, control_image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]] = None, controlnet_conditioning_scale: float | list[float] = 1.0, num_images_per_prompt: int = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_embeds_mask: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds_mask: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, attention_kwargs: dict[str, typing.Any] | None = None, callback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], max_sequence_length: int = 512) ``` [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage/pipeline_qwenimage_controlnet.py#L511) **パラメータ:** prompt (`str` または `list[str]`、*省略可*) : 画像生成をガイドするためのプロンプトです。未定義の場合、代わりに `prompt_embeds` を渡す必要があります。 negative_prompt (`str` または `list[str]`、*省略可能*) : 画像生成をガイドしないプロンプトです。未定義の場合、代わりに `negative_prompt_embeds` を渡す必要があります。ガイダンスを使用していない場合は無視されます(`true_cfg_scale` が `1` 以下の場合に無視されます)。 true_cfg_scale (`float`、*任意*、デフォルト値は 1.0) : [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598)で定義されているガイダンススケールです。`true_cfg_scale`は、[Imagen Paper](https://huggingface.co/papers/2205.11487)の式 2 の `w` として定義されています。`true_cfg_scale > 1`を設定し、`negative_prompt`を指定することで、classifier-free guidance が有効になります。ガイダンススケールを高くすると、`prompt`のテキストと密接に関連する画像の生成が促されますが、通常は画像の品質低下を伴います。 height (`int`、*任意*、デフォルトは self.unet.config.sample_size * self.vae_scale_factor) : 生成される画像のピクセル単位の縦幅。最適な結果を得るため、デフォルトでは 1024 に設定されています。 width (`int`、*任意*、デフォルトは self.unet.config.sample_size * self.vae_scale_factor) : 生成される画像の幅(ピクセル単位)。最適な結果を得るため、デフォルトでは 1024 に設定されています。 num_inference_steps (`int`、*任意*、デフォルト値は 50) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。 sigmas (`list[float]`, *任意*) : `set_timesteps` メソッドで `sigmas` 引数をサポートするスケジューラーにおいて、デノイジングプロセスに使用するカスタムシグマ。`num_inference_steps` が渡された場合のデフォルトの動作が使用されます。 guidance_scale (`float`、*任意*、デフォルトは None) : ガイダンス蒸留モデル用のガイダンススケール値です。従来の classifier-free guidance では、推論時にノイズ予測の再スケーリングを通じてガイダンススケールが適用されますが、ガイダンス蒸留モデルでは、フォワードパス中にガイダンススケールを直接入力パラメータとして受け取ります。`guidance_scale > 1` を設定することでガイダンススケールが有効になります。ガイダンススケールを高くすると、`prompt` のテキストと密接に関連した画像の生成が促されますが、通常は画像品質の低下を伴います。このパラメータは、将来登場するガイダンス蒸留モデルをサポートするためにパイプラインに用意されています。ガイダンス蒸留モデルを使用しない場合は無視されます。従来の classifier-free guidance を有効にするには、`true_cfg_scale > 1.0` と `negative_prompt`(" " のような空の negative prompt でも classifier-free guidance の計算を有効にします)を渡してください。 control_guidance_start (`float` または `list[float]`、*任意*、デフォルト値は 0.0) : ControlNet が適用を開始するステップの割合(全体のステップ数に対するパーセンテージ)。 control_guidance_end (`float` または `list[float]`、*任意*、デフォルト値は 1.0) : ControlNet が適用を停止するステップの割合(全体のステップ数に対するパーセンテージ)。 control_image (`PipelineImageInput`、*任意*) : 生成のガイドとして提供される ControlNet の入力条件。 controlnet_conditioning_scale (`float` または `list[float]`、*任意*、デフォルト値は 1.0) : ControlNet の出力は、元の `transformer` の残差に加算される前に、`controlnet_conditioning_scale` 倍されます。 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`を使用してサンプリングを行い、ラテンツのテンソルが生成されます。 prompt_embeds (`torch.Tensor`, *任意*) : 事前生成されたテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。 prompt_embeds_mask (`torch.Tensor`, *任意*) : `prompt_embeds`用のアテンションマスク。 negative_prompt_embeds (`torch.Tensor`, *任意*) : 事前に生成されたネガティブなテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`negative_prompt` 入力引数から negative_prompt_embeds が生成されます。 negative_prompt_embeds_mask (`torch.Tensor`, *任意*) : `negative_prompt_embeds` 用のアテンションマスク。 output_type (`str`、*任意*、デフォルトは `"pil"`) : 生成画像の出力形式。[PIL](https://pillow.readthedocs.io/en/stable/)(`PIL.Image.Image`)または `np.array` から選択します。 return_dict (`bool`、*任意*、デフォルトは`True`) : プレーンなタプルではなく`~pipelines.qwenimage.QwenImagePipelineOutput`を返すかどうか。 attention_kwargs (`dict`, *任意*) : 指定された場合、[diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py) の `self.processor` で定義されている `AttentionProcessor` に渡される kwargs の辞書です。 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` 属性に列挙された変数のみを、リストに含めることができます。 max_sequence_length (`int`、デフォルトは 512) : `prompt` に使用する最大シーケンス長。 **戻り値:** `~pipelines.qwenimage.QwenImagePipelineOutput` または `tuple` `return_dict` が True の場合は `~pipelines.qwenimage.QwenImagePipelineOutput`、それ以外の場合は `tuple` を返します。tuple を返す場合、最初の要素は生成された画像のリストです。 生成用のパイプラインを呼び出したときに実行される関数。 例: ```py >>> import torch >>> from diffusers.utils import load_image >>> from diffusers import QwenImageControlNetModel, QwenImageMultiControlNetModel, QwenImageControlNetPipeline >>> # QwenImageControlNetModel >>> controlnet = QwenImageControlNetModel.from_pretrained( ... "InstantX/Qwen-Image-ControlNet-Union", torch_dtype=torch.bfloat16 ... ) >>> pipe = QwenImageControlNetPipeline.from_pretrained( ... "Qwen/Qwen-Image", controlnet=controlnet, torch_dtype=torch.bfloat16 ... ) >>> pipe.to("cuda") >>> prompt = "Aesthetics art, traditional asian pagoda, elaborate golden accents, sky blue and white color palette, swirling cloud pattern, digital illustration, east asian architecture, ornamental rooftop, intricate detailing on building, cultural representation." >>> negative_prompt = " " >>> control_image = load_image( ... "https://huggingface.co/InstantX/Qwen-Image-ControlNet-Union/resolve/main/conds/canny.png" ... ) >>> # Depending on the variant being used, the pipeline call will slightly vary. >>> # Refer to the pipeline documentation for more details. >>> image = pipe( ... prompt, ... negative_prompt=negative_prompt, ... control_image=control_image, ... controlnet_conditioning_scale=1.0, ... num_inference_steps=30, ... true_cfg_scale=4.0, ... ).images[0] >>> image.save("qwenimage_cn_union.png") >>> # QwenImageMultiControlNetModel >>> controlnet = QwenImageControlNetModel.from_pretrained( ... "InstantX/Qwen-Image-ControlNet-Union", torch_dtype=torch.bfloat16 ... ) >>> controlnet = QwenImageMultiControlNetModel([controlnet]) >>> pipe = QwenImageControlNetPipeline.from_pretrained( ... "Qwen/Qwen-Image", controlnet=controlnet, torch_dtype=torch.bfloat16 ... ) >>> pipe.to("cuda") >>> prompt = "Aesthetics art, traditional asian pagoda, elaborate golden accents, sky blue and white color palette, swirling cloud pattern, digital illustration, east asian architecture, ornamental rooftop, intricate detailing on building, cultural representation." >>> negative_prompt = " " >>> control_image = load_image( ... "https://huggingface.co/InstantX/Qwen-Image-ControlNet-Union/resolve/main/conds/canny.png" ... ) >>> # Depending on the variant being used, the pipeline call will slightly vary. >>> # Refer to the pipeline documentation for more details. >>> image = pipe( ... prompt, ... negative_prompt=negative_prompt, ... control_image=[control_image, control_image], ... controlnet_conditioning_scale=[0.5, 0.5], ... num_inference_steps=30, ... true_cfg_scale=4.0, ... ).images[0] >>> image.save("qwenimage_cn_union_multi.png") ``` #### encode_prompt[[diffusers.QwenImageControlNetPipeline.encode_prompt]] ```python encode_prompt(prompt: str | list[str], device: typing.Optional[torch.device] = None, num_images_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_embeds_mask: typing.Optional[torch.Tensor] = None, max_sequence_length: int = 1024) ``` [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage/pipeline_qwenimage_controlnet.py#L290) **パラメータ:** prompt (`str` または `list[str]`、*省略可能*) : エンコードするプロンプト device : (`torch.device`): torch デバイス num_images_per_prompt (`int`) : プロンプトごとに生成すべき画像の数 prompt_embeds (`torch.Tensor`, *任意*) : 事前生成されたテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。 ## QwenImageEditPlusPipeline[[diffusers.QwenImageEditPlusPipeline]] #### diffusers.QwenImageEditPlusPipeline[[diffusers.QwenImageEditPlusPipeline]] ```python diffusers.QwenImageEditPlusPipeline(scheduler: FlowMatchEulerDiscreteScheduler, vae: AutoencoderKLQwenImage, text_encoder: Qwen2_5_VLForConditionalGeneration, tokenizer: Qwen2Tokenizer, processor: Qwen2VLProcessor, transformer: QwenImageTransformer2DModel) ``` [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage/pipeline_qwenimage_edit_plus.py#L168) **パラメータ:** transformer ([QwenImageTransformer2DModel](/docs/diffusers/main/ja/api/models/qwenimage_transformer2d#diffusers.QwenImageTransformer2DModel)) : エンコードされた画像潜在変数をデノイズするための条件付き Transformer (MMDiT) アーキテクチャ。 scheduler ([FlowMatchEulerDiscreteScheduler](/docs/diffusers/main/ja/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler)) : `transformer` と組み合わせて、エンコードされた画像の潜在変数をデノイズするために使用するスケジューラー。 vae ([AutoencoderKL](/docs/diffusers/main/ja/api/models/autoencoderkl#diffusers.AutoencoderKL)) : 画像を潜在表現にエンコードし、潜在表現からデコードするための変分オートエンコーダ(VAE)モデル。 text_encoder (`Qwen2.5-VL-7B-Instruct`) : [Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct)、具体的には [Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct) バリアントです。 tokenizer (`Qwen2Tokenizer`) : クラス https://huggingface.co/docs/transformers/en/model_doc/qwen2#transformers.Qwen2Tokenizer の Tokenizer 画像編集用の Qwen-Image-Edit パイプライン。 #### __call__[[diffusers.QwenImageEditPlusPipeline.__call__]] ```python __call__(image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor], NoneType] = None, prompt: str | list[str] = None, negative_prompt: str | list[str] = None, true_cfg_scale: float = 4.0, height: int | None = None, width: int | None = None, num_inference_steps: int = 50, sigmas: list[float] | None = None, guidance_scale: float | None = None, num_images_per_prompt: int = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_embeds_mask: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds_mask: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, attention_kwargs: dict[str, typing.Any] | None = None, callback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], max_sequence_length: int = 512) ``` [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage/pipeline_qwenimage_edit_plus.py#L526) **パラメータ:** image (`torch.Tensor`、`PIL.Image.Image`、`np.ndarray`、`list[torch.Tensor]`、`list[PIL.Image.Image]`、または `list[np.ndarray]`) : `Image`、numpy 配列、またはテンソル。開始点として使用される画像バッチを表します。numpy 配列および PyTorch テンソルの場合、想定される値の範囲は `[0, 1]` です。テンソルまたはテンソルのリストの場合、想定される形状は `(B, C, H, W)` または `(C, H, W)` です。numpy 配列または配列のリストの場合、想定される形状は `(B, H, W, C)` または `(H, W, C)` です。`image` として画像の潜在変数(latents)を受け取ることもできますが、潜在変数を直接渡す場合は、再度エンコードされません。 prompt (`str` または `list[str]`、*省略可*) : 画像生成をガイドするためのプロンプトです。未定義の場合、代わりに `prompt_embeds` を渡す必要があります。 negative_prompt (`str` または `list[str]`、*省略可能*) : 画像生成をガイドしないプロンプトです。未定義の場合、代わりに `negative_prompt_embeds` を渡す必要があります。ガイダンスを使用していない場合は無視されます(`true_cfg_scale` が `1` 以下の場合に無視されます)。 true_cfg_scale (`float`、*任意*、デフォルト値は 1.0) : true_cfg_scale (`float`、*任意*、デフォルト値は 1.0): [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598) で定義されているガイダンススケールです。 `true_cfg_scale` は、[Imagen Paper](https://huggingface.co/papers/2205.11487) の数式 2 の `w` として定義されています。 `true_cfg_scale > 1` を設定し、`negative_prompt` を指定することで、classifier-free guidance が有効になります。ガイダンススケールを高くすると、テキスト `prompt` と密接に関連する画像の生成が促されますが、通常は画像品質の低下を伴います。 height (`int`、*任意*、デフォルトは self.unet.config.sample_size * self.vae_scale_factor) : 生成される画像のピクセル単位の縦幅。最適な結果を得るため、デフォルトでは 1024 に設定されています。 width (`int`、*任意*、デフォルトは self.unet.config.sample_size * self.vae_scale_factor) : 生成される画像の幅(ピクセル単位)。最適な結果を得るため、デフォルトでは 1024 に設定されています。 num_inference_steps (`int`、*任意*、デフォルト値は 50) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。 sigmas (`list[float]`, *任意*) : `set_timesteps` メソッドで `sigmas` 引数をサポートするスケジューラーにおいて、デノイジングプロセスに使用するカスタムシグマ。`num_inference_steps` が渡された場合のデフォルトの動作が使用されます。 guidance_scale (`float`、*任意*、デフォルトは None) : ガイダンス蒸留モデル用のガイダンススケール値です。従来の classifier-free guidance では、推論時にノイズ予測の再スケーリングを通じてガイダンススケールが適用されますが、ガイダンス蒸留モデルでは、フォワードパス中にガイダンススケールを直接入力パラメータとして受け取ります。`guidance_scale > 1` を設定することでガイダンススケールが有効になります。ガイダンススケールを高くすると、`prompt` のテキストと密接に関連した画像の生成が促されますが、通常は画像品質の低下を伴います。このパラメータは、将来登場するガイダンス蒸留モデルをサポートするためにパイプラインに用意されています。ガイダンス蒸留モデルを使用しない場合は無視されます。従来の classifier-free guidance を有効にするには、`true_cfg_scale > 1.0` と `negative_prompt`(" " のような空の negative prompt でも classifier-free guidance の計算を有効にします)を渡してください。 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`を使用してサンプリングを行い、ラテンツのテンソルが生成されます。 prompt_embeds (`torch.Tensor`, *任意*) : 事前生成されたテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。 prompt_embeds_mask (`torch.Tensor`, *任意*) : `prompt_embeds`用のアテンションマスク。 negative_prompt_embeds (`torch.Tensor`, *任意*) : 事前に生成されたネガティブなテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`negative_prompt` 入力引数から negative_prompt_embeds が生成されます。 negative_prompt_embeds_mask (`torch.Tensor`, *任意*) : `negative_prompt_embeds` 用のアテンションマスク。 output_type (`str`、*任意*、デフォルトは `"pil"`) : 生成画像の出力形式。[PIL](https://pillow.readthedocs.io/en/stable/)(`PIL.Image.Image`)または `np.array` から選択します。 return_dict (`bool`、*任意*、デフォルトは`True`) : プレーンなタプルではなく`~pipelines.qwenimage.QwenImagePipelineOutput`を返すかどうか。 attention_kwargs (`dict`, *任意*) : 指定された場合、[diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py) の `self.processor` で定義されている `AttentionProcessor` に渡される kwargs の辞書です。 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` 属性に列挙された変数のみを、リストに含めることができます。 max_sequence_length (`int`、デフォルトは 512) : `prompt` に使用する最大シーケンス長。 **戻り値:** `~pipelines.qwenimage.QwenImagePipelineOutput` または `tuple` `return_dict` が True の場合は `~pipelines.qwenimage.QwenImagePipelineOutput`、それ以外の場合は `tuple` を返します。tuple を返す場合、最初の要素は生成された画像のリストです。 生成用のパイプラインを呼び出したときに実行される関数。 例: ```py >>> import torch >>> from PIL import Image >>> from diffusers import QwenImageEditPlusPipeline >>> from diffusers.utils import load_image >>> pipe = QwenImageEditPlusPipeline.from_pretrained("Qwen/Qwen-Image-Edit-2509", torch_dtype=torch.bfloat16) >>> pipe.to("cuda") >>> image = load_image( ... "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/yarn-art-pikachu.png" ... ).convert("RGB") >>> prompt = ( ... "Make Pikachu hold a sign that says 'Qwen Edit is awesome', yarn art style, detailed, vibrant colors" ... ) >>> # Depending on the variant being used, the pipeline call will slightly vary. >>> # Refer to the pipeline documentation for more details. >>> image = pipe(image, prompt, num_inference_steps=50).images[0] >>> image.save("qwenimage_edit_plus.png") ``` #### encode_prompt[[diffusers.QwenImageEditPlusPipeline.encode_prompt]] ```python encode_prompt(prompt: str | list[str], image: typing.Optional[torch.Tensor] = None, device: typing.Optional[torch.device] = None, num_images_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_embeds_mask: typing.Optional[torch.Tensor] = None, max_sequence_length: int = 1024) ``` [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage/pipeline_qwenimage_edit_plus.py#L286) **パラメータ:** prompt (`str` または `list[str]`、*省略可能*) : エンコードするプロンプト image (`torch.Tensor`, *任意*) : エンコードする画像 device : (`torch.device`): torch デバイス num_images_per_prompt (`int`) : プロンプトごとに生成すべき画像の数 prompt_embeds (`torch.Tensor`, *任意*) : 事前生成されたテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。 ## QwenImageLayeredPipeline[[diffusers.QwenImageLayeredPipeline]] #### diffusers.QwenImageLayeredPipeline[[diffusers.QwenImageLayeredPipeline]] ```python diffusers.QwenImageLayeredPipeline(scheduler: FlowMatchEulerDiscreteScheduler, vae: AutoencoderKLQwenImage, text_encoder: Qwen2_5_VLForConditionalGeneration, tokenizer: Qwen2Tokenizer, processor: Qwen2VLProcessor, transformer: QwenImageTransformer2DModel) ``` [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage/pipeline_qwenimage_layered.py#L174) **パラメータ:** transformer ([QwenImageTransformer2DModel](/docs/diffusers/main/ja/api/models/qwenimage_transformer2d#diffusers.QwenImageTransformer2DModel)) : エンコードされた画像潜在変数をデノイズするための条件付き Transformer (MMDiT) アーキテクチャ。 scheduler ([FlowMatchEulerDiscreteScheduler](/docs/diffusers/main/ja/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler)) : `transformer` と組み合わせて、エンコードされた画像の潜在変数をデノイズするために使用するスケジューラー。 vae ([AutoencoderKL](/docs/diffusers/main/ja/api/models/autoencoderkl#diffusers.AutoencoderKL)) : 画像を潜在表現にエンコードし、潜在表現からデコードするための変分オートエンコーダ(VAE)モデル。 text_encoder (`Qwen2.5-VL-7B-Instruct`) : [Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct)、具体的には [Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct) バリアントです。 tokenizer (`Qwen2Tokenizer`) : クラス https://huggingface.co/docs/transformers/en/model_doc/qwen2#transformers.Qwen2Tokenizer の Tokenizer 画像分解用の Qwen-Image-Layered パイプライン。 #### __call__[[diffusers.QwenImageLayeredPipeline.__call__]] ```python __call__(image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor], NoneType] = None, prompt: str | list[str] = None, negative_prompt: str | list[str] = None, true_cfg_scale: float = 4.0, layers: int | None = 4, num_inference_steps: int = 50, sigmas: list[float] | None = None, guidance_scale: float | None = None, num_images_per_prompt: int = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_embeds_mask: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds_mask: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, attention_kwargs: dict[str, typing.Any] | None = None, callback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], max_sequence_length: int = 512, resolution: int = 640, cfg_normalize: bool = False, use_en_prompt: bool = False) ``` [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage/pipeline_qwenimage_layered.py#L537) **パラメータ:** image (`torch.Tensor`、`PIL.Image.Image`、`np.ndarray`、`list[torch.Tensor]`、`list[PIL.Image.Image]`、または `list[np.ndarray]`) : `Image`、numpy 配列、またはテンソル。開始点として使用される画像バッチを表します。numpy 配列および PyTorch テンソルの場合、想定される値の範囲は `[0, 1]` です。テンソルまたはテンソルのリストの場合、想定される形状は `(B, C, H, W)` または `(C, H, W)` です。numpy 配列または配列のリストの場合、想定される形状は `(B, H, W, C)` または `(H, W, C)` です。`image` として画像の潜在変数(latents)を受け取ることもできますが、潜在変数を直接渡す場合は、再度エンコードされません。 prompt (`str` または `list[str]`、*省略可*) : 画像生成をガイドするためのプロンプトです。未定義の場合、代わりに `prompt_embeds` を渡す必要があります。 negative_prompt (`str` または `list[str]`、*省略可能*) : 画像生成をガイドしないプロンプトです。未定義の場合、代わりに `negative_prompt_embeds` を渡す必要があります。ガイダンスを使用していない場合は無視されます(`true_cfg_scale` が `1` 以下の場合に無視されます)。 true_cfg_scale (`float`、*任意*、デフォルト値は 1.0) : true_cfg_scale (`float`、*任意*、デフォルト値は 1.0): [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598) で定義されているガイダンススケールです。 `true_cfg_scale` は、[Imagen Paper](https://huggingface.co/papers/2205.11487) の数式 2 の `w` として定義されています。 `true_cfg_scale > 1` を設定し、`negative_prompt` を指定することで、classifier-free guidance が有効になります。ガイダンススケールを高くすると、テキスト `prompt` と密接に関連する画像の生成が促されますが、通常は画像品質の低下を伴います。 layers (`int`、*任意*、デフォルトは 4) : 階層化された出力を生成するための潜在層の数。 num_inference_steps (`int`、*任意*、デフォルト値は 50) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。 sigmas (`list[float]`, *任意*) : `set_timesteps` メソッドで `sigmas` 引数をサポートするスケジューラーにおいて、デノイジングプロセスに使用するカスタムシグマ。`num_inference_steps` が渡された場合のデフォルトの動作が使用されます。 guidance_scale (`float`、*任意*、デフォルトは None) : ガイダンス蒸留モデル用のガイダンススケール値です。従来の classifier-free guidance では、推論時にノイズ予測の再スケーリングを通じてガイダンススケールが適用されますが、ガイダンス蒸留モデルでは、フォワードパス中にガイダンススケールを直接入力パラメータとして受け取ります。`guidance_scale > 1` を設定することでガイダンススケールが有効になります。ガイダンススケールを高くすると、`prompt` のテキストと密接に関連した画像の生成が促されますが、通常は画像品質の低下を伴います。このパラメータは、将来登場するガイダンス蒸留モデルをサポートするためにパイプラインに用意されています。ガイダンス蒸留モデルを使用しない場合は無視されます。従来の classifier-free guidance を有効にするには、`true_cfg_scale > 1.0` と `negative_prompt`(" " のような空の negative prompt でも classifier-free guidance の計算を有効にします)を渡してください。 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`を使用してサンプリングを行い、ラテンツのテンソルが生成されます。 prompt_embeds (`torch.Tensor`, *任意*) : 事前生成されたテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。 prompt_embeds_mask (`torch.Tensor`, *任意*) : `prompt_embeds`用のアテンションマスク。 negative_prompt_embeds (`torch.Tensor`, *任意*) : 事前に生成されたネガティブなテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`negative_prompt` 入力引数から negative_prompt_embeds が生成されます。 negative_prompt_embeds_mask (`torch.Tensor`, *任意*) : `negative_prompt_embeds` 用のアテンションマスク。 output_type (`str`、*任意*、デフォルトは `"pil"`) : 生成画像の出力形式。[PIL](https://pillow.readthedocs.io/en/stable/)(`PIL.Image.Image`)または `np.array` から選択します。 return_dict (`bool`、*任意*、デフォルトは`True`) : プレーンなタプルではなく`~pipelines.qwenimage.QwenImagePipelineOutput`を返すかどうか。 attention_kwargs (`dict`, *任意*) : 指定された場合、[diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py) の `self.processor` で定義されている `AttentionProcessor` に渡される kwargs の辞書です。 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` 属性にリストされている変数のみを包含できます。 max_sequence_length (`int`、デフォルトは 512) : `prompt` に使用する最大シーケンス長。 resolution (`int`、*optional*、デフォルトは 640) : (640, 1024) の異なるバケットを使用して、条件と出力の解像度を決定します cfg_normalize (`bool`、*任意*、デフォルトは`False`) : cfg の正規化を有効にするかどうか。 use_en_prompt (`bool`、*任意*、デフォルトは `False`) : ユーザーがキャプションを提供しない場合のキャプションの自動言語 **戻り値:** `~pipelines.qwenimage.QwenImagePipelineOutput` または `tuple` `return_dict` が True の場合は `~pipelines.qwenimage.QwenImagePipelineOutput`、それ以外の場合は `tuple` を返します。tuple を返す場合、最初の要素は生成された画像のリストです。 生成用のパイプラインを呼び出したときに実行される関数。 例: ```py >>> import torch >>> from PIL import Image >>> from diffusers import QwenImageLayeredPipeline >>> from diffusers.utils import load_image >>> pipe = QwenImageLayeredPipeline.from_pretrained("Qwen/Qwen-Image-Layered", torch_dtype=torch.bfloat16) >>> pipe.to("cuda") >>> image = load_image( ... "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/yarn-art-pikachu.png" ... ).convert("RGBA") >>> prompt = "" >>> # Depending on the variant being used, the pipeline call will slightly vary. >>> # Refer to the pipeline documentation for more details. >>> images = pipe( ... image, ... prompt, ... num_inference_steps=50, ... true_cfg_scale=4.0, ... layers=4, ... resolution=640, ... cfg_normalize=False, ... use_en_prompt=True, ... ).images[0] >>> for i, image in enumerate(images): ... image.save(f"{i}.out.png") ``` #### encode_prompt[[diffusers.QwenImageLayeredPipeline.encode_prompt]] ```python encode_prompt(prompt: str | list[str], device: typing.Optional[torch.device] = None, num_images_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_embeds_mask: typing.Optional[torch.Tensor] = None, max_sequence_length: int = 1024) ``` [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage/pipeline_qwenimage_layered.py#L291) **パラメータ:** prompt (`str` または `list[str]`、*省略可能*) : エンコードするプロンプト device : (`torch.device`): torch デバイス num_images_per_prompt (`int`) : プロンプトごとに生成すべき画像の数 prompt_embeds (`torch.Tensor`, *任意*) : 事前生成されたテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。 ## QwenImagePipelineOutput[[diffusers.pipelines.qwenimage.pipeline_output.QwenImagePipelineOutput]] #### diffusers.pipelines.qwenimage.pipeline_output.QwenImagePipelineOutput[[diffusers.pipelines.qwenimage.pipeline_output.QwenImagePipelineOutput]] ```python diffusers.pipelines.qwenimage.pipeline_output.QwenImagePipelineOutput(images: list[PIL.Image.Image] | numpy.ndarray) ``` [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage/pipeline_output.py#L10) **パラメータ:** images (`list[PIL.Image.Image]` または `np.ndarray`) : 長さ `batch_size` のデノイズ済み PIL イメージのリスト、または形状 `(batch_size, height, width, num_channels)` の numpy 配列。PIL イメージまたは numpy 配列は、拡散パイプラインのデノイズ済みイメージを表します。 Stable Diffusion パイプライン用の出力クラスです。
#
# Apache License, Version 2.0(「ライセンス」)の下でライセンスされています。
# このファイルは、ライセンスに準拠した場合にのみ使用できます。
# ライセンスのコピーは以下から入手できます
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 適用される法律で要求される場合、または書面による合意がある場合を除き、ソフトウェア
# ライセンスに基づき配布される本ソフトウェアは、「現状のまま」
# 明示的または黙示的を問わず、いかなる種類の保証や条件も付随しません。
# 権限を管理する特定の言語については、ライセンスを参照してください。
# ライセンスの下での制限。-->
# QwenImage
QwenチームによるQwen-Imageは、Qwenシリーズの画像生成基盤モデルであり、複雑なテキストレンダリングと精密な画像編集において大きな進歩を遂げています。実験により、画像生成および編集の両方で優れた汎用性が示されており、特に中国語におけるテキストレンダリングで卓越したパフォーマンスを発揮しています。
Qwen-Imageには、以下のバリエーションがあります。
| モデルタイプ | モデルID |
|:----------:|:--------:|
| Qwen-Image | [`Qwen/Qwen-Image`](https://huggingface.co/Qwen/Qwen-Image) |
| Qwen-Image-Edit | [`Qwen/Qwen-Image-Edit`](https://huggingface.co/Qwen/Qwen-Image-Edit) |
| Qwen-Image-Edit Plus | [Qwen/Qwen-Image-Edit-2509](https://huggingface.co/Qwen/Qwen-Image-Edit-2509) |
> [!TIP]
> [Caching](../../optimization/cache)ガイドを参照し、中間出力を保存して再利用することで推論を高速化できます。
## より高速な推論のためのLoRA
`lightx2v/Qwen-Image-Lightning` の LoRA を使用して、ステップ数を減らし、推論を高速化します。以下のコードスニペットを参照してください。
コード
```py
from diffusers import DiffusionPipeline, FlowMatchEulerDiscreteScheduler
import torch
import math
ckpt_id = "Qwen/Qwen-Image"
# From
# https://github.com/ModelTC/Qwen-Image-Lightning/blob/342260e8f5468d2f24d084ce04f55e101007118b/generate_with_diffusers.py#L82C9-L97C10
scheduler_config = {
"base_image_seq_len": 256,
"base_shift": math.log(3), # We use shift=3 in distillation
"invert_sigmas": False,
"max_image_seq_len": 8192,
"max_shift": math.log(3), # We use shift=3 in distillation
"num_train_timesteps": 1000,
"shift": 1.0,
"shift_terminal": None, # set shift_terminal to None
"stochastic_sampling": False,
"time_shift_type": "exponential",
"use_beta_sigmas": False,
"use_dynamic_shifting": True,
"use_exponential_sigmas": False,
"use_karras_sigmas": False,
}
scheduler = FlowMatchEulerDiscreteScheduler.from_config(scheduler_config)
pipe = DiffusionPipeline.from_pretrained(
ckpt_id, scheduler=scheduler, dtype=torch.bfloat16
).to("cuda") # or "mps", "xpu", "cpu"
pipe.load_lora_weights(
"lightx2v/Qwen-Image-Lightning", weight_name="Qwen-Image-Lightning-8steps-V1.0.safetensors"
)
prompt = "a tiny astronaut hatching from an egg on the moon, Ultra HD, 4K, cinematic composition."
negative_prompt = " "
image = pipe(
prompt=prompt,
negative_prompt=negative_prompt,
width=1024,
height=1024,
num_inference_steps=8,
true_cfg_scale=1.0,
generator=torch.manual_seed(0),
).images[0]
image.save("qwen_fewsteps.png")
```
> [!TIP]
> パイプラインの `guidance_scale` パラメータは、将来リリースされるガイダンス蒸留モデルをサポートするために用意されています。なお、パイプラインに `guidance_scale` を渡しても効果はありません。Classifier-free guidance を有効にするには、`true_cfg_scale` と `negative_prompt` を渡してください(" " のような空の negative prompt でも、classifier-free guidance の計算は有効になります)。
## QwenImageEditPlusPipelineによる複数画像参照
[QwenImageEditPlusPipeline](/docs/diffusers/main/ja/api/pipelines/qwenimage#diffusers.QwenImageEditPlusPipeline)では、複数の画像を入力リファレンスとして指定できます。
```py
import torch
from PIL import Image
from diffusers import QwenImageEditPlusPipeline
from diffusers.utils import load_image
pipe = QwenImageEditPlusPipeline.from_pretrained(
"Qwen/Qwen-Image-Edit-2509", dtype=torch.bfloat16
).to("cuda") # or "mps", "xpu", "cpu"

Xet Storage Details

Size:
120 kB
·
Xet hash:
7ec9066fd14652ebeafcf5799bca1831843b2b347da81f9c952f66f005ef2d06

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