Diffusers documentation
图像修复
图像修复
Stable Diffusion 模型还可应用于图像修复(inpainting),通过提供掩码和文本提示词,利用 Stable Diffusion 对图像的特定部分进行编辑。
提示
建议使用专为图像修复(inpainting)微调过的检查点,例如 stable-diffusion-v1-5/stable-diffusion-inpainting。默认的文本生成图像 Stable Diffusion 检查点,例如 stable-diffusion-v1-5/stable-diffusion-v1-5,也兼容,但性能可能稍差。
请务必查看 Stable Diffusion 的 技巧 部分,了解如何探索调度器速度与质量之间的权衡,以及如何高效地复用流水线组件!
如果您对使用某个任务的官方检查点感兴趣,请探索 CompVis 和 Stability AI Hub 组织!
StableDiffusionInpaintPipeline
类 diffusers.StableDiffusionInpaintPipeline
< source >( vae: diffusers.models.autoencoders.autoencoder_kl.AutoencoderKL | diffusers.models.autoencoders.autoencoder_asym_kl.AsymmetricAutoencoderKLtext_encoder: CLIPTextModeltokenizer: CLIPTokenizerunet: UNet2DConditionModelscheduler: KarrasDiffusionSchedulerssafety_checker: StableDiffusionSafetyCheckerfeature_extractor: CLIPImageProcessorPilimage_encoder: CLIPVisionModelWithProjection = Nonerequires_safety_checker: bool = True )
参数
- vae ([
AutoencoderKL,AsymmetricAutoencoderKL]) — 变分自编码器(VAE)模型,用于将图像编码为潜在表示,以及从潜在表示解码为图像。 - text_encoder (
CLIPTextModel) — 冻结的文本编码器(clip-vit-large-patch14)。 - tokenizer (CLIPTokenizer) —
用于对文本进行分词的
CLIPTokenizer。 - unet (UNet2DConditionModel) —
用于对编码后的图像潜变量进行去噪的
UNet2DConditionModel。 - scheduler (SchedulerMixin) —
用于与
unet配合,对编码后的图像潜变量进行去噪的调度器。可以是 DDIMScheduler、LMSDiscreteScheduler 或 PNDMScheduler 之一。 - safety_checker (
StableDiffusionSafetyChecker) — 用于评估生成图像是否可能被视为冒犯性或有害的分类模块。 有关模型潜在危害的更多详细信息,请参阅模型卡片。 - feature_extractor (CLIPImageProcessor) —
一个
CLIPImageProcessor,用于从生成的图像中提取特征;作为safety_checker的输入。
使用 Stable Diffusion 进行文本引导图像修复的 Pipeline。
该模型继承自 DiffusionPipeline。有关为所有 pipeline 实现的通用方法(下载、保存、在特定设备上运行等),请参阅父类文档。
该 pipeline 还继承了以下加载方法:
- 用于加载文本反转嵌入的 load_textual_inversion()
- 用于加载 LoRA 权重的 load_lora_weights()
- 用于保存 LoRA 权重的 save_lora_weights()
- 用于加载 IP Adapter 的 load_ip_adapter()
- 用于加载
.ckpt文件的 from_single_file()
__call__
< source >( prompt: str | list[str] = Noneimage: 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: Tensor = Noneheight: int | None = Nonewidth: int | None = Nonepadding_mask_crop: int | None = Nonestrength: float = 1.0num_inference_steps: int = 50timesteps: list = Nonesigmas: list = Noneguidance_scale: float = 7.5negative_prompt: str | list[str] | None = Nonenum_images_per_prompt: int | None = 1eta: float = 0.0generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneprompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Noneip_adapter_image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor], NoneType] = Noneip_adapter_image_embeds: list[torch.Tensor] | None = Noneoutput_type: str | None = 'pil'return_dict: bool = Truecross_attention_kwargs: dict[str, typing.Any] | None = Noneclip_skip: int = Nonecallback_on_step_end: typing.Union[typing.Callable[[int, int], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']**kwargs ) → StableDiffusionPipelineOutput or tuple
参数
- prompt (
str或list[str],可选) — 用于引导图像生成的提示词或提示词列表。如果未定义,则需要传入prompt_embeds。 - image (
torch.Tensor、PIL.Image.Image、np.ndarray、list[torch.Tensor]、list[PIL.Image.Image]或list[np.ndarray]) —Image、numpy 数组或张量,表示要进行图像修复(inpainting)的图像批次(即图像中哪些部分需要用mask_image进行遮罩,并根据prompt重新绘制)。对于 numpy 数组和 PyTorch 张量,预期的取值范围在[0, 1]之间。如果是张量或张量列表,预期的形状应为(B, C, H, W)或(C, H, W)。如果是 numpy 数组或数组列表,预期的形状应为(B, H, W, C)或(H, W, C)。它也可以接受图像潜变量(image latents)作为image,但如果直接传入潜变量,则不会再次进行编码。 - mask_image (
torch.Tensor、PIL.Image.Image、np.ndarray、list[torch.Tensor]、list[PIL.Image.Image]或list[np.ndarray]) —Image、numpy 数组或张量,表示要用于遮罩image的图像批次。遮罩中的白色像素将被重绘,而黑色像素将保留。如果mask_image是 PIL 图像,则在使用前会将其转换为单通道(亮度)。如果它是 numpy 数组或 PyTorch 张量,则应包含一个颜色通道(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, 可选) — 掩码图像的预编码潜在表示(用于图像修复)。 - height (
int,可选,默认为self.unet.config.sample_size * self.vae_scale_factor) — 生成图像的高度(以像素为单位)。 - width (
int,可选,默认为self.unet.config.sample_size * self.vae_scale_factor) — 生成图像的宽度(以像素为单位)。 - padding_mask_crop (
int, 可选,默认为None) — 应用于图像和掩码的裁剪边距大小。如果为None,则不对 image 和 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) — 去噪步数。更多的去噪步数通常能生成更高质量的图像,但推理速度会更慢。此参数受strength调节。 - timesteps (
list[int], 可选) — 用于支持timesteps参数的调度器去噪过程的自定义时间步,该参数位于其set_timesteps方法中。如果未定义,则使用传入num_inference_steps时的默认行为。必须按降序排列。 - sigmas (
list[float],可选) — 用于在支持sigmas参数的调度器的set_timesteps方法中,为去噪过程指定自定义的 sigmas。如果未定义,则使用传入num_inference_steps时的默认行为。 - guidance_scale (
float,可选,默认值为 7.5) — 较高的 guidance scale 值会促使模型生成与文本prompt紧密相关的图像,但代价是图像质量降低。当guidance_scale > 1时,guidance scale 生效。 - negative_prompt (
str或list[str],可选) — 用于指导图像生成中不应包含的内容的提示词或提示词列表。如果未定义,则需要改为传入negative_prompt_embeds。在未使用引导(guidance_scale < 1)时将被忽略。 - num_images_per_prompt (
int,可选,默认为 1) — 每个提示词生成的图像数量。 - eta(
float,可选,默认值为 0.0)— 对应 DDIM 论文中的参数 eta (η)。仅适用于 DDIMScheduler,在其他调度器中会被忽略。 - generator (
torch.Generator或list[torch.Generator],可选) — 用于使生成过程确定性的torch.Generator。 - latents (
torch.Tensor, 可选) — 预先生成的、从高斯分布中采样的含噪潜变量,用作图像生成的输入。可用于以不同的提示词微调同一生成过程。如果未提供,则使用提供的随机generator进行采样,生成一个潜变量张量。 - prompt_embeds (
torch.Tensor, 可选) — 预生成的文本嵌入。可用于轻松调整文本输入(提示词加权)。如果未提供,则从prompt输入参数生成文本嵌入。 - negative_prompt_embeds (
torch.Tensor,可选) — 预生成的负向文本嵌入。可用于轻松调整文本输入(提示词权重)。如果未提供,negative_prompt_embeds将根据negative_prompt输入参数生成。 - ip_adapter_image — (
PipelineImageInput,可选):用于配合 IP Adapter 使用的可选图像输入。 - ip_adapter_image_embeds (
list[torch.Tensor], 可选) — IP-Adapter 的预生成图像嵌入。它应是一个列表,长度与 IP-Adapter 的数量相同。每个元素应为形状为(batch_size, num_images, emb_dim)的张量。如果do_classifier_free_guidance设置为True,则应包含负向图像嵌入。如果未提供,嵌入将从ip_adapter_image输入参数计算得出。 - output_type (
str,可选,默认为"pil") — 生成图像的输出格式。可选PIL.Image或np.array。 - return_dict (
bool,可选,默认为True) — 是否返回 StableDiffusionPipelineOutput 而不是普通元组。 - cross_attention_kwargs (
dict, 可选) — 一个 kwargs 字典,如果指定,将作为参数传递给self.processor中定义的AttentionProcessor。 - clip_skip (
int, 可选) — 在计算提示嵌入时,从 CLIP 中跳过的层数。值为 1 表示使用倒数第二层的输出来计算提示嵌入。 - callback_on_step_end (
Callable、PipelineCallback、MultiPipelineCallbacks、可选) — 在推理过程中,每个去噪步骤结束时调用的函数,或PipelineCallback或MultiPipelineCallbacks的子类,其参数如下: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属性中列出的变量。
返回值
StableDiffusionPipelineOutput 或 tuple
如果 return_dict 为 True,则返回 StableDiffusionPipelineOutput;否则返回一个 tuple,其中第一个元素是包含生成图像的列表,第二个元素是 bool 列表,用于指示对应的生成图像是否包含“不适合工作场所”(nsfw)内容。
用于生成的 pipeline 的调用函数。
示例:
>>> import PIL
>>> import requests
>>> import torch
>>> from io import BytesIO
>>> from diffusers import StableDiffusionInpaintPipeline
>>> def download_image(url):
... response = requests.get(url)
... return PIL.Image.open(BytesIO(response.content)).convert("RGB")
>>> 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"
>>> init_image = download_image(img_url).resize((512, 512))
>>> mask_image = download_image(mask_url).resize((512, 512))
>>> pipe = StableDiffusionInpaintPipeline.from_pretrained(
... "stable-diffusion-v1-5/stable-diffusion-inpainting", torch_dtype=torch.float16
... )
>>> pipe = pipe.to("cuda")
>>> prompt = "Face of a yellow cat, high resolution, sitting on a park bench"
>>> image = pipe(prompt=prompt, image=init_image, mask_image=mask_image).images[0]enable_attention_slicing
< source >( slice_size: str | int = 'auto' )
启用切片注意力计算。启用此选项后,注意力模块会将输入张量切分为多个切片,分步计算注意力。当存在多个注意力头时,计算将按顺序针对每个头执行。此功能可用于节省部分内存,代价是速度略有下降。
> ⚠️ 如果您已经在使用 PyTorch > 2.0 或 xFormers 中的
scaled_dot_product_attention(SDPA),请勿启用注意力切片。这些注意力计算本身已经非常节省内存,因此您无需启用 > 此功能。如果在 SDPA 或 xFormers 上启用注意力切片,可能会导致严重的性能下降!
示例:
>>> import torch
>>> from diffusers import StableDiffusionPipeline
>>> pipe = StableDiffusionPipeline.from_pretrained(
... "stable-diffusion-v1-5/stable-diffusion-v1-5",
... dtype=torch.float16,
... use_safetensors=True,
... )
>>> prompt = "a photo of an astronaut riding a horse on mars"
>>> pipe.enable_attention_slicing()
>>> image = pipe(prompt).images[0]禁用切片注意力计算。如果之前调用过 enable_attention_slicing,则注意力将一次性计算完成。
enable_xformers_memory_efficient_attention
< source >( attention_op: typing.Optional[typing.Callable] = None )
参数
- attention_op (
Callable, 可选) — 覆盖默认的None算子,用作 xFormers 的memory_efficient_attention()函数的op参数。
启用来自 xFormers 的内存高效注意力机制。启用此选项后,您应能观察到更低的 GPU 内存占用,并且在推理期间可能会获得加速。训练期间的加速并不保证。
> ⚠️ 当同时启用 memory efficient attention 和 sliced attention 时,memory efficient attention 具有 > 优先权。
示例:
>>> import torch
>>> from diffusers import DiffusionPipeline
>>> from xformers.ops import MemoryEfficientAttentionFlashAttentionOp
>>> pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1", dtype=torch.float16)
>>> pipe = pipe.to("cuda")
>>> pipe.enable_xformers_memory_efficient_attention(attention_op=MemoryEfficientAttentionFlashAttentionOp)
>>> # Workaround for not accepting attention shape using VAE for Flash Attention
>>> pipe.vae.enable_xformers_memory_efficient_attention(attention_op=None)禁用来自 xFormers 的内存高效注意力。
load_textual_inversion
< source >( pretrained_model_name_or_path: str | list[str] | dict[str, torch.Tensor] | list[dict[str, torch.Tensor]]token: str | list[str] | None = Nonetokenizer: 'PreTrainedTokenizer' | None = Nonetext_encoder: 'PreTrainedModel' | None = None**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike或list[str or os.PathLike]或Dict或list[Dict]) — 可以是以下其中一项,也可以是它们的列表:- 一个字符串,即托管在 Hub 上的预训练模型的 model id(例如
sd-concepts-library/low-poly-hd-logos-icons)。 - 指向包含文本反转权重的目录的路径(例如
./my_text_inversion_directory/)。 - 指向包含文本反转权重的文件的路径(例如
./my_text_inversions.pt)。 - 一个 torch 状态字典。
- 一个字符串,即托管在 Hub 上的预训练模型的 model id(例如
- token (
str或list[str],可选) — 用于覆盖文本反转权重所使用的 token。如果pretrained_model_name_or_path是一个列表,则token也必须是一个长度相等的列表。 - text_encoder (CLIPTextModel,可选) — 冻结的文本编码器(clip-vit-large-patch14)。 如果未指定,函数将使用 self.tokenizer。
- tokenizer (CLIPTokenizer,可选) —
用于对文本进行分词的
CLIPTokenizer。如果未指定,函数将使用 self.tokenizer。 - weight_name (
str, 可选) — 自定义权重文件的名称。在以下情况下应使用此参数:- 保存的文本反演文件采用 🤗 Diffusers 格式,但保存时使用了特定的权重名称,例如
text_inv.bin。 - 保存的文本反演文件采用 Automatic1111 格式。
- 保存的文本反演文件采用 🤗 Diffusers 格式,但保存时使用了特定的权重名称,例如
- cache_dir (
str | os.PathLike, 可选) — 如果未使用标准缓存,则下载的预训练模型配置将被缓存到的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - local_files_only (
bool,可选,默认为False) — 是否仅加载本地的模型权重和配置文件。如果设置为True,则不会从 Hub 下载模型。 - hf_token (
str或 bool,可选) — 用于远程文件的 HTTP bearer 授权令牌。如果为True,则使用由diffusers-cli login生成的令牌(存储在~/.huggingface中)。 - revision (
str, 可选, 默认为"main") — 要使用的特定模型版本。它可以是分支名称、标签名称、提交 id,或 Git 允许的任何标识符。 - subfolder (
str,可选,默认为"") — 模型文件在 Hub 或本地更大的模型仓库中的子文件夹位置。 - mirror (
str, 可选) — 镜像源,用于解决在中国下载模型时可能遇到的访问问题。我们不保证该源的时效性或安全性,详情请参阅镜像站点。
将 Textual Inversion 嵌入加载到 StableDiffusionPipeline 的文本编码器中(同时支持 🤗 Diffusers 和 Automatic1111 格式)。
示例:
要在 🤗 Diffusers 格式中加载 Textual Inversion 嵌入向量:
from diffusers import StableDiffusionPipeline
import torch
model_id = "stable-diffusion-v1-5/stable-diffusion-v1-5"
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to("cuda")
pipe.load_textual_inversion("sd-concepts-library/cat-toy")
prompt = "A <cat-toy> backpack"
image = pipe(prompt, num_inference_steps=50).images[0]
image.save("cat-backpack.png")要在 Automatic1111 格式中加载 Textual Inversion 嵌入向量,请先下载该向量(例如从 civitAI 下载),然后加载该向量
本地:
from diffusers import StableDiffusionPipeline
import torch
model_id = "stable-diffusion-v1-5/stable-diffusion-v1-5"
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to("cuda")
pipe.load_textual_inversion("./charturnerv2.pt", token="charturnerv2")
prompt = "charturnerv2, multiple views of the same character in the same outfit, a character turnaround of a woman wearing a black jacket and red shirt, best quality, intricate details."
image = pipe(prompt, num_inference_steps=50).images[0]
image.save("character.png")load_lora_weights
< source >( pretrained_model_name_or_path_or_dict: str | dict[str, torch.Tensor]adapter_name: str | None = Nonehotswap: bool = False**kwargs )
参数
- pretrained_model_name_or_path_or_dict (
str或os.PathLike或dict) — 参见 lora_state_dict()。 - adapter_name (
str, 可选) — 用于引用已加载的适配器模型的适配器名称。如果未指定,将使用default_{i},其中 i 为正在加载的适配器总数。 - low_cpu_mem_usage (
bool,可选) — 通过仅加载预训练的 LoRA 权重而不初始化随机权重,来加快模型加载速度。 - hotswap (
bool, 可选) — 默认值为False. 是否用新加载的适配器就地替换现有的(LoRA)适配器。这意味着,系统不会加载额外的适配器,而是获取现有适配器的权重,并用新适配器的权重将其替换。这种方式可能更快且更节省内存。然而,热替换的主要优势在于,当模型使用 torch.compile 编译时,加载新适配器无需重新编译模型。使用热替换时,传入的adapter_name应为已加载适配器的名称。如果新适配器和旧适配器的秩和/或 LoRA alpha(即缩放)不同,则在加载适配器之前需要调用一个额外的方法:
将 pretrained_model_name_or_path_or_dict 中指定的 LoRA 权重加载到 self.unet 和 self.text_encoder 中。
所有 kwargs 都会转发到 self.lora_state_dict。
有关状态字典加载方式的更多详细信息,请参阅 lora_state_dict()。
有关状态字典如何加载到 self.unet 的更多详细信息,请参阅 load_lora_into_unet()。
有关状态字典如何加载到 self.text_encoder 的更多详细信息,请参阅 load_lora_into_text_encoder()。
save_lora_weights
< source >( save_directory: str | os.PathLikeunet_lora_layers: dict = Nonetext_encoder_lora_layers: dict = Noneis_main_process: bool = Trueweight_name: str = Nonesave_function: typing.Callable = Nonesafe_serialization: bool = Trueunet_lora_adapter_metadata = Nonetext_encoder_lora_adapter_metadata = None )
参数
- save_directory (
str或os.PathLike) — 用于保存 LoRA 参数的目录。如果该目录不存在,将会自动创建。 - unet_lora_layers (
dict[str, torch.nn.Module]或dict[str, torch.Tensor]) — 与unet对应的 LoRA 层的 state dict。 - text_encoder_lora_layers (
dict[str, torch.nn.Module]或dict[str, torch.Tensor]) — 与text_encoder对应的 LoRA 层的 state dict。由于它来自 🤗 Transformers,因此必须显式传入文本编码器的 LoRA state dict。 - is_main_process (
bool,可选,默认为True) — 调用此函数的进程是否为主进程。在分布式训练期间,当需要在所有进程上调用此函数时非常有用。在这种情况下,仅在主进程上设置is_main_process=True,以避免竞态条件。 - save_function (
Callable) — 用于保存状态字典的函数。在分布式训练期间,当您需要用其他方法替换torch.save时非常有用。可以通过环境变量DIFFUSERS_SAVE_MODE进行配置。 - safe_serialization(
bool,可选,默认为True)—— 是否使用safetensors保存模型,还是使用传统的基于pickle的 PyTorch 方式。 - unet_lora_adapter_metadata — 与 unet 关联的 LoRA 适配器元数据,将随状态字典一起序列化。
- text_encoder_lora_adapter_metadata — 与文本编码器关联的 LoRA 适配器元数据,将随状态字典一起序列化。
保存与 UNet 和文本编码器对应的 LoRA 参数。
encode_prompt
< source >( promptdevicenum_images_per_promptdo_classifier_free_guidancenegative_prompt = Noneprompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonelora_scale: float | None = Noneclip_skip: int | None = None )
参数
- prompt (
str或list[str],可选) — 要编码的提示 - device — (
torch.device): torch 设备 - num_images_per_prompt (
int) — 每个提示词应生成的图像数量 - do_classifier_free_guidance (
bool) — 是否使用 classifier free guidance - negative_prompt (
str或list[str],可选) — 用于不引导图像生成的提示词。如果未定义,则必须传入negative_prompt_embeds。在未使用引导时会被忽略(即当guidance_scale小于1时忽略)。 - prompt_embeds (
torch.Tensor, 可选) — 预生成的文本嵌入。可用于轻松调整文本输入,例如 提示词加权。如果未提供,文本嵌入将从prompt输入参数生成。 - negative_prompt_embeds (
torch.Tensor, 可选) — 预生成的负向文本嵌入。可用于轻松调整文本输入,例如提示词加权。如果未提供,negative_prompt_embeds 将从negative_prompt输入参数生成。 - lora_scale (
float, 可选) — 如果加载了 LoRA 层,将应用于文本编码器所有 LoRA 层的 LoRA 缩放系数。 - clip_skip (
int, 可选) — 在计算提示嵌入时,从 CLIP 中跳过的层数。值为 1 表示使用倒数第二层的输出来计算提示嵌入。
将提示词编码为文本编码器的隐藏状态。
get_guidance_scale_embedding
< source >( w: Tensorembedding_dim: int = 512dtype: dtype = torch.float32 ) → torch.Tensor
StableDiffusionPipelineOutput
类 diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput
< source >( images: list[PIL.Image.Image] | numpy.ndarraynsfw_content_detected: list[bool] | None )
Stable Diffusion 管道的输出类。