Diffusers documentation

QwenImage

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v0.42.1).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

QwenImage

LoRA

Qwen 팀의 Qwen-Image는 Qwen 시리즈의 이미지 생성 기반 모델로, 복잡한 텍스트 렌더링과 정밀한 이미지 편집에서 상당한 진전을 이루었습니다. 실험 결과, 이미지 생성 및 편집 전반에서 강력한 범용 역량을 보여주며, 특히 중국어 텍스트 렌더링에서 뛰어난 성능을 발휘합니다.

Qwen-Image는 다음 변형으로 제공됩니다:

모델 유형모델 ID
Qwen-ImageQwen/Qwen-Image
Qwen-Image-EditQwen/Qwen-Image-Edit
Qwen-Image-Edit PlusQwen/Qwen-Image-Edit-2509

중간 출력을 저장하고 재사용하여 추론 속도를 높이는 방법에 대해 Caching 가이드를 참조하세요.

LoRA를 통한 더 빠른 추론

lightx2v/Qwen-Image-Lightning의 LoRA를 사용하여 단계 수를 줄여 추론 속도를 높입니다. 아래 코드 스니펫을 참조하세요:

Code
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")

파이프라인의 guidance_scale 매개변수는 향후 guidance-distilled 모델이 등장할 때 이를 지원하기 위해 존재합니다. 참고로 파이프라인에 guidance_scale를 전달하는 것은 효과가 없습니다. classifier-free guidance를 활성화하려면 true_cfg_scale와 negative_prompt를 전달하십시오(” ”과 같은 빈 negative prompt도 classifier-free guidance 계산을 활성화해야 합니다).

QwenImageEditPlusPipeline를 사용한 다중 이미지 참조

QwenImageEditPlusPipeline를 사용하면 여러 이미지를 입력 참조로 제공할 수 있습니다.

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):

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)를 사용할 때, 파이프라인은 attention masking을 통해 패딩을 적절히 처리합니다. 이를 통해 패딩 토큰이 생성된 출력에 영향을 미치지 않도록 보장합니다.

# 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를 참조하세요.

QwenImagePipeline

클래스 diffusers.QwenImagePipeline

< >

( scheduler: FlowMatchEulerDiscreteSchedulervae: AutoencoderKLQwenImagetext_encoder: Qwen2_5_VLForConditionalGenerationtokenizer: Qwen2Tokenizertransformer: QwenImageTransformer2DModel )

매개변수

텍스트에서 이미지 생성을 위한 QwenImage 파이프라인.

__call__

< >

( prompt: str | list[str] = Nonenegative_prompt: str | list[str] = Nonetrue_cfg_scale: float = 4.0height: int | None = Nonewidth: int | None = Nonenum_inference_steps: int = 50sigmas: list[float] | None = Noneguidance_scale: float | None = Nonenum_images_per_prompt: int = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneprompt_embeds: typing.Optional[torch.Tensor] = Noneprompt_embeds_mask: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds_mask: typing.Optional[torch.Tensor] = Noneoutput_type: str | None = 'pil'return_dict: bool = Trueattention_kwargs: dict[str, typing.Any] | None = Nonecallback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 512 ) → ~pipelines.qwenimage.QwenImagePipelineOutput or tuple

매개변수

  • 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에서 정의된 guidance scale입니다. true_cfg_scale은 Imagen Paper의 방정식 2의 w로 정의됩니다. true_cfg_scale > 1을 설정하고 negative_prompt를 제공하면 classifier-free guidance가 활성화됩니다. guidance scale이 높을수록 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) — guidance distilled 모델에 사용할 guidance scale 값입니다. 추론 시 노이즈 예측 rescaling을 통해 guidance scale을 적용하는 전통적인 classifier-free guidance와 달리, guidance distilled 모델은 forward pass 과정에서 guidance scale을 직접 입력 파라미터로 받습니다. guidance_scale > 1로 설정하면 guidance scale이 활성화됩니다. guidance scale이 높을수록 prompt 텍스트와 밀접하게 연결된 이미지를 생성하도록 장려되며, 일반적으로 이미지 품질 저하를 대가로 합니다. 이 파이프라인의 해당 파라미터는 향후 등장할 guidance-distilled 모델을 지원하기 위해 존재합니다. guidance distilled 모델을 사용하지 않는 경우 무시됩니다. 전통적인 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 generator 하나 또는 목록
  • latents (torch.Tensor, 선택 사항) — 이미지 생성의 입력으로 사용할 가우시안 분포에서 샘플링된 사전 생성된 노이즈 latents입니다. 동일한 생성을 다른 프롬프트로 조정하는 데 사용할 수 있습니다. 제공되지 않으면, 제공된 랜덤 generator를 사용하여 샘플링하여 latents 텐서가 생성됩니다.
  • prompt_embeds (torch.Tensor, 선택) — 미리 생성된 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩이 생성됩니다.
  • prompt_embeds_mask (torch.Tensor, 선택 사항) — prompt_embeds에 대한 어텐션 마스크입니다.
  • negative_prompt_embeds (torch.Tensor, 선택 사항) — 미리 생성된 negative text embeddings입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 negative_prompt 입력 인자로부터 negative_prompt_embeds가 생성됩니다.
  • negative_prompt_embeds_mask (torch.Tensor, 선택 사항) — negative_prompt_embeds에 대한 어텐션 마스크입니다.
  • output_type (str, 선택 사항, 기본값 "pil") — 이미지 생성의 출력 형식입니다. PIL: PIL.Image.Image 또는 np.array 중 하나를 선택합니다.
  • return_dict (bool, 선택 사항, 기본값 True) — 일반 튜플 대신 ~pipelines.qwenimage.QwenImagePipelineOutput를 반환할지 여부.
  • attention_kwargs (dict, 선택 사항) — 지정된 경우 diffusers.models.attention_processor의 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을 반환할 경우 첫 번째 요소는 생성된 이미지가 포함된 리스트입니다.

생성을 위해 파이프라인을 호출할 때 호출되는 함수.

예:

>>> 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

< >

( prompt: str | list[str]device: typing.Optional[torch.device] = Nonenum_images_per_prompt: int = 1prompt_embeds: typing.Optional[torch.Tensor] = Noneprompt_embeds_mask: typing.Optional[torch.Tensor] = Nonemax_sequence_length: int = 1024 )

매개변수

  • prompt (str 또는 list[str], 선택 사항) — 인코딩할 프롬프트
  • device — (torch.device): torch device
  • num_images_per_prompt (int) — 프롬프트당 생성할 이미지 수
  • prompt_embeds (torch.Tensor, 선택) — 미리 생성된 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩이 생성됩니다.

QwenImageImg2ImgPipeline

클래스 diffusers.QwenImageImg2ImgPipeline

< >

( scheduler: FlowMatchEulerDiscreteSchedulervae: AutoencoderKLQwenImagetext_encoder: Qwen2_5_VLForConditionalGenerationtokenizer: Qwen2Tokenizertransformer: QwenImageTransformer2DModel )

매개변수

텍스트에서 이미지 생성을 위한 QwenImage 파이프라인.

__call__

< >

( prompt: str | list[str] = Nonenegative_prompt: str | list[str] = Nonetrue_cfg_scale: float = 4.0image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]] = Noneheight: int | None = Nonewidth: int | None = Nonestrength: float = 0.6num_inference_steps: int = 50sigmas: list[float] | None = Noneguidance_scale: float | None = Nonenum_images_per_prompt: int = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneprompt_embeds: typing.Optional[torch.Tensor] = Noneprompt_embeds_mask: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds_mask: typing.Optional[torch.Tensor] = Noneoutput_type: str | None = 'pil'return_dict: bool = Trueattention_kwargs: dict[str, typing.Any] | None = Nonecallback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 512 ) → ~pipelines.qwenimage.QwenImagePipelineOutput or tuple

매개변수

  • 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]입니다. 텐서 또는 텐서 목록인 경우 예상 shape은 (B, C, H, W) 또는 (C, H, W)여야 합니다. numpy 배열 또는 배열 목록인 경우 예상 shape은 (B, H, W, C) 또는 (H, W, C)여야 합니다. image로 이미지 latents도 받을 수 있지만, latents를 직접 전달하는 경우 다시 인코딩되지 않습니다.
  • true_cfg_scale (float, 선택 사항, 기본값 1.0) — Classifier-Free Diffusion Guidance에서 정의된 guidance scale입니다. true_cfg_scale은 Imagen Paper의 방정식 2의 w로 정의됩니다. true_cfg_scale > 1을 설정하고 negative_prompt를 제공하면 classifier-free guidance가 활성화됩니다. guidance scale이 높을수록 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) — guidance distilled 모델에 사용할 guidance scale 값입니다. 추론 시 노이즈 예측 rescaling을 통해 guidance scale을 적용하는 전통적인 classifier-free guidance와 달리, guidance distilled 모델은 forward pass 과정에서 guidance scale을 직접 입력 파라미터로 받습니다. guidance_scale > 1로 설정하면 guidance scale이 활성화됩니다. guidance scale이 높을수록 prompt 텍스트와 밀접하게 연결된 이미지를 생성하도록 장려되며, 일반적으로 이미지 품질 저하를 대가로 합니다. 이 파이프라인의 해당 파라미터는 향후 등장할 guidance-distilled 모델을 지원하기 위해 존재합니다. guidance distilled 모델을 사용하지 않는 경우 무시됩니다. 전통적인 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 generator 하나 또는 목록
  • latents (torch.Tensor, 선택 사항) — 이미지 생성의 입력으로 사용할 가우시안 분포에서 샘플링된 사전 생성된 노이즈 latents입니다. 동일한 생성을 다른 프롬프트로 조정하는 데 사용할 수 있습니다. 제공되지 않으면, 제공된 랜덤 generator를 사용하여 샘플링하여 latents 텐서가 생성됩니다.
  • prompt_embeds (torch.Tensor, 선택) — 미리 생성된 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩이 생성됩니다.
  • prompt_embeds_mask (torch.Tensor, 선택 사항) — prompt_embeds에 대한 어텐션 마스크입니다.
  • negative_prompt_embeds (torch.Tensor, 선택 사항) — 미리 생성된 negative text embeddings입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 negative_prompt 입력 인자로부터 negative_prompt_embeds가 생성됩니다.
  • negative_prompt_embeds_mask (torch.Tensor, 선택 사항) — negative_prompt_embeds에 대한 어텐션 마스크입니다.
  • output_type (str, 선택 사항, 기본값 "pil") — 이미지 생성의 출력 형식입니다. PIL: PIL.Image.Image 또는 np.array 중 하나를 선택합니다.
  • return_dict (bool, 선택 사항, 기본값 True) — 일반 튜플 대신 ~pipelines.qwenimage.QwenImagePipelineOutput를 반환할지 여부.
  • attention_kwargs (dict, 선택 사항) — 지정된 경우 diffusers.models.attention_processor의 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을 반환할 경우 첫 번째 요소는 생성된 이미지가 포함된 리스트입니다.

생성을 위해 파이프라인을 호출할 때 호출되는 함수.

예:

>>> 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

< >

( prompt: str | list[str]device: typing.Optional[torch.device] = Nonenum_images_per_prompt: int = 1prompt_embeds: typing.Optional[torch.Tensor] = Noneprompt_embeds_mask: typing.Optional[torch.Tensor] = Nonemax_sequence_length: int = 1024 )

매개변수

  • prompt (str 또는 list[str], 선택 사항) — 인코딩할 프롬프트
  • device — (torch.device): torch device
  • num_images_per_prompt (int) — 프롬프트당 생성할 이미지 수
  • prompt_embeds (torch.Tensor, 선택) — 미리 생성된 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩이 생성됩니다.

QwenImageInpaintPipeline

클래스 diffusers.QwenImageInpaintPipeline

< >

( scheduler: FlowMatchEulerDiscreteSchedulervae: AutoencoderKLQwenImagetext_encoder: Qwen2_5_VLForConditionalGenerationtokenizer: Qwen2Tokenizertransformer: QwenImageTransformer2DModel )

매개변수

텍스트에서 이미지 생성을 위한 QwenImage 파이프라인.

__call__

< >

( prompt: str | list[str] = Nonenegative_prompt: str | list[str] = Nonetrue_cfg_scale: float = 4.0image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]] = Nonemask_image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]] = Nonemasked_image_latents: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]] = Noneheight: int | None = Nonewidth: int | None = Nonepadding_mask_crop: int | None = Nonestrength: float = 0.6num_inference_steps: int = 50sigmas: list[float] | None = Noneguidance_scale: float | None = Nonenum_images_per_prompt: int = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneprompt_embeds: typing.Optional[torch.Tensor] = Noneprompt_embeds_mask: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds_mask: typing.Optional[torch.Tensor] = Noneoutput_type: str | None = 'pil'return_dict: bool = Trueattention_kwargs: dict[str, typing.Any] | None = Nonecallback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 512 ) → ~pipelines.qwenimage.QwenImagePipelineOutput or tuple

매개변수

  • 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]입니다. 텐서 또는 텐서 목록인 경우 예상 shape은 (B, C, H, W) 또는 (C, H, W)여야 합니다. numpy 배열 또는 배열 목록인 경우 예상 shape은 (B, H, W, C) 또는 (H, W, C)여야 합니다. image로 이미지 latents도 받을 수 있지만, latents를 직접 전달하는 경우 다시 인코딩되지 않습니다.
  • true_cfg_scale (float, 선택 사항, 기본값 1.0) — Classifier-Free Diffusion Guidance에서 정의된 guidance scale입니다. true_cfg_scale은 Imagen Paper의 방정식 2의 w로 정의됩니다. true_cfg_scale > 1을 설정하고 negative_prompt를 제공하면 classifier-free guidance가 활성화됩니다. guidance scale이 높을수록 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개 대신 하나의 색상 채널(L)을 포함해야 하므로, pytorch 텐서의 예상 shape은 (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에 의해 마스크 latents 텐서가 생성됩니다.
  • 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) — guidance distilled 모델에 사용할 guidance scale 값입니다. 추론 시 노이즈 예측 rescaling을 통해 guidance scale을 적용하는 전통적인 classifier-free guidance와 달리, guidance distilled 모델은 forward pass 과정에서 guidance scale을 직접 입력 파라미터로 받습니다. guidance_scale > 1로 설정하면 guidance scale이 활성화됩니다. guidance scale이 높을수록 prompt 텍스트와 밀접하게 연결된 이미지를 생성하도록 장려되며, 일반적으로 이미지 품질 저하를 대가로 합니다. 이 파이프라인의 해당 파라미터는 향후 등장할 guidance-distilled 모델을 지원하기 위해 존재합니다. guidance distilled 모델을 사용하지 않는 경우 무시됩니다. 전통적인 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 generator 하나 또는 목록
  • latents (torch.Tensor, 선택 사항) — 이미지 생성의 입력으로 사용할 가우시안 분포에서 샘플링된 사전 생성된 노이즈 latents입니다. 동일한 생성을 다른 프롬프트로 조정하는 데 사용할 수 있습니다. 제공되지 않으면, 제공된 랜덤 generator를 사용하여 샘플링하여 latents 텐서가 생성됩니다.
  • prompt_embeds (torch.Tensor, 선택) — 미리 생성된 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩이 생성됩니다.
  • prompt_embeds_mask (torch.Tensor, 선택 사항) — prompt_embeds에 대한 어텐션 마스크입니다.
  • negative_prompt_embeds (torch.Tensor, 선택 사항) — 미리 생성된 negative text embeddings입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 negative_prompt 입력 인자로부터 negative_prompt_embeds가 생성됩니다.
  • negative_prompt_embeds_mask (torch.Tensor, 선택 사항) — negative_prompt_embeds에 대한 어텐션 마스크입니다.
  • output_type (str, 선택 사항, 기본값 "pil") — 이미지 생성의 출력 형식입니다. PIL: PIL.Image.Image 또는 np.array 중 하나를 선택합니다.
  • return_dict (bool, 선택 사항, 기본값 True) — 일반 튜플 대신 ~pipelines.qwenimage.QwenImagePipelineOutput를 반환할지 여부.
  • attention_kwargs (dict, 선택 사항) — 지정된 경우 diffusers.models.attention_processor의 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을 반환할 경우 첫 번째 요소는 생성된 이미지가 포함된 리스트입니다.

생성을 위해 파이프라인을 호출할 때 호출되는 함수.

예:

>>> 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

< >

( prompt: str | list[str]device: typing.Optional[torch.device] = Nonenum_images_per_prompt: int = 1prompt_embeds: typing.Optional[torch.Tensor] = Noneprompt_embeds_mask: typing.Optional[torch.Tensor] = Nonemax_sequence_length: int = 1024 )

매개변수

  • prompt (str 또는 list[str], 선택 사항) — 인코딩할 프롬프트
  • device — (torch.device): torch device
  • num_images_per_prompt (int) — 프롬프트당 생성할 이미지 수
  • prompt_embeds (torch.Tensor, 선택) — 미리 생성된 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩이 생성됩니다.

QwenImageEditPipeline

클래스 diffusers.QwenImageEditPipeline

< >

( scheduler: FlowMatchEulerDiscreteSchedulervae: AutoencoderKLQwenImagetext_encoder: Qwen2_5_VLForConditionalGenerationtokenizer: Qwen2Tokenizerprocessor: Qwen2VLProcessortransformer: QwenImageTransformer2DModel )

매개변수

이미지 편집을 위한 Qwen-Image-Edit 파이프라인.

__call__

< >

( image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor], NoneType] = Noneprompt: str | list[str] = Nonenegative_prompt: str | list[str] = Nonetrue_cfg_scale: float = 4.0height: int | None = Nonewidth: int | None = Nonenum_inference_steps: int = 50sigmas: list[float] | None = Noneguidance_scale: float | None = Nonenum_images_per_prompt: int = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneprompt_embeds: typing.Optional[torch.Tensor] = Noneprompt_embeds_mask: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds_mask: typing.Optional[torch.Tensor] = Noneoutput_type: str | None = 'pil'return_dict: bool = Trueattention_kwargs: dict[str, typing.Any] | None = Nonecallback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 512 ) → ~pipelines.qwenimage.QwenImagePipelineOutput or tuple

매개변수

  • image (torch.Tensor, PIL.Image.Image, np.ndarray, list[torch.Tensor], list[PIL.Image.Image] 또는 list[np.ndarray]) — 시작점으로 사용할 이미지 배치의 Image, numpy 배열 또는 텐서를 나타냅니다. numpy 배열과 pytorch 텐서 모두에서 예상 값 범위는 [0, 1]입니다. 텐서 또는 텐서 목록인 경우 예상 shape은 (B, C, H, W) 또는 (C, H, W)여야 합니다. numpy 배열 또는 배열 목록인 경우 예상 shape은 (B, H, W, C) 또는 (H, W, C)여야 합니다. image로 이미지 latents도 받을 수 있지만, 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에서 정의된 가이던스 스케일입니다. true_cfg_scale은 Imagen Paper의 방정식 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) — guidance distilled 모델에 사용할 guidance scale 값입니다. 추론 시 노이즈 예측 rescaling을 통해 guidance scale을 적용하는 전통적인 classifier-free guidance와 달리, guidance distilled 모델은 forward pass 과정에서 guidance scale을 직접 입력 파라미터로 받습니다. guidance_scale > 1로 설정하면 guidance scale이 활성화됩니다. guidance scale이 높을수록 prompt 텍스트와 밀접하게 연결된 이미지를 생성하도록 장려되며, 일반적으로 이미지 품질 저하를 대가로 합니다. 이 파이프라인의 해당 파라미터는 향후 등장할 guidance-distilled 모델을 지원하기 위해 존재합니다. guidance distilled 모델을 사용하지 않는 경우 무시됩니다. 전통적인 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 generator 하나 또는 목록
  • latents (torch.Tensor, 선택 사항) — 이미지 생성의 입력으로 사용할 가우시안 분포에서 샘플링된 사전 생성된 노이즈 latents입니다. 동일한 생성을 다른 프롬프트로 조정하는 데 사용할 수 있습니다. 제공되지 않으면, 제공된 랜덤 generator를 사용하여 샘플링하여 latents 텐서가 생성됩니다.
  • prompt_embeds (torch.Tensor, 선택) — 미리 생성된 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩이 생성됩니다.
  • prompt_embeds_mask (torch.Tensor, 선택 사항) — prompt_embeds에 대한 어텐션 마스크입니다.
  • negative_prompt_embeds (torch.Tensor, 선택 사항) — 미리 생성된 negative text embeddings입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 negative_prompt 입력 인자로부터 negative_prompt_embeds가 생성됩니다.
  • negative_prompt_embeds_mask (torch.Tensor, 선택 사항) — negative_prompt_embeds에 대한 어텐션 마스크입니다.
  • output_type (str, 선택 사항, 기본값 "pil") — 이미지 생성의 출력 형식입니다. PIL: PIL.Image.Image 또는 np.array 중 하나를 선택합니다.
  • return_dict (bool, 선택 사항, 기본값 True) — 일반 튜플 대신 ~pipelines.qwenimage.QwenImagePipelineOutput를 반환할지 여부.
  • attention_kwargs (dict, 선택 사항) — 지정된 경우 diffusers.models.attention_processor의 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을 반환할 경우 첫 번째 요소는 생성된 이미지가 포함된 리스트입니다.

생성을 위해 파이프라인을 호출할 때 호출되는 함수.

예:

>>> 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

< >

( prompt: str | list[str]image: typing.Optional[torch.Tensor] = Nonedevice: typing.Optional[torch.device] = Nonenum_images_per_prompt: int = 1prompt_embeds: typing.Optional[torch.Tensor] = Noneprompt_embeds_mask: typing.Optional[torch.Tensor] = Nonemax_sequence_length: int = 1024 )

매개변수

  • prompt (str 또는 list[str], 선택 사항) — 인코딩할 프롬프트
  • image (torch.Tensor, 선택 사항) — 인코딩할 이미지
  • device — (torch.device): torch device
  • num_images_per_prompt (int) — 프롬프트당 생성할 이미지 수
  • prompt_embeds (torch.Tensor, 선택) — 미리 생성된 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩이 생성됩니다.

QwenImageEditInpaintPipeline

클래스 diffusers.QwenImageEditInpaintPipeline

< >

( scheduler: FlowMatchEulerDiscreteSchedulervae: AutoencoderKLQwenImagetext_encoder: Qwen2_5_VLForConditionalGenerationtokenizer: Qwen2Tokenizerprocessor: Qwen2VLProcessortransformer: QwenImageTransformer2DModel )

매개변수

이미지 편집을 위한 Qwen-Image-Edit 파이프라인.

__call__

< >

( image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor], NoneType] = Noneprompt: str | list[str] = Nonenegative_prompt: str | list[str] = Nonemask_image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]] = Nonemasked_image_latents: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]] = Nonetrue_cfg_scale: float = 4.0height: int | None = Nonewidth: int | None = Nonepadding_mask_crop: int | None = Nonestrength: float = 0.6num_inference_steps: int = 50sigmas: list[float] | None = Noneguidance_scale: float | None = Nonenum_images_per_prompt: int = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneprompt_embeds: typing.Optional[torch.Tensor] = Noneprompt_embeds_mask: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds_mask: typing.Optional[torch.Tensor] = Noneoutput_type: str | None = 'pil'return_dict: bool = Trueattention_kwargs: dict[str, typing.Any] | None = Nonecallback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 512 ) → ~pipelines.qwenimage.QwenImagePipelineOutput or tuple

매개변수

  • image (torch.Tensor, PIL.Image.Image, np.ndarray, list[torch.Tensor], list[PIL.Image.Image] 또는 list[np.ndarray]) — 시작점으로 사용할 이미지 배치의 Image, numpy 배열 또는 텐서를 나타냅니다. numpy 배열과 pytorch 텐서 모두에서 예상 값 범위는 [0, 1]입니다. 텐서 또는 텐서 목록인 경우 예상 shape은 (B, C, H, W) 또는 (C, H, W)여야 합니다. numpy 배열 또는 배열 목록인 경우 예상 shape은 (B, H, W, C) 또는 (H, W, C)여야 합니다. image로 이미지 latents도 받을 수 있지만, 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에서 정의된 가이던스 스케일입니다. true_cfg_scale은 Imagen Paper의 방정식 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개 대신 하나의 색상 채널(L)을 포함해야 하므로, pytorch 텐서의 예상 shape은 (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에 의해 마스크 latents 텐서가 생성됩니다.
  • 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) — guidance distilled 모델에 사용할 guidance scale 값입니다. 추론 시 노이즈 예측 rescaling을 통해 guidance scale을 적용하는 전통적인 classifier-free guidance와 달리, guidance distilled 모델은 forward pass 과정에서 guidance scale을 직접 입력 파라미터로 받습니다. guidance_scale > 1로 설정하면 guidance scale이 활성화됩니다. guidance scale이 높을수록 prompt 텍스트와 밀접하게 연결된 이미지를 생성하도록 장려되며, 일반적으로 이미지 품질 저하를 대가로 합니다. 이 파이프라인의 해당 파라미터는 향후 등장할 guidance-distilled 모델을 지원하기 위해 존재합니다. guidance distilled 모델을 사용하지 않는 경우 무시됩니다. 전통적인 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 generator 하나 또는 목록
  • latents (torch.Tensor, 선택 사항) — 이미지 생성의 입력으로 사용할 가우시안 분포에서 샘플링된 사전 생성된 노이즈 latents입니다. 동일한 생성을 다른 프롬프트로 조정하는 데 사용할 수 있습니다. 제공되지 않으면, 제공된 랜덤 generator를 사용하여 샘플링하여 latents 텐서가 생성됩니다.
  • prompt_embeds (torch.Tensor, 선택) — 미리 생성된 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩이 생성됩니다.
  • prompt_embeds_mask (torch.Tensor, 선택 사항) — prompt_embeds에 대한 어텐션 마스크입니다.
  • negative_prompt_embeds (torch.Tensor, 선택 사항) — 미리 생성된 negative text embeddings입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 negative_prompt 입력 인자로부터 negative_prompt_embeds가 생성됩니다.
  • negative_prompt_embeds_mask (torch.Tensor, 선택 사항) — negative_prompt_embeds에 대한 어텐션 마스크입니다.
  • output_type (str, 선택 사항, 기본값 "pil") — 이미지 생성의 출력 형식입니다. PIL: PIL.Image.Image 또는 np.array 중 하나를 선택합니다.
  • return_dict (bool, 선택 사항, 기본값 True) — 일반 튜플 대신 ~pipelines.qwenimage.QwenImagePipelineOutput를 반환할지 여부.
  • attention_kwargs (dict, 선택 사항) — 지정된 경우 diffusers.models.attention_processor의 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을 반환할 경우 첫 번째 요소는 생성된 이미지가 포함된 리스트입니다.

생성을 위해 파이프라인을 호출할 때 호출되는 함수.

예:

>>> 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

< >

( prompt: str | list[str]image: typing.Optional[torch.Tensor] = Nonedevice: typing.Optional[torch.device] = Nonenum_images_per_prompt: int = 1prompt_embeds: typing.Optional[torch.Tensor] = Noneprompt_embeds_mask: typing.Optional[torch.Tensor] = Nonemax_sequence_length: int = 1024 )

매개변수

  • prompt (str 또는 list[str], 선택 사항) — 인코딩할 프롬프트
  • image (torch.Tensor, 선택 사항) — 인코딩할 이미지
  • device — (torch.device): torch device
  • num_images_per_prompt (int) — 프롬프트당 생성할 이미지 수
  • prompt_embeds (torch.Tensor, 선택) — 미리 생성된 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩이 생성됩니다.

QwenImageControlNetPipeline

클래스 diffusers.QwenImageControlNetPipeline

< >

( scheduler: FlowMatchEulerDiscreteSchedulervae: AutoencoderKLQwenImagetext_encoder: Qwen2_5_VLForConditionalGenerationtokenizer: Qwen2Tokenizertransformer: QwenImageTransformer2DModelcontrolnet: diffusers.models.controlnets.controlnet_qwenimage.QwenImageControlNetModel | diffusers.models.controlnets.controlnet_qwenimage.QwenImageMultiControlNetModel )

매개변수

텍스트에서 이미지 생성을 위한 QwenImage 파이프라인.

__call__

< >

( prompt: str | list[str] = Nonenegative_prompt: str | list[str] = Nonetrue_cfg_scale: float = 4.0height: int | None = Nonewidth: int | None = Nonenum_inference_steps: int = 50sigmas: list[float] | None = Noneguidance_scale: float | None = Nonecontrol_guidance_start: float | list[float] = 0.0control_guidance_end: float | list[float] = 1.0control_image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]] = Nonecontrolnet_conditioning_scale: float | list[float] = 1.0num_images_per_prompt: int = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneprompt_embeds: typing.Optional[torch.Tensor] = Noneprompt_embeds_mask: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds_mask: typing.Optional[torch.Tensor] = Noneoutput_type: str | None = 'pil'return_dict: bool = Trueattention_kwargs: dict[str, typing.Any] | None = Nonecallback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 512 ) → ~pipelines.qwenimage.QwenImagePipelineOutput or tuple

매개변수

  • 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에서 정의된 guidance scale입니다. true_cfg_scale은 Imagen Paper의 방정식 2의 w로 정의됩니다. true_cfg_scale > 1을 설정하고 negative_prompt를 제공하면 classifier-free guidance가 활성화됩니다. guidance scale이 높을수록 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) — guidance distilled 모델에 사용할 guidance scale 값입니다. 추론 시 노이즈 예측 rescaling을 통해 guidance scale을 적용하는 전통적인 classifier-free guidance와 달리, guidance distilled 모델은 forward pass 과정에서 guidance scale을 직접 입력 파라미터로 받습니다. guidance_scale > 1로 설정하면 guidance scale이 활성화됩니다. guidance scale이 높을수록 prompt 텍스트와 밀접하게 연결된 이미지를 생성하도록 장려되며, 일반적으로 이미지 품질 저하를 대가로 합니다. 이 파이프라인의 해당 파라미터는 향후 등장할 guidance-distilled 모델을 지원하기 위해 존재합니다. guidance distilled 모델을 사용하지 않는 경우 무시됩니다. 전통적인 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의 잔차(residual)에 더해지기 전에 controlnet_conditioning_scale로 곱해집니다.
  • num_images_per_prompt (int, 선택 사항, 기본값 1) — 프롬프트당 생성할 이미지의 수입니다.
  • generator (torch.Generator 또는 list[torch.Generator], 선택 사항) — 생성을 결정적으로 만들기 위한 torch generator 하나 또는 목록
  • latents (torch.Tensor, 선택 사항) — 이미지 생성의 입력으로 사용할 가우시안 분포에서 샘플링된 사전 생성된 노이즈 latents입니다. 동일한 생성을 다른 프롬프트로 조정하는 데 사용할 수 있습니다. 제공되지 않으면, 제공된 랜덤 generator를 사용하여 샘플링하여 latents 텐서가 생성됩니다.
  • prompt_embeds (torch.Tensor, 선택) — 미리 생성된 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩이 생성됩니다.
  • prompt_embeds_mask (torch.Tensor, 선택 사항) — prompt_embeds에 대한 어텐션 마스크입니다.
  • negative_prompt_embeds (torch.Tensor, 선택 사항) — 미리 생성된 negative text embeddings입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 negative_prompt 입력 인자로부터 negative_prompt_embeds가 생성됩니다.
  • negative_prompt_embeds_mask (torch.Tensor, 선택 사항) — negative_prompt_embeds에 대한 어텐션 마스크입니다.
  • output_type (str, 선택 사항, 기본값 "pil") — 이미지 생성의 출력 형식입니다. PIL: PIL.Image.Image 또는 np.array 중 하나를 선택합니다.
  • return_dict (bool, 선택 사항, 기본값 True) — 일반 튜플 대신 ~pipelines.qwenimage.QwenImagePipelineOutput를 반환할지 여부.
  • attention_kwargs (dict, 선택 사항) — 지정된 경우 diffusers.models.attention_processor의 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을 반환할 경우 첫 번째 요소는 생성된 이미지가 포함된 리스트입니다.

생성을 위해 파이프라인을 호출할 때 호출되는 함수.

예:

>>> 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

< >

( prompt: str | list[str]device: typing.Optional[torch.device] = Nonenum_images_per_prompt: int = 1prompt_embeds: typing.Optional[torch.Tensor] = Noneprompt_embeds_mask: typing.Optional[torch.Tensor] = Nonemax_sequence_length: int = 1024 )

매개변수

  • prompt (str 또는 list[str], 선택 사항) — 인코딩할 프롬프트
  • device — (torch.device): torch device
  • num_images_per_prompt (int) — 프롬프트당 생성할 이미지 수
  • prompt_embeds (torch.Tensor, 선택) — 미리 생성된 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩이 생성됩니다.

QwenImageEditPlusPipeline

클래스 diffusers.QwenImageEditPlusPipeline

< >

( scheduler: FlowMatchEulerDiscreteSchedulervae: AutoencoderKLQwenImagetext_encoder: Qwen2_5_VLForConditionalGenerationtokenizer: Qwen2Tokenizerprocessor: Qwen2VLProcessortransformer: QwenImageTransformer2DModel )

매개변수

이미지 편집을 위한 Qwen-Image-Edit 파이프라인.

__call__

< >

( image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor], NoneType] = Noneprompt: str | list[str] = Nonenegative_prompt: str | list[str] = Nonetrue_cfg_scale: float = 4.0height: int | None = Nonewidth: int | None = Nonenum_inference_steps: int = 50sigmas: list[float] | None = Noneguidance_scale: float | None = Nonenum_images_per_prompt: int = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneprompt_embeds: typing.Optional[torch.Tensor] = Noneprompt_embeds_mask: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds_mask: typing.Optional[torch.Tensor] = Noneoutput_type: str | None = 'pil'return_dict: bool = Trueattention_kwargs: dict[str, typing.Any] | None = Nonecallback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 512 ) → ~pipelines.qwenimage.QwenImagePipelineOutput or tuple

매개변수

  • image (torch.Tensor, PIL.Image.Image, np.ndarray, list[torch.Tensor], list[PIL.Image.Image] 또는 list[np.ndarray]) — 시작점으로 사용할 이미지 배치의 Image, numpy 배열 또는 텐서를 나타냅니다. numpy 배열과 pytorch 텐서 모두에서 예상 값 범위는 [0, 1]입니다. 텐서 또는 텐서 목록인 경우 예상 shape은 (B, C, H, W) 또는 (C, H, W)여야 합니다. numpy 배열 또는 배열 목록인 경우 예상 shape은 (B, H, W, C) 또는 (H, W, C)여야 합니다. image로 이미지 latents도 받을 수 있지만, 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에서 정의된 가이던스 스케일입니다. true_cfg_scale은 Imagen Paper의 방정식 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) — guidance distilled 모델에 사용할 guidance scale 값입니다. 추론 시 노이즈 예측 rescaling을 통해 guidance scale을 적용하는 전통적인 classifier-free guidance와 달리, guidance distilled 모델은 forward pass 과정에서 guidance scale을 직접 입력 파라미터로 받습니다. guidance_scale > 1로 설정하면 guidance scale이 활성화됩니다. guidance scale이 높을수록 prompt 텍스트와 밀접하게 연결된 이미지를 생성하도록 장려되며, 일반적으로 이미지 품질 저하를 대가로 합니다. 이 파이프라인의 해당 파라미터는 향후 등장할 guidance-distilled 모델을 지원하기 위해 존재합니다. guidance distilled 모델을 사용하지 않는 경우 무시됩니다. 전통적인 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 generator 하나 또는 목록
  • latents (torch.Tensor, 선택 사항) — 이미지 생성의 입력으로 사용할 가우시안 분포에서 샘플링된 사전 생성된 노이즈 latents입니다. 동일한 생성을 다른 프롬프트로 조정하는 데 사용할 수 있습니다. 제공되지 않으면, 제공된 랜덤 generator를 사용하여 샘플링하여 latents 텐서가 생성됩니다.
  • prompt_embeds (torch.Tensor, 선택) — 미리 생성된 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩이 생성됩니다.
  • prompt_embeds_mask (torch.Tensor, 선택 사항) — prompt_embeds에 대한 어텐션 마스크입니다.
  • negative_prompt_embeds (torch.Tensor, 선택 사항) — 미리 생성된 negative text embeddings입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 negative_prompt 입력 인자로부터 negative_prompt_embeds가 생성됩니다.
  • negative_prompt_embeds_mask (torch.Tensor, 선택 사항) — negative_prompt_embeds에 대한 어텐션 마스크입니다.
  • output_type (str, 선택 사항, 기본값 "pil") — 이미지 생성의 출력 형식입니다. PIL: PIL.Image.Image 또는 np.array 중 하나를 선택합니다.
  • return_dict (bool, 선택 사항, 기본값 True) — 일반 튜플 대신 ~pipelines.qwenimage.QwenImagePipelineOutput를 반환할지 여부.
  • attention_kwargs (dict, 선택 사항) — 지정된 경우 diffusers.models.attention_processor의 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을 반환할 경우 첫 번째 요소는 생성된 이미지가 포함된 리스트입니다.

생성을 위해 파이프라인을 호출할 때 호출되는 함수.

예:

>>> 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

< >

( prompt: str | list[str]image: typing.Optional[torch.Tensor] = Nonedevice: typing.Optional[torch.device] = Nonenum_images_per_prompt: int = 1prompt_embeds: typing.Optional[torch.Tensor] = Noneprompt_embeds_mask: typing.Optional[torch.Tensor] = Nonemax_sequence_length: int = 1024 )

매개변수

  • prompt (str 또는 list[str], 선택 사항) — 인코딩할 프롬프트
  • image (torch.Tensor, 선택 사항) — 인코딩할 이미지
  • device — (torch.device): torch device
  • num_images_per_prompt (int) — 프롬프트당 생성할 이미지 수
  • prompt_embeds (torch.Tensor, 선택) — 미리 생성된 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩이 생성됩니다.

QwenImageLayeredPipeline

클래스 diffusers.QwenImageLayeredPipeline

< >

( scheduler: FlowMatchEulerDiscreteSchedulervae: AutoencoderKLQwenImagetext_encoder: Qwen2_5_VLForConditionalGenerationtokenizer: Qwen2Tokenizerprocessor: Qwen2VLProcessortransformer: QwenImageTransformer2DModel )

매개변수

이미지 분해를 위한 Qwen-Image-Layered 파이프라인.

__call__

< >

( image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor], NoneType] = Noneprompt: str | list[str] = Nonenegative_prompt: str | list[str] = Nonetrue_cfg_scale: float = 4.0layers: int | None = 4num_inference_steps: int = 50sigmas: list[float] | None = Noneguidance_scale: float | None = Nonenum_images_per_prompt: int = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneprompt_embeds: typing.Optional[torch.Tensor] = Noneprompt_embeds_mask: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds_mask: typing.Optional[torch.Tensor] = Noneoutput_type: str | None = 'pil'return_dict: bool = Trueattention_kwargs: dict[str, typing.Any] | None = Nonecallback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 512resolution: int = 640cfg_normalize: bool = Falseuse_en_prompt: bool = False ) → ~pipelines.qwenimage.QwenImagePipelineOutput or tuple

매개변수

  • image (torch.Tensor, PIL.Image.Image, np.ndarray, list[torch.Tensor], list[PIL.Image.Image] 또는 list[np.ndarray]) — 시작점으로 사용할 이미지 배치의 Image, numpy 배열 또는 텐서를 나타냅니다. numpy 배열과 pytorch 텐서 모두에서 예상 값 범위는 [0, 1]입니다. 텐서 또는 텐서 목록인 경우 예상 shape은 (B, C, H, W) 또는 (C, H, W)여야 합니다. numpy 배열 또는 배열 목록인 경우 예상 shape은 (B, H, W, C) 또는 (H, W, C)여야 합니다. image로 이미지 latents도 받을 수 있지만, 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에서 정의된 가이던스 스케일입니다. true_cfg_scale은 Imagen Paper의 방정식 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) — guidance distilled 모델에 사용할 guidance scale 값입니다. 추론 시 노이즈 예측 rescaling을 통해 guidance scale을 적용하는 전통적인 classifier-free guidance와 달리, guidance distilled 모델은 forward pass 과정에서 guidance scale을 직접 입력 파라미터로 받습니다. guidance_scale > 1로 설정하면 guidance scale이 활성화됩니다. guidance scale이 높을수록 prompt 텍스트와 밀접하게 연결된 이미지를 생성하도록 장려되며, 일반적으로 이미지 품질 저하를 대가로 합니다. 이 파이프라인의 해당 파라미터는 향후 등장할 guidance-distilled 모델을 지원하기 위해 존재합니다. guidance distilled 모델을 사용하지 않는 경우 무시됩니다. 전통적인 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 generator 하나 또는 목록
  • latents (torch.Tensor, 선택 사항) — 이미지 생성의 입력으로 사용할 가우시안 분포에서 샘플링된 사전 생성된 노이즈 latents입니다. 동일한 생성을 다른 프롬프트로 조정하는 데 사용할 수 있습니다. 제공되지 않으면, 제공된 랜덤 generator를 사용하여 샘플링하여 latents 텐서가 생성됩니다.
  • prompt_embeds (torch.Tensor, 선택) — 미리 생성된 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩이 생성됩니다.
  • prompt_embeds_mask (torch.Tensor, 선택 사항) — prompt_embeds에 대한 어텐션 마스크입니다.
  • negative_prompt_embeds (torch.Tensor, 선택 사항) — 미리 생성된 negative text embeddings입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 negative_prompt 입력 인자로부터 negative_prompt_embeds가 생성됩니다.
  • negative_prompt_embeds_mask (torch.Tensor, 선택 사항) — negative_prompt_embeds에 대한 어텐션 마스크입니다.
  • output_type (str, 선택 사항, 기본값 "pil") — 이미지 생성의 출력 형식입니다. PIL: PIL.Image.Image 또는 np.array 중 하나를 선택합니다.
  • return_dict (bool, 선택 사항, 기본값 True) — 일반 튜플 대신 ~pipelines.qwenimage.QwenImagePipelineOutput를 반환할지 여부.
  • attention_kwargs (dict, 선택 사항) — 지정된 경우 diffusers.models.attention_processor의 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, 선택 사항, 기본값 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을 반환할 경우 첫 번째 요소는 생성된 이미지가 포함된 리스트입니다.

생성을 위해 파이프라인을 호출할 때 호출되는 함수.

예:

>>> 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

< >

( prompt: str | list[str]device: typing.Optional[torch.device] = Nonenum_images_per_prompt: int = 1prompt_embeds: typing.Optional[torch.Tensor] = Noneprompt_embeds_mask: typing.Optional[torch.Tensor] = Nonemax_sequence_length: int = 1024 )

매개변수

  • prompt (str 또는 list[str], 선택 사항) — 인코딩할 프롬프트
  • device — (torch.device): torch device
  • num_images_per_prompt (int) — 프롬프트당 생성할 이미지 수
  • prompt_embeds (torch.Tensor, 선택) — 미리 생성된 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩이 생성됩니다.

QwenImagePipelineOutput

클래스 diffusers.pipelines.qwenimage.pipeline_output.QwenImagePipelineOutput

< >

( images: list[PIL.Image.Image] | numpy.ndarray )

매개변수

  • images (list[PIL.Image.Image] 또는 np.ndarray) — batch_size 길이의 denoised PIL 이미지 목록 또는 (batch_size, height, width, num_channels) 형태의 numpy 배열. PIL 이미지 또는 numpy 배열은 diffusion 파이프라인의 denoised 이미지를 나타냅니다.

Stable Diffusion 파이프라인의 출력 클래스입니다.

Update on GitHub