Transformers documentation

TIPSv2 DPT

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

and get access to the augmented documentation experience

to get started

该模型于 2026-04-13 在 HF papers 上发布,并于 2026-07-06 贡献至 Hugging Face Transformers。

TIPSv2 DPT

FlashAttention SDPA

概述

使用带有密集预测 Transformer 头(DPT)的 TIPSv2,更多信息请参阅 TIPSv2 文档。

tipsv2 architecture overview

该模型由 guarin 贡献。 原始代码可在此处找到。

您可以在 TIPSv2 集合中找到所有原始的 TIPSv2 DPT 检查点。

有关 TIPSv2 视觉和语言骨干网络以及零样本图像分类,请参阅 TIPSv2。

Pipeline
密集预测
深度估计
法线估计
语义分割
from transformers import pipeline

pipe = pipeline(task="depth-estimation", model="google/tipsv2-b14-dpt", device_map="auto")
out = pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/room.jpg")
out["depth"]  # PIL Image normalized to [min, max] of predicted_depth

# Visualization
import matplotlib.pyplot as plt
from transformers.image_utils import load_image

image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/room.jpg")

figure, axes = plt.subplots(1, 2, figsize=(10, 5))
axes[0].imshow(image)
axes[1].imshow(out["depth"])
axes[1].set_title("Depth")
for axis in axes:
    axis.axis("off")
plt.show()
tipsv2 depth estimation pipeline
from transformers import pipeline

pipe = pipeline(task="image-segmentation", model="google/tipsv2-b14-dpt", device_map="auto")
out = pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/room.jpg")
out[0]["label"] # string class label
out[0]["mask"]  # PIL Image with binary mask set to class id

# Visualization
import matplotlib.pyplot as plt
from transformers.image_utils import load_image

image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/room.jpg")

figure, axes = plt.subplots(1, 2, figsize=(10, 5))
axes[0].imshow(image)
axes[1].imshow(out[0]["mask"], cmap="gray")
axes[1].set_title(out[0]["label"])
for axis in axes:
    axis.axis("off")
plt.show()
tipsv2 image segmentation pipeline

备注

Tipsv2DptConfig

class transformers.Tipsv2DptConfig

< >

( transformers_version: str | None = Nonearchitectures: list[str] | None = Noneoutput_hidden_states: bool | None = Falsereturn_dict: bool | None = Truedtype: str | torch.dtype | None = Nonechunk_size_feed_forward: int = 0is_encoder_decoder: bool = Falseid2label: dict[int, str] | dict[str, str] | None = Nonelabel2id: dict[str, int] | dict[str, str] | None = Noneproblem_type: Literal['regression', 'single_label_classification', 'multi_label_classification'] | None = Nonebackbone_config: dict | transformers.configuration_utils.PreTrainedConfig | None = Noneneck_hidden_sizes: list[int] | tuple[int, ...] | None = Nonefusion_hidden_size: int = 256reassemble_factors: list[int | float] | tuple[int | float, ...] | None = Nonereadout_activation: str = 'gelu_pytorch_tanh'num_depth_bins: int = 256min_depth: float = 0.001max_depth: float = 10.0depth_decoder_activation: str = 'relu'semantic_loss_ignore_index: int = 255 )

参数

  • backbone_config (Union[dict, ~configuration_utils.PreTrainedConfig],可选) — 主干模型的配置。
  • neck_hidden_sizes (list[int],可选,默认为 [96, 192, 384, 768]) — 用于将主干网络的特征图投影到的隐藏层大小。
  • fusion_hidden_size (int,可选,默认为 256) — 融合前的通道数。
  • reassemble_factors (list[float],可选,默认为 [4, 2, 1, 0.5]) — 重组层的上采样/下采样因子。
  • readout_activation (str, 可选,默认为 "gelu_pytorch_tanh") — 在 readout 投影层之后应用的激活函数。
  • num_depth_bins (int,可选,默认为 256) — 深度估计头所使用的深度 bin 数量。
  • min_depth (float,可选,默认值为 0.001) — 用于深度分箱计算的最小深度值(单位:米)。
  • max_depth (float,可选,默认值为 10.0) — 用于深度分箱计算的最大深度值(单位:米)。
  • depth_decoder_activation (str,可选,默认为 "relu") — 在深度解码器投影层之后应用的激活函数。
  • semantic_loss_ignore_index (int,可选,默认为 255) — 在语义分割的交叉熵损失中需要忽略的标签索引。

这是用于存储 Tipsv2 DptModel 配置的类。它根据指定的参数实例化 Tipsv2 Dpt 模型,并定义模型架构。使用默认值实例化配置将得到与 google/tipsv2-b14-dpt 类似的配置。

配置对象继承自 PreTrainedConfig,可用于控制模型输出。有关更多信息,请参阅 PreTrainedConfig 的文档。

示例:

>>> from transformers import Tipsv2DptConfig, Tipsv2DptForDensePrediction

>>> configuration = Tipsv2DptConfig()
>>> model = Tipsv2DptForDensePrediction(configuration)
>>> configuration = model.config

Tipsv2DptImageProcessor

class transformers.Tipsv2DptImageProcessor

< >

( **kwargs: *<class 'transformers.processing_utils.ImagesKwargs'> )

参数

  • do_convert_rgb (bool,kwargs,可选,默认为 True) — 是否将图像转换为 RGB。
  • do_resize (bool,kwargs,可选,默认为 True) — 是否调整图像大小。
  • size (Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs,默认为 {'height' -- 448, 'width': 448}): 描述输入到模型的最大尺寸。
  • default_to_square (bool,kwargs,可选,默认为 True) — 当 size 为 int 时,是否在调整大小时默认使用正方形图像。
  • crop_size (Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs) — 应用 center_crop 后输出图像的尺寸。
  • resample (Annotated[Union[int, PILImageResampling, NoneType], None], kwargs,默认为 2) — 如果调整图像大小,则使用的重采样滤波器。它可以是枚举 PILImageResampling 中的一个值。仅当 do_resize 设置为 True 时才会生效。
  • do_rescale (bool,kwargs,可选,默认为 True) — 是否对图像进行重新缩放。
  • rescale_factor (float,kwargs,可选,默认为 0.00392156862745098) — 当 do_rescale 设置为 True 时,用于对图像进行缩放的缩放因子。
  • do_normalize (bool,kwargs,可选,默认为 False) — 是否对图像进行归一化。
  • image_mean (Union[float, list[float], tuple[float, ...]], kwargs, 可选) — 用于归一化的图像均值。仅当 do_normalize 设置为 True 时生效。
  • image_std (Union[float, list[float], tuple[float, ...]], kwargs, 可选) — 用于归一化的图像标准差。仅当 do_normalize 设置为 True 时生效。
  • do_pad (bool, kwargs, 可选) — 是否对图像进行填充。填充操作会将图像填充至批次中的最大尺寸,或填充至每张图像的固定正方形尺寸。具体的填充策略取决于模型。
  • pad_size (Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs) — 用于填充图像的 {"height": int, "width" int} 尺寸。必须大于为预处理提供的任何图像尺寸。如果未提供 pad_size,图像将被填充到批次中最大的高度和宽度。仅在 do_pad=True. 时应用。
  • do_center_crop (bool,kwargs,可选) — 是否对图像进行中心裁剪。
  • data_format (Union[str, ~image_utils.ChannelDimension], kwargs, 可选) — 仅支持 ChannelDimension.FIRST。为兼容旧版处理器而添加。
  • input_data_format (Union[str, ~image_utils.ChannelDimension], kwargs, 可选) — 输入图像的通道维度格式。如果未设置,则从输入图像中推断通道维度格式。可以是以下之一:
    • "channels_first" 或 ChannelDimension.FIRST:图像采用 (num_channels, height, width) 格式。
    • "channels_last" 或 ChannelDimension.LAST:图像采用 (height, width, num_channels) 格式。
    • "none" 或 ChannelDimension.NONE:图像为 (height, width) 格式。
  • device (Annotated[Union[str, torch.device, NoneType], None], kwargs) — 用于处理视频的设备。如果未设置,则从输入视频中推断设备。
  • return_tensors (Annotated[str | ~utils.generic.TensorType | None, None], kwargs) — 如果设置为 'pt',则返回堆叠的张量,否则返回张量列表。
  • disable_grouping (bool,kwargs,可选) — 是否禁用按尺寸对图像进行分组,从而逐个处理图像而非批量处理。 如果为 None,则当图像位于 CPU 上时设置为 True,否则设置为 False。此选择基于经验观察,详见此处:https://github.com/huggingface/transformers/pull/38157
  • image_seq_length (int, kwargs, optional) — 输入中每张图片所使用的图像 token 数量。 为向后兼容而添加,但在未来的模型中应将其设置为处理器属性。 如果设置为 'pt',则返回堆叠的张量,否则返回张量列表。
  • disable_grouping (bool,kwargs,可选) — 是否禁用按尺寸对图像进行分组,从而逐个处理图像而非批量处理。 如果为 None,则当图像位于 CPU 上时设置为 True,否则设置为 False。此选择基于经验观察,详见此处:https://github.com/huggingface/transformers/pull/38157
  • image_seq_length (int, kwargs, optional) — 输入中每张图片所使用的图像 token 数量。 为向后兼容而添加,但在未来的模型中应将其设置为处理器属性。 如果设置为 'pt',则返回堆叠的张量,否则返回张量列表。
  • disable_grouping (bool,kwargs,可选) — 是否禁用按尺寸对图像进行分组,从而逐个处理图像而非批量处理。 如果为 None,则当图像位于 CPU 上时设置为 True,否则设置为 False。此选择基于经验观察,详见此处:https://github.com/huggingface/transformers/pull/38157
  • image_seq_length (int, kwargs, optional) — 输入中每张图片所使用的图像 token 数量。 为向后兼容而添加,但在未来的模型中应将其设置为处理器属性。 如果设置为 'pt',则返回堆叠的张量,否则返回张量列表。
  • disable_grouping (bool,kwargs,可选) — 是否禁用按尺寸对图像进行分组,从而逐个处理图像而非批量处理。 如果为 None,则当图像位于 CPU 上时设置为 True,否则设置为 False。此选择基于经验观察,详见此处:https://github.com/huggingface/transformers/pull/38157
  • image_seq_length (int, kwargs, optional) — 输入中每张图片所使用的图像 token 数量。 为向后兼容而添加,但在未来的模型中应将其设置为处理器属性。 如果设置为 'pt',则返回堆叠的张量,否则返回张量列表。
  • disable_grouping (bool,kwargs,可选) — 是否禁用按尺寸对图像进行分组,从而逐个处理图像而非批量处理。 如果为 None,则当图像位于 CPU 上时设置为 True,否则设置为 False。此选择基于经验观察,详见此处:https://github.com/huggingface/transformers/pull/38157
  • image_seq_length (int, kwargs, optional) — 输入中每张图片所使用的图像 token 数量。 为向后兼容而添加,但在未来的模型中应将其设置为处理器属性。 如果设置为 'pt',则返回堆叠的张量,否则返回张量列表。
  • disable_grouping (bool,kwargs,可选) — 是否禁用按尺寸对图像进行分组,从而逐个处理图像而非批量处理。 如果为 None,则当图像位于 CPU 上时设置为 True,否则设置为 False。此选择基于经验观察,详见此处:https://github.com/huggingface/transformers/pull/38157
  • image_seq_length (int, kwargs, optional) — 输入中每张图片所使用的图像 token 数量。 为向后兼容而添加,但在未来的模型中应将其设置为处理器属性。 如果设置为 'pt',则返回堆叠的张量,否则返回张量列表。
  • disable_grouping (bool,kwargs,可选) — 是否禁用按尺寸对图像进行分组,从而逐个处理图像而非批量处理。 如果为 None,则当图像位于 CPU 上时设置为 True,否则设置为 False。此选择基于经验观察,详见此处:https://github.com/huggingface/transformers/pull/38157
  • image_seq_length (int, kwargs, optional) — 输入中每张图片所使用的图像 token 数量。 为向后兼容而添加,但在未来的模型中应将其设置为处理器属性。 如果设置为 'pt',则返回堆叠的张量,否则返回张量列表。
  • disable_grouping (bool,kwargs,可选) — 是否禁用按尺寸对图像进行分组,从而逐个处理图像而非批量处理。 如果为 None,则当图像位于 CPU 上时设置为 True,否则设置为 False。此选择基于经验观察,详见此处:https://github.com/huggingface/transformers/pull/38157
  • image_seq_length (int, kwargs, optional) — 输入中每张图片所使用的图像 token 数量。 为向后兼容而添加,但在未来的模型中应将其设置为处理器属性。 如果设置为 'pt',则返回堆叠的张量,否则返回张量列表。
  • disable_grouping (bool,kwargs,可选) — 是否禁用按尺寸对图像进行分组,从而逐个处理图像而非批量处理。 如果为 None,则当图像位于 CPU 上时设置为 True,否则设置为 False。此选择基于经验观察,详见此处:https://github.com/huggingface/transformers/pull/38157
  • image_seq_length (int, kwargs, optional) — 输入中每张图片所使用的图像 token 数量。 为向后兼容而添加,但在未来的模型中应将其设置为处理器属性。 如果设置为 'pt',则返回堆叠的张量,否则返回张量列表。
  • disable_grouping (bool,kwargs,可选) — 是否禁用按尺寸对图像进行分组,从而逐个处理图像而非批量处理。 如果为 None,则当图像位于 CPU 上时设置为 True,否则设置为 False。此选择基于经验观察,详见此处:https://github.com/huggingface/transformers/pull/38157
  • image_seq_length (int, kwargs, optional) — 输入中每张图片所使用的图像 token 数量。 为向后兼容而添加,但在未来的模型中应将其设置为处理器属性。 如果设置为 'pt',则返回堆叠的张量,否则返回张量列表。
  • disable_grouping (bool,kwargs,可选) — 是否禁用按尺寸对图像进行分组,从而逐个处理图像而非批量处理。 如果为 None,则当图像位于 CPU 上时设置为 True,否则设置为 False。此选择基于经验观察,详见此处:https://github.com/huggingface/transformers/pull/38157
  • image_seq_length (int, kwargs, optional) — 输入中每张图片所使用的图像 token 数量。 为向后兼容而添加,但在未来的模型中应将其设置为处理器属性。 如果设置为 'pt',则返回堆叠的张量,否则返回张量列表。
  • disable_grouping (bool,kwargs,可选) — 是否禁用按尺寸对图像进行分组,从而逐个处理图像而非批量处理。 如果为 None,则当图像位于 CPU 上时设置为 True,否则设置为 False。此选择基于经验观察,详见此处:https://github.com/huggingface/transformers/pull/38157
  • image_seq_length (int, kwargs, optional) — 输入中每张图片所使用的图像 token 数量。 为向后兼容而添加,但在未来的模型中应将其设置为处理器属性。 如果设置为 'pt',则返回堆叠的张量,否则返回张量列表。
  • disable_grouping (bool,kwargs,可选) — 是否禁用按尺寸对图像进行分组,从而逐个处理图像而非批量处理。 如果为 None,则当图像位于 CPU 上时设置为 True,否则设置为 False。此选择基于经验观察,详见此处:https://github.com/huggingface/transformers/pull/38157
  • image_seq_length (int, kwargs, optional) — 输入中每张图片所使用的图像 token 数量。 为向后兼容而添加,但在未来的模型中应将其设置为处理器属性。 如果设置为 'pt',则返回堆叠的张量,否则返回张量列表。
  • disable_grouping (bool,kwargs,可选) — 是否禁用按尺寸对图像进行分组,从而逐个处理图像而非批量处理。 如果为 None,则当图像位于 CPU 上时设置为 True,否则设置为 False。此选择基于经验观察,详见此处:https://github.com/huggingface/transformers/pull/38157
  • image_seq_length (int, kwargs, optional) — 输入中每张图片所使用的图像 token 数量。 为向后兼容而添加,但在未来的模型中应将其设置为处理器属性。 如果设置为 'pt',则返回堆叠的张量,否则返回张量列表。
  • disable_grouping (bool,kwargs,可选) — 是否禁用按尺寸对图像进行分组,从而逐个处理图像而非批量处理。 如果为 None,则当图像位于 CPU 上时设置为 True,否则设置为 False。此选择基于经验观察,详见此处:https://github.com/huggingface/transformers/pull/38157
  • image_seq_length (int, kwargs, optional) — 输入中每张图片所使用的图像 token 数量。 为向后兼容而添加,但在未来的模型中应将其设置为处理器属性。 如果设置为 'pt',则返回堆叠的张量,否则返回张量列表。
  • disable_grouping (bool,kwargs,可选) — 是否禁用按尺寸对图像进行分组,从而逐个处理图像而非批量处理。 如果为 None,则当图像位于 CPU 上时设置为 True,否则设置为 False。此选择基于经验观察,详见此处:https://github.com/huggingface/transformers/pull/38157
  • image_seq_length (int, kwargs, optional) — 输入中每张图片所使用的图像 token 数量。 为向后兼容而添加,但在未来的模型中应将其设置为处理器属性。 如果设置为 'pt',则返回堆叠的张量,否则返回张量列表。
  • disable_grouping (bool,kwargs,可选) — 是否禁用按尺寸对图像进行分组,从而逐个处理图像而非批量处理。 如果为 None,则当图像位于 CPU 上时设置为 True,否则设置为 False。此选择基于经验观察,详见此处:https://github.com/huggingface/transformers/pull/38157
  • image_seq_length (int, kwargs, optional) — 输入中每张图片所使用的图像 token 数量。 为向后兼容而添加,但在未来的模型中应将其设置为处理器属性。 如果设置为 'pt',则返回堆叠的张量,否则返回张量列表。
  • disable_grouping (bool,kwargs,可选) — 是否禁用按尺寸对图像进行分组,从而逐个处理图像而非批量处理。 如果为 None,则当图像位于 CPU 上时设置为 True,否则设置为 False。此选择基于经验观察,详见此处:https://github.com/huggingface/transformers/pull/38157
  • image_seq_length (int, kwargs, optional) — 输入中每张图片所使用的图像 token 数量。 为向后兼容而添加,但在未来的模型中应将其设置为处理器属性。 如果设置为 'pt',则返回堆叠的张量,否则返回张量列表。
  • disable_grouping (bool,kwargs,可选) — 是否禁用按尺寸对图像进行分组,从而逐个处理图像而非批量处理。 如果为 None,则当图像位于 CPU 上时设置为 True,否则设置为 False。此选择基于经验观察,详见此处:https://github.com/huggingface/transformers/pull/38157
  • image_seq_length (int,kwargs,可选) — 输入中每张图片所使用的图像 token 数量。 为向后兼容而添加,但在未来的模型中,应将其设置为处理器的属性。
  • Returns 如果设置为 'pt',则返回堆叠的张量,否则返回张量列表。 —

构建一个 Tipsv2DptImageProcessor 图像处理器。

disable_grouping (bool, kwargs, 可选): 是否禁用按尺寸对图像进行分组,从而逐个处理图像而非批量处理。 如果为 None,则当图像位于 CPU 上时设置为 True,否则设置为 False。此选择基于经验观察,详情见此处:https://github.com/huggingface/transformers/pull/38157 image_seq_length (int, kwargs, 可选): 输入中每张图像所使用的图像 token 数量。 为向后兼容而添加,但在未来的模型中应将其设置为处理器属性。

预处理

< >

( images: typing.Union[ForwardRef('PIL.Image.Image'), numpy.ndarray, ForwardRef('torch.Tensor'), list['PIL.Image.Image'], list[numpy.ndarray], list['torch.Tensor']]*argsimage_like_kwargs: dict[str, typing.Any] | None = None**kwargs: *<class 'transformers.processing_utils.ImagesKwargs'> ) → ~image_processing_base.BatchFeature

参数

  • images (Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]]) — 要预处理的图像。期望输入单张图像或一批图像,其像素值范围为 0 到 255。如果传入的图像像素值在 0 到 1 之间,请设置 do_rescale=False。
  • image_like_kwargs (dict[str, Any], 可选) — 用于额外图像类输入的开发者标志,这些输入也将被预处理。仅在以关键字参数传递输入不起作用时使用此标志。例如,preprocess(images, masks=masks) 是首选方式,但对于某些模型会导致参数优先级问题。在这种情况下,可以改用 preprocess(images, image_like_inputs={"masks": masks})。
  • do_convert_rgb (bool,kwargs,可选) — 是否将图像转换为 RGB。
  • do_resize (bool,kwargs,可选) — 是否调整图像大小。
  • size (Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs) — 描述模型的最大输入维度。
  • default_to_square (bool, kwargs, 可选) — 当 size 为整数时,是否在调整大小时默认使用正方形图像。
  • crop_size (Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs) — 应用 center_crop 后输出图像的尺寸。
  • resample (Annotated[Union[int, PILImageResampling, NoneType], None], kwargs) — 如果调整图像大小,则使用的重采样滤波器。可以是枚举 PILImageResampling 中的一个值。仅当 do_resize 设置为 True 时生效。
  • do_rescale (bool,kwargs,可选) — 是否对图像进行重新缩放。
  • rescale_factor (float, kwargs, 可选) — 如果 do_rescale 设置为 True,则用于对图像进行缩放的缩放因子。
  • do_normalize (bool,kwargs,可选) — 是否对图像进行归一化。
  • image_mean (Union[float, list[float], tuple[float, ...]], kwargs, 可选) — 用于归一化的图像均值。仅当 do_normalize 设置为 True 时生效。
  • image_std (Union[float, list[float], tuple[float, ...]], kwargs, 可选) — 用于归一化的图像标准差。仅当 do_normalize 设置为 True 时生效。
  • do_pad (bool, kwargs, 可选) — 是否对图像进行填充。填充操作会将图像填充至批次中的最大尺寸,或填充至每张图像的固定正方形尺寸。具体的填充策略取决于模型。
  • pad_size (Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs) — 用于填充图像的 {"height": int, "width" int} 尺寸。必须大于为预处理提供的任何图像尺寸。如果未提供 pad_size,图像将被填充到批次中最大的高度和宽度。仅在 do_pad=True. 时应用。
  • do_center_crop (bool,kwargs,可选) — 是否对图像进行中心裁剪。
  • data_format (Union[str, ~image_utils.ChannelDimension], kwargs, 可选) — 仅支持 ChannelDimension.FIRST。为兼容旧版处理器而添加。
  • input_data_format (Union[str, ~image_utils.ChannelDimension], kwargs, 可选) — 输入图像的通道维度格式。如果未设置,则从输入图像中推断通道维度格式。可以是以下之一:
    • "channels_first" 或 ChannelDimension.FIRST:图像采用 (num_channels, height, width) 格式。
    • "channels_last" 或 ChannelDimension.LAST:图像采用 (height, width, num_channels) 格式。
    • "none" 或 ChannelDimension.NONE:图像为 (height, width) 格式。
  • device (Annotated[Union[str, torch.device, NoneType], None], kwargs) — 用于处理视频的设备。如果未设置,则从输入视频中推断设备。
  • return_tensors (Annotated[str | ~utils.generic.TensorType | None, None], kwargs) — 如果设置为 'pt',则返回堆叠的张量,否则返回张量列表。
  • disable_grouping (bool,kwargs,可选) — 是否禁用按尺寸对图像进行分组,从而逐个处理图像而非批量处理。 如果为 None,则当图像位于 CPU 上时设置为 True,否则设置为 False。此选择基于经验观察,详见此处:https://github.com/huggingface/transformers/pull/38157
  • image_seq_length (int,kwargs,可选) — 输入中每张图片所使用的图像 token 数量。 为向后兼容而添加,但在未来的模型中,应将其设置为处理器的属性。

返回值

~image_processing_base.BatchFeature

  • data (dict) — 由 call 方法返回的列表/数组/张量字典(如 ‘pixel_values’ 等)。
  • tensor_type (Union[None, str, TensorType], 可选) — 您可以在此处指定 tensor_type,以便在初始化时将 PyTorch/Numpy 张量中的整数列表进行转换。

预处理一张图像或一批图像。

post_process_depth_estimation

< >

( outputstarget_sizes: transformers.utils.generic.TensorType | list[tuple[int, int]] | None = None ) → list[dict[str, torch.Tensor]]

参数

  • outputs(DepthEstimatorOutput 或 Tipsv2DptDensePredictorOutput)— 模型的原始输出。
  • target_sizes (TensorType 或 list[tuple[int, int]],可选) — 形状为 (batch_size, 2) 的张量,或包含每个图像目标尺寸(高度、宽度)的元组列表(tuple[int, int])。如果设为 None,则不会调整预测结果的尺寸。

返回值

list[dict[str, torch.Tensor]]

一个字典列表,其中每个字典包含表示处理后深度预测的张量。

将 Tipsv2DptForDepthEstimation 或 Tipsv2DptForDensePrediction 的输出转换为最终的深度预测。

post_process_normal_estimation

< >

( outputstarget_sizes: transformers.utils.generic.TensorType | list[tuple[int, int]] | None = None )

参数

  • outputs(Tipsv2DptNormalEstimatorOutput 或 Tipsv2DptDensePredictorOutput)— 模型的原始输出。
  • target_sizes (TensorType 或 list[tuple[int, int]],可选) — 形状为 (batch_size, 2) 的张量,或包含每个图像目标尺寸(高度、宽度)的元组列表(tuple[int, int])。如果设为 None,则不会调整预测结果的尺寸。

将 Tipsv2DptForNormalEstimation 或 Tipsv2DptForDensePrediction 的输出转换为 L2 归一化的表面法线图。

post_process_semantic_segmentation

< >

( outputstarget_sizes: transformers.utils.generic.TensorType | list[tuple[int, int]] | None = Nonereturn_segmentation_scores: bool = False ) → list[torch.Tensor] or list[SemanticSegmentationPostProcessorOutput]

参数

  • outputs(SemanticSegmenterOutput 或 Tipsv2DptDensePredictorOutput)— 模型的原始输出。
  • target_sizes [(TensorType 或 list[tuple[int, int]], optional) — 形状为 (batch_size, 2) 的张量,或包含每个图像目标尺寸(高度、宽度)的元组列表(tuple[int, int])。如果设为 None,则不会调整预测结果的尺寸。
  • return_segmentation_scores (bool,可选,默认为 False) — 是否随分割图一起返回分割分数。当 True 时,返回列表中的每个元素都是一个 SemanticSegmentationPostProcessorOutput,包含字段 segmentation(类别 ID,形状为 (height, width))和 segmentation_scores(形状为 (num_classes, height, width))。

返回值

list[torch.Tensor] 或 list[SemanticSegmentationPostProcessorOutput]

当 return_segmentation_scores=False(默认值)时,返回一个长度为 batch_size 的列表,其中每个元素都是形状为 (height, width) 的分割图,包含类别 ID。当 return_segmentation_scores=True 时,返回一个 SemanticSegmentationPostProcessorOutput 列表,包含字段 segmentation(类别 ID,形状为 (height, width))和 segmentation_scores(形状为 (num_classes, height, width))。在这两种情况下,(height, width) 对应于目标尺寸(如果指定了 target_sizes)。

将 Tipsv2DptForSemanticSegmentation 或 Tipsv2DptForDensePrediction 的输出转换为语义分割图。

Tipsv2DptForDensePrediction

class transformers.Tipsv2DptForDensePrediction

< >

( config: Tipsv2DptConfig )

参数

  • config (Tipsv2DptConfig) — 模型的配置类,包含模型的所有参数。使用配置文件进行初始化时,不会加载与模型关联的权重,仅加载配置。请查看 from_pretrained() 方法以加载模型权重。

TIPSv2-DPT 模型具有三个独立的头,分别用于深度估计、表面法线估计和语义分割——只需运行一次共享骨干网络的前向传播。

该模型继承自 PreTrainedModel。请查阅父类文档,了解该库为所有模型实现的通用方法(例如下载或保存、调整输入嵌入大小、剪枝头等)。

该模型也是 PyTorch torch.nn.Module 的子类。 请将其作为常规的 PyTorch Module 使用,有关通用用法和行为的所有事项,请参阅 PyTorch 文档。

forward

< >

( pixel_values: Tensor**kwargs: Unpack ) → Tipsv2DptDensePredictorOutput or tuple(torch.Tensor)

参数

返回值

Tipsv2DptDensePredictorOutput 或 tuple(torch.Tensor)

Tipsv2DptDensePredictorOutput 或 torch.Tensor 元组(当传入 return_dict=False 或 config.return_dict=False 时),其包含的元素取决于配置(Tipsv2DptConfig)和输入。

Tipsv2DptForDensePrediction 的 forward 方法重写了 __call__ 特殊方法。

尽管前向传播的实现需要在此函数中定义,但之后应调用 Module 实例,而不是直接调用此函数,因为前者会负责执行预处理和后处理步骤,而后者则会静默地忽略这些步骤。

  • predicted_depth(形状为 (batch_size, height, width) 的 torch.Tensor,可选)— 每个像素的预测深度。

  • normals(形状为 (batch_size, 3, height, width) 的 torch.Tensor)— 原始法线贴图预测值(未归一化)。

  • segmentation_logits(形状为 (batch_size, config.num_labels, height, width) 的 torch.Tensor)— 每个像素的分类分数。

    返回的 logits 不一定与作为输入传入的 `pixel_values` 具有相同的尺寸。这是为了避免进行两次插值,从而在用户需要将 logits 调整回原始图像尺寸作为后处理时损失一些质量。您应始终检查 logits 的形状,并根据需要进行调整。
  • hidden_states (tuple[torch.Tensor, ...],可选,当传入 output_hidden_states=True 或 config.output_hidden_states=True 时返回) — 一个 torch.Tensor 元组(如果模型具有嵌入层,则包含嵌入层输出的一个张量,以及每个层输出的一个张量),形状为 (batch_size, sequence_length, hidden_size)。

    模型在每一层输出处的隐藏状态,以及可选的初始嵌入输出。

  • attentions (tuple[torch.Tensor, ...],可选,当传入 output_attentions=True 或 config.output_attentions=True 时返回) — 一个 torch.Tensor 元组(每层一个),形状为 (batch_size, num_heads, sequence_length, sequence_length)。

    注意力权重,即经过注意力 softmax 之后的权重,用于在自注意力头中计算加权平均值。

示例:

>>> import torch
>>> from transformers import Tipsv2DptForDensePrediction, AutoImageProcessor
>>> from transformers.image_utils import load_image

>>> model_id = "google/tipsv2-b14-dpt"
>>> model = Tipsv2DptForDensePrediction.from_pretrained(model_id, device_map="auto")
>>> image_processor = AutoImageProcessor.from_pretrained(model_id)

>>> image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/room.jpg")
>>> inputs = image_processor(images=image, return_tensors="pt").to(model.device)

>>> with torch.no_grad():
...     outputs = model(**inputs)

>>> # outputs.predicted_depth: (batch_size, height, width) tensor with predicted depth in meters
>>> # outputs.normals: (batch_size, 3, height, width) tensor with normals in XYZ format (unnormalized)
>>> # outputs.segmentation_logits: (batch_size, config.num_labels, height, width) tensor with segmentation logits
>>> depth_results = image_processor.post_process_depth_estimation(outputs, target_sizes=[(image.height, image.width)])
>>> normal_results = image_processor.post_process_normal_estimation(outputs, target_sizes=[(image.height, image.width)])
>>> segmentation_results = image_processor.post_process_semantic_segmentation(outputs, target_sizes=[(image.height, image.width)])

>>> predicted_depth = depth_results[0]["predicted_depth"]  # (height, width) tensor with predicted depth in meters
>>> normals = normal_results[0]["normals"]  # (3, height, width) tensor with normals in XYZ format (L2-normalized)
>>> segmentation = segmentation_results[0]  # (height, width) tensor with class ids

Tipsv2DptForDepthEstimation

class transformers.Tipsv2DptForDepthEstimation

< >

( config: Tipsv2DptConfig )

参数

  • config (Tipsv2DptConfig) — 模型的配置类,包含模型的所有参数。使用配置文件进行初始化时,不会加载与模型关联的权重,仅加载配置。请查看 from_pretrained() 方法以加载模型权重。

带有单目深度估计头的 TIPSv2-DPT 模型。

该模型继承自 PreTrainedModel。请查阅父类文档,了解该库为所有模型实现的通用方法(例如下载或保存、调整输入嵌入大小、剪枝头等)。

该模型也是 PyTorch torch.nn.Module 的子类。 请将其作为常规的 PyTorch Module 使用,有关通用用法和行为的所有事项,请参阅 PyTorch 文档。

forward

< >

( pixel_values: Tensorlabels: typing.Optional[torch.Tensor] = None**kwargs: Unpack ) → DepthEstimatorOutput or tuple(torch.Tensor)

参数

  • pixel_values (torch.Tensor,形状为 (batch_size, num_channels, image_size, image_size)) — 与输入图像对应的张量。可以使用 Tipsv2DptImageProcessor 获取像素值。有关详细信息,请参阅 Tipsv2DptImageProcessor.call()(processor_class 使用 Tipsv2DptImageProcessor 处理图像)。
  • labels(形状为 (batch_size, height, width) 的 torch.LongTensor,可选) — 用于计算损失的真实深度估计图。

返回值

DepthEstimatorOutput 或 tuple(torch.Tensor)

DepthEstimatorOutput 或 torch.Tensor 元组(如果传入 return_dict=False 或 config.return_dict=False),其包含的元素取决于配置(Tipsv2DptConfig)和输入。

Tipsv2DptForDepthEstimation 的 forward 方法重写了 __call__ 特殊方法。

尽管前向传播的实现需要在此函数中定义,但之后应调用 Module 实例,而不是直接调用此函数,因为前者会负责执行预处理和后处理步骤,而后者则会静默地忽略这些步骤。

  • loss (torch.Tensor,形状为 (1,),可选,当提供 labels 时返回) — 分类损失(如果 config.num_labels==1,则为回归损失)。

  • predicted_depth(形状为 (batch_size, height, width) 的 torch.Tensor)— 每个像素的预测深度。

  • hidden_states (tuple(torch.Tensor),可选,当传入 output_hidden_states=True 或 config.output_hidden_states=True 时返回) — 一个 torch.Tensor 元组(如果模型具有嵌入层,则包含嵌入层输出的一个张量,以及每个层输出的一个张量),形状为 (batch_size, num_channels, height, width)。

    模型在每一层输出处的隐藏状态,以及可选的初始嵌入输出。

  • attentions (tuple(torch.Tensor),可选,当传入 output_attentions=True 或 config.output_attentions=True 时返回) — 一个 torch.Tensor 元组(每层一个),形状为 (batch_size, num_heads, patch_size, sequence_length)。

    注意力权重,即经过注意力 softmax 之后的权重,用于在自注意力头中计算加权平均值。

示例:

>>> import torch
>>> from transformers import AutoModelForDepthEstimation, AutoImageProcessor
>>> from transformers.image_utils import load_image

>>> model_id = "google/tipsv2-b14-dpt"
>>> model = AutoModelForDepthEstimation.from_pretrained(model_id, device_map="auto")
>>> image_processor = AutoImageProcessor.from_pretrained(model_id)

>>> image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/room.jpg")
>>> inputs = image_processor(images=image, return_tensors="pt").to(model.device)

>>> with torch.no_grad():
...     outputs = model(**inputs)

>>> results = image_processor.post_process_depth_estimation(outputs, target_sizes=[(image.height, image.width)])
>>> predicted_depth = results[0]["predicted_depth"]  # (height, width) tensor with predicted depth in meters

Tipsv2DptForNormalEstimation

class transformers.Tipsv2DptForNormalEstimation

< >

( config: Tipsv2DptConfig )

参数

  • config (Tipsv2DptConfig) — 模型的配置类,包含模型的所有参数。使用配置文件进行初始化时,不会加载与模型关联的权重,仅加载配置。请查看 from_pretrained() 方法以加载模型权重。

带有表面法线估计头的 TIPSv2-DPT 模型。

该模型继承自 PreTrainedModel。请查阅父类文档,了解该库为所有模型实现的通用方法(例如下载或保存、调整输入嵌入大小、剪枝头等)。

该模型也是 PyTorch torch.nn.Module 的子类。 请将其作为常规的 PyTorch Module 使用,有关通用用法和行为的所有事项,请参阅 PyTorch 文档。

forward

< >

( pixel_values: Tensorlabels: typing.Optional[torch.Tensor] = None**kwargs: Unpack ) → Tipsv2DptNormalEstimatorOutput or tuple(torch.Tensor)

参数

  • pixel_values (torch.Tensor,形状为 (batch_size, num_channels, image_size, image_size)) — 与输入图像对应的张量。可以使用 Tipsv2DptImageProcessor 获取像素值。有关详细信息,请参阅 Tipsv2DptImageProcessor.call()(processor_class 使用 Tipsv2DptImageProcessor 处理图像)。
  • labels(形状为 (batch_size, sequence_length) 的 torch.Tensor,可选)— 用于计算掩码语言建模损失的标签。索引值应在 [0, ..., config.vocab_size] 范围内,或为 -100(参见 input_ids 的文档字符串)。索引值设为 -100 的 token 将被忽略(即被掩码),损失仅针对标签位于 [0, ..., config.vocab_size] 范围内的 token 进行计算。

返回值

Tipsv2DptNormalEstimatorOutput 或 tuple(torch.Tensor)

Tipsv2DptNormalEstimatorOutput 或 torch.Tensor 元组(当传入 return_dict=False 或 config.return_dict=False 时),其包含的元素取决于配置(Tipsv2DptConfig)和输入。

Tipsv2DptForNormalEstimation 的 forward 方法重写了 __call__ 特殊方法。

尽管前向传播的实现需要在此函数中定义,但之后应调用 Module 实例,而不是直接调用此函数,因为前者会负责执行预处理和后处理步骤,而后者则会静默地忽略这些步骤。

  • loss (torch.Tensor,形状为 (1,),可选,在提供 labels 时返回) — 法线估计损失。
  • normals(形状为 (batch_size, num_labels, height, width) 的 torch.Tensor)— 模型输出的原始法线贴图预测值(未归一化)。
  • hidden_states (tuple(torch.Tensor),可选,在传入 output_hidden_states=True 或 config.output_hidden_states=True 时返回) — torch.Tensor 元组(包含嵌入层的输出以及每个阶段的输出) 形状为 (batch_size, sequence_length, hidden_size)。模型在每一层输出处的隐藏状态,以及初始嵌入层的输出。
  • attentions (tuple(torch.Tensor),可选,当传入 output_attentions=True 或 config.output_attentions=True 时返回) — 一个 torch.Tensor 元组(每层一个),形状为 (batch_size, num_heads, sequence_length, sequence_length)。注意力 softmax 之后的注意力权重。

示例:

>>> import torch
>>> from transformers import Tipsv2DptForNormalEstimation, AutoImageProcessor
>>> from transformers.image_utils import load_image

>>> model_id = "google/tipsv2-b14-dpt"
>>> model = Tipsv2DptForNormalEstimation.from_pretrained(model_id, device_map="auto")
>>> image_processor = AutoImageProcessor.from_pretrained(model_id)

>>> image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/room.jpg")
>>> inputs = image_processor(images=image, return_tensors="pt").to(model.device)

>>> with torch.no_grad():
...     outputs = model(**inputs)

>>> results = image_processor.post_process_normal_estimation(outputs, target_sizes=[(image.height, image.width)])
>>> normals = results[0]["normals"]  # (3, height, width) tensor with normals in XYZ format (L2-normalized)

Tipsv2DptForSemanticSegmentation

class transformers.Tipsv2DptForSemanticSegmentation

< >

( config: Tipsv2DptConfig )

参数

  • config (Tipsv2DptConfig) — 模型的配置类,包含模型的所有参数。使用配置文件进行初始化时,不会加载与模型关联的权重,仅加载配置。请查看 from_pretrained() 方法以加载模型权重。

带有语义分割头的 TIPSv2-DPT 模型。

该模型继承自 PreTrainedModel。请查阅父类文档,了解该库为所有模型实现的通用方法(例如下载或保存、调整输入嵌入大小、剪枝头等)。

该模型也是 PyTorch torch.nn.Module 的子类。 请将其作为常规的 PyTorch Module 使用,有关通用用法和行为的所有事项,请参阅 PyTorch 文档。

forward

< >

( pixel_values: Tensorlabels: typing.Optional[torch.LongTensor] = None**kwargs: Unpack ) → SemanticSegmenterOutput or tuple(torch.Tensor)

参数

  • pixel_values (torch.Tensor,形状为 (batch_size, num_channels, image_size, image_size)) — 与输入图像对应的张量。可以使用 Tipsv2DptImageProcessor 获取像素值。有关详细信息,请参阅 Tipsv2DptImageProcessor.call()(processor_class 使用 Tipsv2DptImageProcessor 处理图像)。
  • labels(形状为 (batch_size, height, width) 的 torch.LongTensor,可选) — 用于计算损失的语义分割真值图。索引应在 [0, ..., config.num_labels - 1] 范围内。如果 config.num_labels > 1,则计算分类损失(交叉熵)。

返回值

SemanticSegmenterOutput 或 tuple(torch.Tensor)

一个 SemanticSegmenterOutput 或 torch.Tensor 元组(如果传入了 return_dict=False 或 config.return_dict=False),其包含的元素取决于配置(Tipsv2DptConfig)和输入。

Tipsv2DptForSemanticSegmentation 的 forward 方法重写了 __call__ 特殊方法。

尽管前向传播的实现需要在此函数中定义,但之后应调用 Module 实例,而不是直接调用此函数,因为前者会负责执行预处理和后处理步骤,而后者则会静默地忽略这些步骤。

  • loss (torch.Tensor,形状为 (1,),可选,当提供 labels 时返回) — 分类损失(如果 config.num_labels==1,则为回归损失)。

  • logits(形状为 (batch_size, config.num_labels, logits_height, logits_width) 的 torch.Tensor)— 每个像素的分类分数。

    返回的 logits 的大小不一定与作为输入传入的 pixel_values 相同。这样做的目的是避免进行两次插值,从而在用户需要作为后处理将 logits 调整回原始图像大小时损失一些质量。您应始终检查 logits 的形状,并根据需要进行调整。

  • hidden_states (tuple(torch.Tensor),可选,当传入 output_hidden_states=True 或 config.output_hidden_states=True 时返回) — 一个 torch.Tensor 元组(如果模型具有嵌入层,则包含嵌入层的输出,以及每一层的输出),形状为 (batch_size, patch_size, hidden_size)。

    模型在每一层输出处的隐藏状态,以及可选的初始嵌入输出。

  • attentions (tuple(torch.Tensor),可选,当传入 output_attentions=True 或 config.output_attentions=True 时返回) — 一个 torch.Tensor 元组(每层一个),形状为 (batch_size, num_heads, patch_size, sequence_length)。

    注意力权重,即经过注意力 softmax 之后的权重,用于在自注意力头中计算加权平均值。

示例:

>>> import torch
>>> from transformers import AutoModelForSemanticSegmentation, AutoImageProcessor
>>> from transformers.image_utils import load_image

>>> model_id = "google/tipsv2-b14-dpt"
>>> model = AutoModelForSemanticSegmentation.from_pretrained(model_id, device_map="auto")
>>> image_processor = AutoImageProcessor.from_pretrained(model_id)

>>> image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/room.jpg")
>>> inputs = image_processor(images=image, return_tensors="pt").to(model.device)

>>> with torch.no_grad():
...     outputs = model(**inputs)

>>> results = image_processor.post_process_semantic_segmentation(outputs, target_sizes=[(image.height, image.width)])
>>> segmentation_map = results[0]  # (height, width) tensor with class ids
Update on GitHub