Diffusers 文档
文本到(RGB,深度)
并获得增强的文档体验
开始使用
文本到(RGB,深度)
LDM3D 由 Gabriela Ben Melech Stan、Diana Wofk、Scottie Fox、Alex Redden、Will Saxton、Jean Yu、Estelle Aflalo、Shao-Yen Tseng、Fabio Nonato、Matthias Muller 和 Vasudev Lal 在LDM3D: Latent Diffusion Model for 3D 中提出。LDM3D 从给定的文本提示生成图像和深度图,与现有的仅生成图像的文本到图像扩散模型(如Stable Diffusion)不同。LDM3D 以几乎相同的参数数量成功创建了一个可以同时压缩 RGB 图像和深度图的潜在空间。
两个检查点可供使用
- ldm3d-original。论文中使用的原始检查点
- ldm3d-4c。新版本的 LDM3D 使用 4 通道输入而不是 6 通道输入,并在更高分辨率的图像上进行了微调。
论文摘要如下:
这篇研究论文提出了一种用于 3D 的潜在扩散模型(LDM3D),它可以根据给定的文本提示生成图像和深度图数据,从而允许用户从文本提示生成 RGBD 图像。LDM3D 模型在包含 RGB 图像、深度图和标题的元组数据集上进行了微调,并通过大量实验进行了验证。我们还开发了一个名为 DepthFusion 的应用程序,它使用生成的 RGB 图像和深度图,通过 TouchDesigner 创建沉浸式和交互式的 360 度视角体验。这项技术有望改变娱乐和游戏、建筑和设计等广泛行业。总而言之,这篇论文对生成式 AI 和计算机视觉领域做出了重大贡献,并展示了 LDM3D 和 DepthFusion 彻底改变内容创建和数字体验的潜力。总结该方法的简短视频可以在此 URL 找到。
务必查看 Stable Diffusion 的 提示 部分,了解如何探索调度器速度和质量之间的权衡,以及如何高效地重用管道组件!
StableDiffusionLDM3DPipeline
class diffusers.StableDiffusionLDM3DPipeline
< 来源 >( vae: AutoencoderKL text_encoder: CLIPTextModel tokenizer: CLIPTokenizer unet: UNet2DConditionModel scheduler: KarrasDiffusionSchedulers safety_checker: StableDiffusionSafetyChecker feature_extractor: CLIPImageProcessor image_encoder: typing.Optional[transformers.models.clip.modeling_clip.CLIPVisionModelWithProjection] requires_safety_checker: bool = True )
__call__
< 来源 >( prompt: typing.Union[str, typing.List[str]] = None height: typing.Optional[int] = None width: typing.Optional[int] = None num_inference_steps: int = 49 timesteps: typing.List[int] = None sigmas: typing.List[float] = None guidance_scale: float = 5.0 negative_prompt: typing.Union[str, typing.List[str], NoneType] = None num_images_per_prompt: typing.Optional[int] = 1 eta: float = 0.0 generator: typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None latents: typing.Optional[torch.Tensor] = None prompt_embeds: typing.Optional[torch.Tensor] = None negative_prompt_embeds: typing.Optional[torch.Tensor] = None ip_adapter_image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, typing.List[PIL.Image.Image], typing.List[numpy.ndarray], typing.List[torch.Tensor], NoneType] = None ip_adapter_image_embeds: typing.Optional[typing.List[torch.Tensor]] = None output_type: typing.Optional[str] = 'pil' return_dict: bool = True cross_attention_kwargs: typing.Optional[typing.Dict[str, typing.Any]] = None guidance_rescale: float = 0.0 clip_skip: typing.Optional[int] = None callback_on_step_end: typing.Optional[typing.Callable[[int, int, typing.Dict], NoneType]] = None callback_on_step_end_tensor_inputs: typing.List[str] = ['latents'] **kwargs ) → StableDiffusionPipelineOutput 或 tuple
参数
- prompt (
str
或List[str]
, 可选) — 用于引导图像生成的提示词。如果未定义,则需要传入prompt_embeds
。 - height (
int
, 可选, 默认为self.unet.config.sample_size * self.vae_scale_factor
) — 生成图像的高度(像素)。 - width (
int
, 可选, 默认为self.unet.config.sample_size * self.vae_scale_factor
) — 生成图像的宽度(像素)。 - num_inference_steps (
int
, 可选, 默认为 50) — 去噪步数。更多的去噪步数通常会带来更高质量的图像,但推理速度会变慢。 - timesteps (
List[int]
, 可选) — 用于去噪过程的自定义时间步,适用于支持timesteps
参数的调度器的set_timesteps
方法。如果未定义,将使用传入num_inference_steps
时的默认行为。必须按降序排列。 - sigmas (
List[float]
, 可选) — 用于去噪过程的自定义 sigmas,适用于支持sigmas
参数的调度器的set_timesteps
方法。如果未定义,将使用传入num_inference_steps
时的默认行为。 - guidance_scale (
float
, 可选, 默认为 5.0) — 较高的引导尺度值鼓励模型生成与文本prompt
紧密相关的图像,但会降低图像质量。当guidance_scale > 1
时启用引导尺度。 - 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 适配器的可选图像输入。 - 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
, 可选) — 在推理过程中每次去噪步骤结束时调用的函数。该函数将使用以下参数调用: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
,其中第一个元素是生成的图像列表,第二个元素是指示相应生成的图像是否包含“不适合工作”(nsfw) 内容的 bool
列表。
用于生成的管道的调用函数。
示例
>>> from diffusers import StableDiffusionLDM3DPipeline
>>> pipe = StableDiffusionLDM3DPipeline.from_pretrained("Intel/ldm3d-4c")
>>> pipe = pipe.to("cuda")
>>> prompt = "a photo of an astronaut riding a horse on mars"
>>> output = pipe(prompt)
>>> rgb_image, depth_image = output.rgb, output.depth
>>> rgb_image[0].save("astronaut_ldm3d_rgb.jpg")
>>> depth_image[0].save("astronaut_ldm3d_depth.png")
encode_prompt
< 源 >( prompt device num_images_per_prompt do_classifier_free_guidance negative_prompt = None prompt_embeds: typing.Optional[torch.Tensor] = None negative_prompt_embeds: typing.Optional[torch.Tensor] = None lora_scale: typing.Optional[float] = None clip_skip: typing.Optional[int] = None )
参数
- prompt (
str
或List[str]
, 可选) — 待编码的提示词 - device — (
torch.device
): torch 设备 - num_images_per_prompt (
int
) — 每个提示词应生成的图像数量 - do_classifier_free_guidance (
bool
) — 是否使用分类器自由引导 - negative_prompt (
str
或List[str]
, 可选) — 不用于引导图像生成的提示词。如果未定义,则必须传递negative_prompt_embeds
。当不使用引导时(即,如果guidance_scale
小于1
时),此参数将被忽略。 - prompt_embeds (
torch.Tensor
, 可选) — 预生成的文本嵌入。可用于轻松调整文本输入,例如提示词权重。如果未提供,将从prompt
输入参数生成文本嵌入。 - negative_prompt_embeds (
torch.Tensor
, 可选) — 预生成的负面文本嵌入。可用于轻松调整文本输入,例如提示词权重。如果未提供,将从negative_prompt
输入参数生成 negative_prompt_embeds。 - lora_scale (
float
, 可选) — 如果加载了 LoRA 层,则应用于文本编码器所有 LoRA 层的 LoRA 比例。 - clip_skip (
int
, 可选) — 从 CLIP 跳过的层数,用于计算提示词嵌入。值为 1 表示将使用倒数第二层的输出计算提示词嵌入。
将提示编码为文本编码器隐藏状态。
get_guidance_scale_embedding
< 源 >( w: Tensor embedding_dim: int = 512 dtype: dtype = torch.float32 ) → torch.Tensor
LDM3DPipelineOutput
类 diffusers.pipelines.stable_diffusion_ldm3d.pipeline_stable_diffusion_ldm3d.LDM3DPipelineOutput
< 源 >( rgb: typing.Union[typing.List[PIL.Image.Image], numpy.ndarray] depth: typing.Union[typing.List[PIL.Image.Image], numpy.ndarray] nsfw_content_detected: typing.Optional[typing.List[bool]] )
参数
- rgb (
List[PIL.Image.Image]
或np.ndarray
) — 长度为batch_size
的去噪 PIL 图像列表或形状为(batch_size, height, width, num_channels)
的 NumPy 数组。 - depth (
List[PIL.Image.Image]
或np.ndarray
) — 长度为batch_size
的去噪 PIL 图像列表或形状为(batch_size, height, width, num_channels)
的 NumPy 数组。 - nsfw_content_detected (
List[bool]
) — 表示相应生成的图像是否包含“不安全内容”(nsfw)的列表,如果无法执行安全检查,则为None
。
Stable Diffusion 管道的输出类。
升频器
LDM3D-VR 是 LDM3D 的扩展版本。
该论文摘要如下:潜在扩散模型已被证明在创建和操纵视觉输出方面处于最先进水平。然而,据我们所知,同时生成深度图和 RGB 仍然受到限制。我们引入 LDM3D-VR,一套针对虚拟现实开发的扩散模型,其中包括 LDM3D-pano 和 LDM3D-SR。这些模型分别能够基于文本提示生成全景 RGBD,以及将低分辨率输入升级到高分辨率 RGBD。我们的模型是在现有预训练模型的基础上,针对包含全景/高分辨率 RGB 图像、深度图和标题的数据集进行微调的。这两个模型都与现有相关方法进行了比较评估。
两个检查点可供使用
- ldm3d-pano。此检查点支持全景图像的生成,需要使用 StableDiffusionLDM3DPipeline 管道。
- ldm3d-sr。此检查点支持 RGB 和深度图像的升频。可在原始 LDM3D 管道之后使用 communauty 管道中的 StableDiffusionUpscaleLDM3DPipeline 进行级联使用。