Diffusers 文档
万寿菊计算机视觉
并获得增强的文档体验
开始使用
万寿菊计算机视觉
Marigold 在 CVPR 2024 口头报告论文《重新利用基于扩散的图像生成器进行单目深度估计》中提出,作者为 Bingxin Ke、Anton Obukhov、Shengyu Huang、Nando Metzger、Rodrigo Caye Daudt 和 Konrad Schindler。其核心思想是**重新利用文本到图像潜在扩散模型 (LDM) 的生成先验,用于传统计算机视觉任务**。这种方法通过微调 Stable Diffusion 进行**单目深度估计**,如上图预告片所示。
Marigold 后来在后续论文《Marigold:基于扩散的图像生成器在图像分析中的经济适用性适应》中得到扩展,作者为 Bingxin Ke、Kevin Qu、Tianfu Wang、Nando Metzger、Shengyu Huang、Bo Li、Anton Obukhov 和 Konrad Schindler。这项工作将 Marigold 扩展到支持**表面法线**和**内禀图像分解** (IID) 等新模态,引入了**潜在一致性模型** (LCM) 的训练协议,并展示了**高分辨率** (HR) 处理能力。
早期的 Marigold 模型(v1-0 及更早版本)经过优化,至少需要 10 个推理步骤才能获得最佳结果。后来开发了 LCM 模型,仅需 1 到 4 个步骤即可实现高质量推理。Marigold 模型 v1-1 及更高版本使用 DDIM 调度器,可在 1 到 4 个步骤内获得最佳结果。
可用管道
每个管道都针对特定的计算机视觉任务量身定制,处理输入的 RGB 图像并生成相应的预测。目前,已实现以下计算机视觉任务
可用检查点
所有原始检查点都可以在 Hugging Face 上的 PRS-ETH 组织下找到。它们旨在与 Diffusers 管道和 原始代码库一起使用,后者也可以用于训练新的模型检查点。以下是推荐检查点的摘要,所有这些检查点都可以在 1 到 4 个步骤内生成可靠的结果。
模型权重 | 模态 | 评论 |
---|---|---|
prs-eth/marigold-depth-v1-1 | 深度 | 仿射不变深度预测为每个像素分配一个介于 0(近平面)和 1(远平面)之间的值,两个平面均由模型在推理过程中确定。 |
prs-eth/marigold-normals-v0-1 | 法线 | 表面法线预测是屏幕空间相机中单位长度的 3D 向量,值范围为 -1 到 1。 |
prs-eth/marigold-iid-appearance-v1-1 | 内在属性 | InteriorVerse 分解包括反照率和两种 BRDF 材料属性:粗糙度和金属性。 |
prs-eth/marigold-iid-lighting-v1-1 | 内在属性 | 图像 \(\(I\)\) 的 HyperSim 分解包括反照率 \(\(A\)\)、漫反射着色 \(\(S\)\) 和非漫反射残差 \(\(R\)\):\(\(I = A*S+R\)\)。 |
务必查看“调度器”指南,了解如何探索调度器速度和质量之间的权衡,并查看“跨管道重用组件”部分,了解如何有效地将相同组件加载到多个管道中。此外,要了解有关减少此管道内存使用的更多信息,请参阅此处的“[减少内存使用]”部分。
Marigold 管道在模型检查点中嵌入了调度器,并已使用该调度器进行设计和测试。最佳推理步数因调度器而异,没有适用于所有情况的通用值。为了适应这一点,管道的 `__call__` 方法中的 `num_inference_steps` 参数默认为 `None`(参见 API 参考)。除非明确设置,否则它会继承检查点配置文件(`model_index.json`)中 `default_denoising_steps` 字段的值。这确保了在仅使用 `image` 参数调用管道时获得高质量预测。
另请参阅万寿菊使用示例。
Marigold 深度预测 API
class diffusers.MarigoldDepthPipeline
< source >( unet: UNet2DConditionModel vae: AutoencoderKL scheduler: typing.Union[diffusers.schedulers.scheduling_ddim.DDIMScheduler, diffusers.schedulers.scheduling_lcm.LCMScheduler] text_encoder: CLIPTextModel tokenizer: CLIPTokenizer prediction_type: typing.Optional[str] = None scale_invariant: typing.Optional[bool] = True shift_invariant: typing.Optional[bool] = True default_denoising_steps: typing.Optional[int] = None default_processing_resolution: typing.Optional[int] = None )
参数
- unet (
UNet2DConditionModel
) — 条件 U-Net,用于去噪深度潜在空间,并以图像潜在空间为条件。 - vae (
AutoencoderKL
) — 变分自编码器 (VAE) 模型,用于编码和解码图像及预测,在潜在表示之间转换。 - scheduler (
DDIMScheduler
或LCMScheduler
) — 与unet
结合使用的调度器,用于去噪编码图像潜在空间。 - text_encoder (
CLIPTextModel
) — 文本编码器,用于空文本嵌入。 - tokenizer (
CLIPTokenizer
) — CLIP 分词器。 - prediction_type (
str
, 可选) — 模型所做预测的类型。 - scale_invariant (
bool
, 可选) — 一个模型属性,指定预测的深度图是否为尺度不变的。此值必须在模型配置中设置。当与shift_invariant=True
标志一起使用时,该模型也称为“仿射不变”。注意:不支持覆盖此值。 - shift_invariant (
bool
, 可选) — 一个模型属性,指定预测的深度图是否为平移不变的。此值必须在模型配置中设置。当与scale_invariant=True
标志一起使用时,该模型也称为“仿射不变”。注意:不支持覆盖此值。 - default_denoising_steps (
int
, 可选) — 生成高质量预测所需的最小去噪扩散步数。此值必须在模型配置中设置。当调用管道时未明确设置num_inference_steps
时,将使用此默认值。这对于确保与管道兼容的各种模型(例如依赖非常短的去噪时间表 (LCMScheduler
) 和那些具有完整扩散时间表 (DDIMScheduler
) 的模型)获得合理的结果是必需的。 - default_processing_resolution (
int
, 可选) — 管道的processing_resolution
参数的推荐值。此值必须在模型配置中设置。当调用管道时未明确设置processing_resolution
时,将使用此默认值。这对于确保使用各种具有不同最佳处理分辨率值的模型获得合理的结果是必需的。
使用 Marigold 方法进行单目深度估计的管道:https://marigoldmonodepth.github.io。
该模型继承自DiffusionPipeline。有关库为所有管道实现的通用方法(例如下载或保存、在特定设备上运行等),请查看超类文档。
__call__
< source >( image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, typing.List[PIL.Image.Image], typing.List[numpy.ndarray], typing.List[torch.Tensor]] num_inference_steps: typing.Optional[int] = None ensemble_size: int = 1 processing_resolution: typing.Optional[int] = None match_input_resolution: bool = True resample_method_input: str = 'bilinear' resample_method_output: str = 'bilinear' batch_size: int = 1 ensembling_kwargs: typing.Optional[typing.Dict[str, typing.Any]] = None latents: typing.Union[torch.Tensor, typing.List[torch.Tensor], NoneType] = None generator: typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None output_type: str = 'np' output_uncertainty: bool = False output_latent: bool = False return_dict: bool = True ) → MarigoldDepthOutput 或 tuple
参数
- image (
PIL.Image.Image
,np.ndarray
,torch.Tensor
,List[PIL.Image.Image]
,List[np.ndarray]
), —List[torch.Tensor]
: 用于深度估计任务的输入图像。对于数组和张量,预期值范围为[0, 1]
。通过提供四维数组或张量,可以传递一批图像。此外,可以传递二维或三维数组或张量列表。在后一种情况下,所有列表元素必须具有相同的宽度和高度。 - num_inference_steps (
int
, 可选, 默认为None
) — 推理过程中的去噪扩散步数。默认值None
会导致自动选择。 - ensemble_size (
int
, 默认为1
) — 集成预测的数量。值越大,可测量的改进和视觉退化越大。 - processing_resolution (
int
, 可选, 默认为None
) — 有效处理分辨率。当设置为0
时,匹配较大的输入图像尺寸。这会产生更清晰的预测,但也可能导致全局上下文的整体丢失。默认值None
解析为模型配置中的最佳值。 - match_input_resolution (
bool
, 可选, 默认为True
) — 启用时,输出预测将调整大小以匹配输入尺寸。禁用时,输出的长边将等于processing_resolution
。 - resample_method_input (
str
, 可选, 默认为"bilinear"
) — 用于将输入图像调整到processing_resolution
的重采样方法。接受的值为:"nearest"
,"nearest-exact"
,"bilinear"
,"bicubic"
或"area"
。 - resample_method_output (
str
, 可选, 默认为"bilinear"
) — 用于将输出预测调整为与输入分辨率匹配的重采样方法。接受的值为"nearest"
、"nearest-exact"
、"bilinear"
、"bicubic"
或"area"
。 - batch_size (
int
, 可选, 默认为1
) — 批处理大小;仅在设置ensemble_size
或传递图像张量时才重要。 - ensembling_kwargs (
dict
, 可选, 默认为None
) — 额外字典,用于精确控制集成。提供以下选项:- reduction (
str
, 可选, 默认为"median"
): 定义在每个像素位置应用的集成函数,可以是"median"
或"mean"
。 - regularizer_strength (
float
, 可选, 默认为0.02
): 将对齐的预测拉入 0 到 1 单位范围的正则化器的强度。 - max_iter (
int
, 可选, 默认为2
): 对齐求解器步骤的最大数量。请参考scipy.optimize.minimize
函数的options
参数。 - tol (
float
, 可选, 默认为1e-3
): 对齐求解器容差。当达到容差时,求解器停止。 - max_res (
int
, 可选, 默认为None
): 执行对齐的分辨率;None
匹配processing_resolution
。
- reduction (
- latents (
torch.Tensor
, 或List[torch.Tensor]
, 可选, 默认为None
) — 用于替换随机初始化的潜在噪声张量。这些可以取自上一个函数调用的输出。 - generator (
torch.Generator
, 或List[torch.Generator]
, 可选, 默认为None
) — 随机数生成器对象,以确保可复现性。 - output_type (
str
, 可选, 默认为"np"
) — 输出中prediction
和可选的uncertainty
字段的首选格式。接受的值为:"np"
(numpy 数组)或"pt"
(torch 张量)。 - output_uncertainty (
bool
, 可选, 默认为False
) — 启用后,如果ensemble_size
参数设置为大于 2 的值,则输出的uncertainty
字段将包含预测不确定性图。 - output_latent (
bool
, 可选, 默认为False
) — 启用后,输出的latent
字段将包含与集合中的预测相对应的潜在代码。这些代码可以保存、修改,并用于后续调用latents
参数。 - return_dict (
bool
, 可选, 默认为True
) — 是否返回 MarigoldDepthOutput 而不是普通元组。
返回
MarigoldDepthOutput 或 tuple
如果 return_dict
为 True
,则返回 MarigoldDepthOutput;否则返回一个 tuple
,其中第一个元素是预测,第二个元素是不确定性(或 None
),第三个元素是潜在(或 None
)。
调用管道时调用的函数。
示例
>>> import diffusers
>>> import torch
>>> pipe = diffusers.MarigoldDepthPipeline.from_pretrained(
... "prs-eth/marigold-depth-v1-1", variant="fp16", torch_dtype=torch.float16
... ).to("cuda")
>>> image = diffusers.utils.load_image("https://marigoldmonodepth.github.io/images/einstein.jpg")
>>> depth = pipe(image)
>>> vis = pipe.image_processor.visualize_depth(depth.prediction)
>>> vis[0].save("einstein_depth.png")
>>> depth_16bit = pipe.image_processor.export_depth_to_16bit_png(depth.prediction)
>>> depth_16bit[0].save("einstein_depth_16bit.png")
类 diffusers.pipelines.marigold.MarigoldDepthOutput
< 源 >( prediction: typing.Union[numpy.ndarray, torch.Tensor] uncertainty: typing.Union[NoneType, numpy.ndarray, torch.Tensor] latent: typing.Optional[torch.Tensor] )
参数
- prediction (
np.ndarray
,torch.Tensor
) — 预测的深度图,值范围为 [0, 1]。对于torch.Tensor
,形状为 $numimages × 1 × height × width$,对于np.ndarray
,形状为 $numimages × height × width × 1$。 - uncertainty (
None
,np.ndarray
,torch.Tensor
) — 从集合计算出的不确定性图,值范围为 [0, 1]。对于torch.Tensor
,形状为 $numimages × 1 × height × width$,对于np.ndarray
,形状为 $numimages × height × width × 1$。 - latent (
None
,torch.Tensor
) — 与预测相对应的潜在特征,与管道的latents
参数兼容。形状为 $numimages * numensemble × 4 × latentheight × latentwidth$。
Marigold 单目深度预测管道的输出类。
diffusers.pipelines.marigold.MarigoldImageProcessor.visualize_depth
< 源 >( depth: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, typing.List[PIL.Image.Image], typing.List[numpy.ndarray], typing.List[torch.Tensor]] val_min: float = 0.0 val_max: float = 1.0 color_map: str = 'Spectral' )
可视化深度图,例如 MarigoldDepthPipeline
的预测。
返回:带有深度图可视化的 List[PIL.Image.Image]
。
Marigold 法线估计 API
类 diffusers.MarigoldNormalsPipeline
< 源 >( unet: UNet2DConditionModel vae: AutoencoderKL scheduler: typing.Union[diffusers.schedulers.scheduling_ddim.DDIMScheduler, diffusers.schedulers.scheduling_lcm.LCMScheduler] text_encoder: CLIPTextModel tokenizer: CLIPTokenizer prediction_type: typing.Optional[str] = None use_full_z_range: typing.Optional[bool] = True default_denoising_steps: typing.Optional[int] = None default_processing_resolution: typing.Optional[int] = None )
参数
- unet (
UNet2DConditionModel
) — 条件 U-Net,用于去噪法线潜在,以图像潜在为条件。 - vae (
AutoencoderKL
) — 变分自编码器(VAE)模型,用于编码和解码图像及预测与潜在表示之间的转换。 - scheduler (
DDIMScheduler
或LCMScheduler
) — 与unet
结合使用的调度器,用于对编码图像潜在进行去噪。 - text_encoder (
CLIPTextModel
) — 文本编码器,用于空文本嵌入。 - tokenizer (
CLIPTokenizer
) — CLIP 分词器。 - prediction_type (
str
, 可选) — 模型做出的预测类型。 - use_full_z_range (
bool
, 可选) — 模型预测的法线是否使用 Z 维的完整范围,或者仅使用其正半部分。 - default_denoising_steps (
int
, 可选) — 生成合理质量预测所需的最小去噪扩散步数。此值必须在模型配置中设置。当调用管道时未明确设置num_inference_steps
时,将使用默认值。这对于确保与管道兼容的各种模型(例如依赖非常短去噪调度(LCMScheduler
)和具有完整扩散调度(DDIMScheduler
)的模型)获得合理结果是必需的。 - default_processing_resolution (
int
, 可选) — 管道processing_resolution
参数的推荐值。此值必须在模型配置中设置。当调用管道时未明确设置processing_resolution
时,将使用默认值。这对于确保与各种以不同最佳处理分辨率值训练的模型获得合理结果是必需的。
使用 Marigold 方法进行单目法线估计的管道:https://marigoldmonodepth.github.io。
该模型继承自DiffusionPipeline。有关库为所有管道实现的通用方法(例如下载或保存、在特定设备上运行等),请查看超类文档。
__call__
< 源 >( image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, typing.List[PIL.Image.Image], typing.List[numpy.ndarray], typing.List[torch.Tensor]] num_inference_steps: typing.Optional[int] = None ensemble_size: int = 1 processing_resolution: typing.Optional[int] = None match_input_resolution: bool = True resample_method_input: str = 'bilinear' resample_method_output: str = 'bilinear' batch_size: int = 1 ensembling_kwargs: typing.Optional[typing.Dict[str, typing.Any]] = None latents: typing.Union[torch.Tensor, typing.List[torch.Tensor], NoneType] = None generator: typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None output_type: str = 'np' output_uncertainty: bool = False output_latent: bool = False return_dict: bool = True ) → MarigoldNormalsOutput 或 tuple
参数
- image (
PIL.Image.Image
,np.ndarray
,torch.Tensor
,List[PIL.Image.Image]
,List[np.ndarray]
), —List[torch.Tensor]
: 用作法线估计任务输入的图像。对于数组和张量,预期值范围在[0, 1]
之间。可以通过提供四维数组或张量来传递一批图像。此外,可以传递二维或三维数组或张量图像列表。在后一种情况下,所有列表元素必须具有相同的宽度和高度。 - num_inference_steps (
int
, 可选, 默认为None
) — 推理期间的去噪扩散步数。默认值None
会导致自动选择。 - ensemble_size (
int
, 默认为1
) — 集合预测的数量。较高的值会带来显著改进和视觉降级。 - processing_resolution (
int
, 可选, 默认为None
) — 有效处理分辨率。设置为0
时,与较大的输入图像尺寸匹配。这会产生更清晰的预测,但也可能导致全局上下文的整体丢失。默认值None
会解析为模型配置中的最佳值。 - match_input_resolution (
bool
, 可选, 默认为True
) — 启用后,输出预测将调整大小以匹配输入尺寸。禁用后,输出的较长边将等于processing_resolution
。 - resample_method_input (
str
, 可选, 默认为"bilinear"
) — 用于将输入图像调整大小为processing_resolution
的重采样方法。接受的值为:"nearest"
、"nearest-exact"
、"bilinear"
、"bicubic"
或"area"
。 - resample_method_output (
str
, 可选, 默认为"bilinear"
) — 用于将输出预测调整大小以匹配输入分辨率的重采样方法。接受的值为"nearest"
、"nearest-exact"
、"bilinear"
、"bicubic"
或"area"
。 - batch_size (
int
, 可选, 默认为1
) — 批次大小;仅当设置ensemble_size
或传递图像张量时才重要。 - ensembling_kwargs (
dict
, 可选, 默认为None
) — 包含精确集合控制参数的额外字典。以下选项可用:- reduction (
str
, 可选, 默认为"closest"
): 定义应用于每个像素位置的集合函数,可以是"closest"
或"mean"
。
- reduction (
- latents (
torch.Tensor
, 可选, 默认为None
) — 潜在噪声张量,用于替换随机初始化。这些可以从上一个函数调用的输出中获取。 - generator (
torch.Generator
或List[torch.Generator]
, 可选, 默认为None
) — 随机数生成器对象,用于确保可重现性。 - output_type (
str
, 可选, 默认为"np"
) — 输出的prediction
和可选的uncertainty
字段的首选格式。接受的值为:"np"
(numpy 数组)或"pt"
(torch 张量)。 - output_uncertainty (
bool
, 可选, 默认为False
) — 启用后,如果ensemble_size
参数设置为大于 2 的值,则输出的uncertainty
字段将包含预测不确定性图。 - output_latent (
bool
, 可选, 默认为False
) — 启用后,输出的latent
字段将包含与集合中的预测相对应的潜在代码。这些代码可以保存、修改,并用于后续调用latents
参数。 - return_dict (
bool
, 可选, 默认为True
) — 是否返回 MarigoldNormalsOutput 而不是普通元组。
返回
MarigoldNormalsOutput 或 tuple
如果 return_dict
为 True
,则返回 MarigoldNormalsOutput;否则返回一个 tuple
,其中第一个元素是预测,第二个元素是不确定性(或 None
),第三个元素是潜在(或 None
)。
调用管道时调用的函数。
示例
>>> import diffusers
>>> import torch
>>> pipe = diffusers.MarigoldNormalsPipeline.from_pretrained(
... "prs-eth/marigold-normals-v1-1", variant="fp16", torch_dtype=torch.float16
... ).to("cuda")
>>> image = diffusers.utils.load_image("https://marigoldmonodepth.github.io/images/einstein.jpg")
>>> normals = pipe(image)
>>> vis = pipe.image_processor.visualize_normals(normals.prediction)
>>> vis[0].save("einstein_normals.png")
类 diffusers.pipelines.marigold.MarigoldNormalsOutput
< 源 >( prediction: typing.Union[numpy.ndarray, torch.Tensor] uncertainty: typing.Union[NoneType, numpy.ndarray, torch.Tensor] latent: typing.Optional[torch.Tensor] )
参数
- prediction (
np.ndarray
,torch.Tensor
) — 预测的法线,值范围为 [-1, 1]。对于torch.Tensor
,形状为 $numimages × 3 × height × width$,对于np.ndarray
,形状为 $numimages × height × width × 3$。 - uncertainty (
None
,np.ndarray
,torch.Tensor
) — 从集合计算出的不确定性图,值范围为 [0, 1]。对于torch.Tensor
,形状为 $numimages × 1 × height × width$,对于np.ndarray
,形状为 $numimages × height × width × 1$。 - latent (
None
,torch.Tensor
) — 与预测相对应的潜在特征,与管道的latents
参数兼容。形状为 $numimages * numensemble × 4 × latentheight × latentwidth$。
Marigold 单目法线预测管道的输出类。
diffusers.pipelines.marigold.MarigoldImageProcessor.visualize_normals
< 源 >( normals: typing.Union[numpy.ndarray, torch.Tensor, typing.List[numpy.ndarray], typing.List[torch.Tensor]] flip_x: bool = False flip_y: bool = False flip_z: bool = False )
可视化表面法线,例如 MarigoldNormalsPipeline
的预测。
返回:包含表面法线可视化的 List[PIL.Image.Image]
。
Marigold 本征图像分解 API
class diffusers.MarigoldIntrinsicsPipeline
< source >( unet: UNet2DConditionModel vae: AutoencoderKL scheduler: typing.Union[diffusers.schedulers.scheduling_ddim.DDIMScheduler, diffusers.schedulers.scheduling_lcm.LCMScheduler] text_encoder: CLIPTextModel tokenizer: CLIPTokenizer prediction_type: typing.Optional[str] = None target_properties: typing.Optional[typing.Dict[str, typing.Any]] = None default_denoising_steps: typing.Optional[int] = None default_processing_resolution: typing.Optional[int] = None )
参数
- unet (
UNet2DConditionModel
) — 条件 U-Net 用于对目标潜在值进行去噪,以图像潜在值为条件。 - vae (
AutoencoderKL
) — 变分自动编码器 (VAE) 模型,用于将图像和预测编码和解码为潜在表示,以及从潜在表示进行编码和解码。 - scheduler (
DDIMScheduler
或LCMScheduler
) — 与unet
结合使用的调度器,用于对编码的图像潜在值进行去噪。 - text_encoder (
CLIPTextModel
) — 文本编码器,用于空文本嵌入。 - tokenizer (
CLIPTokenizer
) — CLIP 分词器。 - prediction_type (
str
, 可选) — 模型所做预测的类型。 - target_properties (
Dict[str, Any]
, 可选) — 预测模态的属性,例如target_names
,一个List[str]
,用于定义预测模态的数量、顺序和名称,以及解释预测可能需要的任何其他元数据。 - default_denoising_steps (
int
, 可选) — 产生合理质量预测所需的最少去噪扩散步数。此值必须在模型配置中设置。当调用管道时未明确设置num_inference_steps
时,将使用默认值。这对于确保与管道兼容的各种模型(例如依赖于非常短的去噪调度 (LCMScheduler
) 和那些具有完整扩散调度 (DDIMScheduler
) 的模型)获得合理结果是必需的。 - default_processing_resolution (
int
, 可选) — 管道的processing_resolution
参数的推荐值。此值必须在模型配置中设置。当调用管道时未明确设置processing_resolution
时,将使用默认值。这对于确保与经过不同最佳处理分辨率值训练的各种模型获得合理结果是必需的。
使用 Marigold 方法进行本征图像分解 (IID) 的管道:https://marigoldcomputervision.github.io。
该模型继承自DiffusionPipeline。有关库为所有管道实现的通用方法(例如下载或保存、在特定设备上运行等),请查看超类文档。
__call__
< source >( image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, typing.List[PIL.Image.Image], typing.List[numpy.ndarray], typing.List[torch.Tensor]] num_inference_steps: typing.Optional[int] = None ensemble_size: int = 1 processing_resolution: typing.Optional[int] = None match_input_resolution: bool = True resample_method_input: str = 'bilinear' resample_method_output: str = 'bilinear' batch_size: int = 1 ensembling_kwargs: typing.Optional[typing.Dict[str, typing.Any]] = None latents: typing.Union[torch.Tensor, typing.List[torch.Tensor], NoneType] = None generator: typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None output_type: str = 'np' output_uncertainty: bool = False output_latent: bool = False return_dict: bool = True ) → MarigoldIntrinsicsOutput 或 tuple
参数
- image (
PIL.Image.Image
,np.ndarray
,torch.Tensor
,List[PIL.Image.Image]
,List[np.ndarray]
), —List[torch.Tensor]
:用于本征分解任务的输入图像。对于数组和张量,预期值范围在[0, 1]
之间。通过提供四维数组或张量,可以传递一批图像。此外,可以传递二维或三维数组或张量列表。在后一种情况下,所有列表元素必须具有相同的宽度和高度。 - num_inference_steps (
int
, 可选, 默认为None
) — 推理期间的去噪扩散步数。默认值None
会导致自动选择。 - ensemble_size (
int
, 默认为1
) — 集成预测的数量。较高的值会导致可衡量的改进和视觉退化。 - processing_resolution (
int
, 可选, 默认为None
) — 有效处理分辨率。当设置为0
时,与较大的输入图像尺寸匹配。这会产生更清晰的预测,但也可能导致整体全局上下文丢失。默认值None
解析为模型配置中的最佳值。 - match_input_resolution (
bool
, 可选, 默认为True
) — 启用时,输出预测将调整大小以匹配输入尺寸。禁用时,输出的较长边将等于processing_resolution
。 - resample_method_input (
str
, 可选, 默认为"bilinear"
) — 用于将输入图像调整到processing_resolution
的重采样方法。接受的值为:"nearest"
、"nearest-exact"
、"bilinear"
、"bicubic"
或"area"
。 - resample_method_output (
str
, 可选, 默认为"bilinear"
) — 用于将输出预测调整大小以匹配输入分辨率的重采样方法。接受的值为"nearest"
、"nearest-exact"
、"bilinear"
、"bicubic"
或"area"
。 - batch_size (
int
, 可选, 默认为1
) — 批大小;仅在设置ensemble_size
或传递图像张量时才重要。 - ensembling_kwargs (
dict
, 可选, 默认为None
) — 带有精确集成控制参数的额外字典。以下选项可用:- reduction (
str
, 可选, 默认为"median"
):定义每个像素位置应用的集成函数,可以是"median"
或"mean"
。
- reduction (
- latents (
torch.Tensor
, 可选, 默认为None
) — 潜在噪声张量,用于替换随机初始化。这些可以取自上一个函数调用的输出。 - generator (
torch.Generator
, 或List[torch.Generator]
, 可选, 默认为None
) — 随机数生成器对象,以确保可重现性。 - output_type (
str
, 可选, 默认为"np"
) — 输出的prediction
和可选uncertainty
字段的首选格式。接受的值为:"np"
(numpy 数组) 或"pt"
(torch 张量)。 - output_uncertainty (
bool
, 可选, 默认为False
) — 启用时,输出的uncertainty
字段包含预测不确定性图,前提是ensemble_size
参数设置为大于 2 的值。 - output_latent (
bool
, 可选, 默认为False
) — 启用时,输出的latent
字段包含与集成中的预测相对应的潜在代码。这些代码可以保存、修改,并用于后续调用latents
参数。 - return_dict (
bool
, 可选, 默认为True
) — 是否返回 MarigoldIntrinsicsOutput 而不是普通元组。
返回
MarigoldIntrinsicsOutput 或 tuple
如果 return_dict
为 True
,则返回 MarigoldIntrinsicsOutput,否则返回 tuple
,其中第一个元素是预测,第二个元素是不确定性(或 None
),第三个元素是潜在值(或 None
)。
调用管道时调用的函数。
示例
>>> import diffusers
>>> import torch
>>> pipe = diffusers.MarigoldIntrinsicsPipeline.from_pretrained(
... "prs-eth/marigold-iid-appearance-v1-1", variant="fp16", torch_dtype=torch.float16
... ).to("cuda")
>>> image = diffusers.utils.load_image("https://marigoldmonodepth.github.io/images/einstein.jpg")
>>> intrinsics = pipe(image)
>>> vis = pipe.image_processor.visualize_intrinsics(intrinsics.prediction, pipe.target_properties)
>>> vis[0]["albedo"].save("einstein_albedo.png")
>>> vis[0]["roughness"].save("einstein_roughness.png")
>>> vis[0]["metallicity"].save("einstein_metallicity.png")
>>> import diffusers
>>> import torch
>>> pipe = diffusers.MarigoldIntrinsicsPipeline.from_pretrained(
... "prs-eth/marigold-iid-lighting-v1-1", variant="fp16", torch_dtype=torch.float16
... ).to("cuda")
>>> image = diffusers.utils.load_image("https://marigoldmonodepth.github.io/images/einstein.jpg")
>>> intrinsics = pipe(image)
>>> vis = pipe.image_processor.visualize_intrinsics(intrinsics.prediction, pipe.target_properties)
>>> vis[0]["albedo"].save("einstein_albedo.png")
>>> vis[0]["shading"].save("einstein_shading.png")
>>> vis[0]["residual"].save("einstein_residual.png")
class diffusers.pipelines.marigold.MarigoldIntrinsicsOutput
< source >( prediction: typing.Union[numpy.ndarray, torch.Tensor] uncertainty: typing.Union[NoneType, numpy.ndarray, torch.Tensor] latent: typing.Optional[torch.Tensor] )
参数
- prediction (
np.ndarray
,torch.Tensor
) — 预测的图像本征值,值范围在 [0, 1] 之间。对于torch.Tensor
,形状为 $(numimages numtargets) imes 3 imes height imes width$,对于np.ndarray
,形状为 $(numimages numtargets) imes height imes width imes 3$,其中numtargets
对应于本征图像分解的预测目标模态的数量。 - uncertainty (
None
,np.ndarray
,torch.Tensor
) — 从集成计算的不确定性图,值范围在 [0, 1] 之间。对于torch.Tensor
,形状为 $(numimages numtargets) imes 3 imes height imes width$,对于np.ndarray
,形状为 $(numimages numtargets) imes height imes width imes 3$。 - latent (
None
,torch.Tensor
) — 与预测相对应的潜在特征,与管道的latents
参数兼容。形状为 $(numimages numensemble) imes (numtargets 4) imes latentheight imes latentwidth$。
Marigold 本征图像分解管道的输出类。
diffusers.pipelines.marigold.MarigoldImageProcessor.visualize_intrinsics
< source >( prediction: typing.Union[numpy.ndarray, torch.Tensor, typing.List[numpy.ndarray], typing.List[torch.Tensor]] target_properties: typing.Dict[str, typing.Any] color_map: typing.Union[str, typing.Dict[str, str]] = 'binary' )
参数
- prediction (
Union[np.ndarray, torch.Tensor, List[np.ndarray], List[torch.Tensor]]
) — 本征图像分解。 - target_properties (
Dict[str, Any]
) — 分解属性。预期条目:target_names: List[str]
和一个字典,其键为prediction_space: str
、sub_target_names: List[Union[str, Null]]
(必须有 3 个条目,缺失模态为空)、up_to_scale: bool
,每个目标和子目标各一个。 - color_map (
Union[str, Dict[str, str]]
, 可选, 默认为"Spectral"
) — 用于将单通道预测转换为彩色表示的颜色图。当传入字典时,每个模态可以使用自己的颜色图进行着色。
可视化本征图像分解,例如 MarigoldIntrinsicsPipeline
的预测。
返回:包含本征图像分解可视化的 List[Dict[str, PIL.Image.Image]]
。