# TIPSv2 DPT

    
        
        
    

## 概述

带有密集预测 Transformer 头（DPT）的 [TIPSv2](./tipsv2)，更多信息请参阅 [TIPSv2](./tipsv2) 文档。<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/tipsv2_architecture.jpg" alt="tipsv2 architecture overview" width="600"/>

该模型由 [guarin](https://huggingface.co/guarin) 贡献。原始代码可在[此处](https://github.com/google-deepmind/tips)找到。

您可以在 [TIPSv2](https://huggingface.co/collections/google/tipsv2) 集合中找到所有原始的 TIPSv2 DPT 检查点。

> [!TIP]
> 有关 TIPSv2 视觉和语言骨干网络以及零样本图像分类，请参阅 [TIPSv2](./tipsv2)。

```python
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()
```

<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/tipsv2_depth_estimation.jpg"
alt="tipsv2 depth estimation pipeline" width="600"/>

```python
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()
```

<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/tipsv2_pipeline_segmentation.jpg"
alt="tipsv2 image segmentation pipeline" width="600"/>

使用 [Tipsv2DptForDensePrediction](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptForDensePrediction) 可以在共享骨干网络上通过单次前向传播同时执行所有三项任务（深度、法线和分割）。

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

# Visualization
import matplotlib.pyplot as plt

# Convert L2-normalized normals in [-1, 1] to RGB in [0, 255]
normals_rgb = ((normals + 1.0) / 2.0 * 255.0).clamp(0, 255).to(torch.uint8)

figure, axes = plt.subplots(2, 2, figsize=(10, 6))
axes[0, 0].imshow(image)
axes[0, 1].imshow(predicted_depth.cpu())
axes[0, 1].set_title("Depth")
axes[1, 0].imshow(normals_rgb.permute(1, 2, 0).cpu())
axes[1, 0].set_title("Normals")
axes[1, 1].imshow(segmentation.cpu())
axes[1, 1].set_title("Segmentation")
for axis in axes.flat:
    axis.axis("off")
plt.show()
```

<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/tipsv2_all_tasks.jpg"
alt="tipsv2 all tasks" width="600"/>

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

# Visualization
import matplotlib.pyplot as plt

figure, axes = plt.subplots(1, 2, figsize=(10, 5))
axes[0].imshow(image)
axes[1].imshow(predicted_depth.cpu())
axes[1].set_title("Depth")
for axis in axes:
    axis.axis("off")
plt.show()
```

<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/tipsv2_depth_estimation.jpg"
alt="tipsv2 depth estimation" width="600"/>

```python
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)

# Visualization
import matplotlib.pyplot as plt

# Convert L2-normalized normals in [-1, 1] to RGB in [0, 255]
normals_rgb = ((normals + 1.0) / 2.0 * 255.0).clamp(0, 255).to(torch.uint8)

figure, axes = plt.subplots(1, 2, figsize=(10, 5))
axes[0].imshow(image)
axes[1].imshow(normals_rgb.permute(1, 2, 0).cpu())
axes[1].set_title("Normals")
for axis in axes:
    axis.axis("off")
plt.show()
```

<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/tipsv2_normal_estimation.jpg"
alt="tipsv2 normal estimation" width="600"/>

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

# Visualization
import matplotlib.pyplot as plt

figure, axes = plt.subplots(1, 2, figsize=(10, 5))
axes[0].imshow(image)
axes[1].imshow(segmentation_map.cpu())
axes[1].set_title("Segmentation")
for axis in axes:
    axis.axis("off")
plt.show()
```

<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/tipsv2_semantic_segmentation.jpg"
alt="tipsv2 semantic segmentation" width="600"/>

## 备注

- [Tipsv2DptForDensePrediction](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptForDensePrediction) 执行一次共享骨干网络的前向传播，并同时生成三个输出：`predicted_depth`、`normals` 和 `segmentation_logits`。当您需要对同一图像执行全部三项任务时，请使用该模型。
- [Tipsv2DptForDepthEstimation](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptForDepthEstimation)、[Tipsv2DptForNormalEstimation](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptForNormalEstimation) 和 [Tipsv2DptForSemanticSegmentation](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptForSemanticSegmentation) 是单任务变体，它们会丢弃其他任务头。请在 pipeline 中或针对单一任务进行推理时使用它们。

## Tipsv2DptConfig[[transformers.Tipsv2DptConfig]]

#### transformers.Tipsv2DptConfig[[transformers.Tipsv2DptConfig]]

```python
transformers.Tipsv2DptConfig(transformers_version: str | None = None, architectures: list[str] | None = None, output_hidden_states: bool | None = False, return_dict: bool | None = True, dtype: str | torch.dtype | None = None, chunk_size_feed_forward: int = 0, is_encoder_decoder: bool = False, id2label: dict[int, str] | dict[str, str] | None = None, label2id: dict[str, int] | dict[str, str] | None = None, problem_type: Literal['regression', 'single_label_classification', 'multi_label_classification'] | None = None, backbone_config: dict | transformers.configuration_utils.PreTrainedConfig | None = None, neck_hidden_sizes: list[int] | tuple[int, ...] | None = None, fusion_hidden_size: int = 256, reassemble_factors: list[int | float] | tuple[int | float, ...] | None = None, readout_activation: str = 'gelu_pytorch_tanh', num_depth_bins: int = 256, min_depth: float = 0.001, max_depth: float = 10.0, depth_decoder_activation: str = 'relu', semantic_loss_ignore_index: int = 255)
```

[来源](https://github.com/huggingface/transformers/blob/v5.23.0/src/transformers/models/tipsv2_dpt/configuration_tipsv2_dpt.py#L30)

**参数：**

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"`) : 在读出投影层之后应用的激活函数。

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](https://huggingface.co/google/tipsv2-b14-dpt) 类似的配置。

配置对象继承自 [PreTrainedConfig](/docs/transformers/v5.23.0/zh/main_classes/configuration#transformers.PreTrainedConfig)，可用于控制模型输出。有关更多信息，请参阅 [PreTrainedConfig](/docs/transformers/v5.23.0/zh/main_classes/configuration#transformers.PreTrainedConfig) 的文档。

示例：

```python
>>> from transformers import Tipsv2DptConfig, Tipsv2DptForDensePrediction

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

## Tipsv2DptImageProcessor[[transformers.Tipsv2DptImageProcessor]]

#### transformers.Tipsv2DptImageProcessor[[transformers.Tipsv2DptImageProcessor]]

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

[来源](https://github.com/huggingface/transformers/blob/v5.23.0/src/transformers/models/tipsv2_dpt/image_processing_tipsv2_dpt.py#L32)

**参数：**

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 为整数时，是否在调整大小时默认使用正方形图像。

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*, *可选*) : 输入中每张图片所使用的图像标记数量。为向后兼容而添加，但在未来的模型中应将其设置为处理器属性。如果设置为 `'pt'`，则返回堆叠的张量，否则返回张量列表。

disable_grouping (`bool`, *kwargs*, *可选*) : 是否禁用按尺寸对图像进行分组，从而逐个处理图像而非批量处理。如果为 None，则当图像位于 CPU 上时设置为 True，否则设置为 False。此选择基于经验观察，详见此处：https://github.com/huggingface/transformers/pull/38157

image_seq_length (`int`, *kwargs*, *可选*) : 输入中每张图片所使用的图像标记数量。为向后兼容而添加，但在未来的模型中应将其设置为处理器属性。如果设置为 `'pt'`，则返回堆叠的张量，否则返回张量列表。

disable_grouping (`bool`, *kwargs*, *可选*) : 是否禁用按尺寸对图像进行分组，从而逐个处理图像而非批量处理。如果为 None，则当图像位于 CPU 上时设置为 True，否则设置为 False。此选择基于经验观察，详见此处：https://github.com/huggingface/transformers/pull/38157

image_seq_length (`int`, *kwargs*, *可选*) : 输入中每张图片所使用的图像标记数量。为向后兼容而添加，但在未来的模型中应将其设置为处理器属性。如果设置为 `'pt'`，则返回堆叠的张量，否则返回张量列表。

disable_grouping (`bool`, *kwargs*, *可选*) : 是否禁用按尺寸对图像进行分组，从而逐个处理图像而非批量处理。如果为 None，则当图像位于 CPU 上时设置为 True，否则设置为 False。此选择基于经验观察，详见此处：https://github.com/huggingface/transformers/pull/38157

image_seq_length (`int`, *kwargs*, *可选*) : 输入中每张图片所使用的图像标记数量。为向后兼容而添加，但在未来的模型中应将其设置为处理器属性。如果设置为 `'pt'`，则返回堆叠的张量，否则返回张量列表。

disable_grouping (`bool`, *kwargs*, *可选*) : 是否禁用按尺寸对图像进行分组，从而逐个处理图像而非批量处理。如果为 None，则当图像位于 CPU 上时设置为 True，否则设置为 False。此选择基于经验观察，详见此处：https://github.com/huggingface/transformers/pull/38157

image_seq_length (`int`, *kwargs*, *可选*) : 输入中每张图片所使用的图像标记数量。为向后兼容而添加，但在未来的模型中应将其设置为处理器属性。如果设置为 `'pt'`，则返回堆叠的张量，否则返回张量列表。

disable_grouping (`bool`, *kwargs*, *可选*) : 是否禁用按尺寸对图像进行分组，从而逐个处理图像而非批量处理。如果为 None，则当图像位于 CPU 上时设置为 True，否则设置为 False。此选择基于经验观察，详见此处：https://github.com/huggingface/transformers/pull/38157

image_seq_length (`int`, *kwargs*, *可选*) : 输入中每张图片所使用的图像标记数量。为向后兼容而添加，但在未来的模型中应将其设置为处理器属性。如果设置为 `'pt'`，则返回堆叠的张量，否则返回张量列表。

disable_grouping (`bool`, *kwargs*, *可选*) : 是否禁用按尺寸对图像进行分组，从而逐个处理图像而非批量处理。如果为 None，则当图像位于 CPU 上时设置为 True，否则设置为 False。此选择基于经验观察，详见此处：https://github.com/huggingface/transformers/pull/38157

image_seq_length (`int`, *kwargs*, *可选*) : 输入中每张图片所使用的图像标记数量。为向后兼容而添加，但在未来的模型中应将其设置为处理器属性。如果设置为 `'pt'`，则返回堆叠的张量，否则返回张量列表。

disable_grouping (`bool`, *kwargs*, *可选*) : 是否禁用按尺寸对图像进行分组，从而逐个处理图像而非批量处理。如果为 None，则当图像位于 CPU 上时设置为 True，否则设置为 False。此选择基于经验观察，详见此处：https://github.com/huggingface/transformers/pull/38157

image_seq_length (`int`, *kwargs*, *可选*) : 输入中每张图片所使用的图像标记数量。为向后兼容而添加，但在未来的模型中应将其设置为处理器属性。如果设置为 `'pt'`，则返回堆叠的张量，否则返回张量列表。

disable_grouping (`bool`, *kwargs*, *可选*) : 是否禁用按尺寸对图像进行分组，从而逐个处理图像而非批量处理。如果为 None，则当图像位于 CPU 上时设置为 True，否则设置为 False。此选择基于经验观察，详见此处：https://github.com/huggingface/transformers/pull/38157

image_seq_length (`int`, *kwargs*, *可选*) : 输入中每张图片所使用的图像标记数量。为向后兼容而添加，但在未来的模型中应将其设置为处理器属性。如果设置为 `'pt'`，则返回堆叠的张量，否则返回张量列表。

disable_grouping (`bool`, *kwargs*, *可选*) : 是否禁用按尺寸对图像进行分组，从而逐个处理图像而非批量处理。如果为 None，则当图像位于 CPU 上时设置为 True，否则设置为 False。此选择基于经验观察，详见此处：https://github.com/huggingface/transformers/pull/38157

image_seq_length (`int`, *kwargs*, *可选*) : 输入中每张图片所使用的图像标记数量。为向后兼容而添加，但在未来的模型中应将其设置为处理器属性。如果设置为 `'pt'`，则返回堆叠的张量，否则返回张量列表。

disable_grouping (`bool`, *kwargs*, *可选*) : 是否禁用按尺寸对图像进行分组，从而逐个处理图像而非批量处理。如果为 None，则当图像位于 CPU 上时设置为 True，否则设置为 False。此选择基于经验观察，详见此处：https://github.com/huggingface/transformers/pull/38157

image_seq_length (`int`, *kwargs*, *可选*) : 输入中每张图片所使用的图像标记数量。为向后兼容而添加，但在未来的模型中应将其设置为处理器属性。如果设置为 `'pt'`，则返回堆叠的张量，否则返回张量列表。

disable_grouping (`bool`, *kwargs*, *可选*) : 是否禁用按尺寸对图像进行分组，从而逐个处理图像而非批量处理。如果为 None，则当图像位于 CPU 上时设置为 True，否则设置为 False。此选择基于经验观察，详见此处：https://github.com/huggingface/transformers/pull/38157

image_seq_length (`int`, *kwargs*, *可选*) : 输入中每张图片所使用的图像标记数量。为向后兼容而添加，但在未来的模型中应将其设置为处理器属性。如果设置为 `'pt'`，则返回堆叠的张量，否则返回张量列表。

disable_grouping (`bool`, *kwargs*, *可选*) : 是否禁用按尺寸对图像进行分组，从而逐个处理图像而非批量处理。如果为 None，则当图像位于 CPU 上时设置为 True，否则设置为 False。此选择基于经验观察，详见此处：https://github.com/huggingface/transformers/pull/38157

image_seq_length (`int`, *kwargs*, *可选*) : 输入中每张图片所使用的图像标记数量。为向后兼容而添加，但在未来的模型中应将其设置为处理器属性。如果设置为 `'pt'`，则返回堆叠的张量，否则返回张量列表。

disable_grouping (`bool`, *kwargs*, *可选*) : 是否禁用按尺寸对图像进行分组，从而逐个处理图像而非批量处理。如果为 None，则当图像位于 CPU 上时设置为 True，否则设置为 False。此选择基于经验观察，详见此处：https://github.com/huggingface/transformers/pull/38157

image_seq_length (`int`, *kwargs*, *可选*) : 输入中每张图片所使用的图像标记数量。为向后兼容而添加，但在未来的模型中应将其设置为处理器属性。如果设置为 `'pt'`，则返回堆叠的张量，否则返回张量列表。

disable_grouping (`bool`, *kwargs*, *可选*) : 是否禁用按尺寸对图像进行分组，从而逐个处理图像而非批量处理。如果为 None，则当图像位于 CPU 上时设置为 True，否则设置为 False。此选择基于经验观察，详见此处：https://github.com/huggingface/transformers/pull/38157

image_seq_length (`int`, *kwargs*, *可选*) : 输入中每张图片所使用的图像标记数量。为向后兼容而添加，但在未来的模型中应将其设置为处理器属性。如果设置为 `'pt'`，则返回堆叠的张量，否则返回张量列表。

disable_grouping (`bool`, *kwargs*, *可选*) : 是否禁用按尺寸对图像进行分组，从而逐个处理图像而非批量处理。如果为 None，则当图像位于 CPU 上时设置为 True，否则设置为 False。此选择基于经验观察，详见此处：https://github.com/huggingface/transformers/pull/38157

image_seq_length (`int`, *kwargs*, *可选*) : 输入中每张图片所使用的图像标记数量。为向后兼容而添加，但在未来的模型中应将其设置为处理器属性。如果设置为 `'pt'`，则返回堆叠的张量，否则返回张量列表。

disable_grouping (`bool`, *kwargs*, *可选*) : 是否禁用按尺寸对图像进行分组，从而逐个处理图像而非批量处理。如果为 None，则当图像位于 CPU 上时设置为 True，否则设置为 False。此选择基于经验观察，详见此处：https://github.com/huggingface/transformers/pull/38157

image_seq_length (`int`, *kwargs*, *可选*) : 输入中每张图片所使用的图像标记数量。为向后兼容而添加，但在未来的模型中应将其设置为处理器属性。如果设置为 `'pt'`，则返回堆叠的张量，否则返回张量列表。

disable_grouping (`bool`, *kwargs*, *可选*) : 是否禁用按尺寸对图像进行分组，从而逐个处理图像而非批量处理。如果为 None，则当图像位于 CPU 上时设置为 True，否则设置为 False。此选择基于经验观察，详见此处：https://github.com/huggingface/transformers/pull/38157

image_seq_length (`int`, *kwargs*, *可选*) : 输入中每张图片所使用的图像标记数量。为向后兼容而添加，但在未来的模型中应将其设置为处理器属性。如果设置为 `'pt'`，则返回堆叠的张量，否则返回张量列表。

disable_grouping (`bool`, *kwargs*, *可选*) : 是否禁用按尺寸对图像进行分组，从而逐个处理图像而非批量处理。如果为 None，则当图像位于 CPU 上时设置为 True，否则设置为 False。此选择基于经验观察，详见此处：https://github.com/huggingface/transformers/pull/38157

image_seq_length (`int`, *kwargs*, *可选*) : 输入中每张图片所使用的图像标记数量。为向后兼容而添加，但在未来的模型中应将其设置为处理器属性。如果设置为 `'pt'`，则返回堆叠的张量，否则返回张量列表。

disable_grouping (`bool`, *kwargs*, *可选*) : 是否禁用按尺寸对图像进行分组，从而逐个处理图像而非批量处理。如果为 None，则当图像位于 CPU 上时设置为 True，否则设置为 False。此选择基于经验观察，详见此处：https://github.com/huggingface/transformers/pull/38157

image_seq_length (`int`, *kwargs*, *可选*) : 输入中每张图片所使用的图像 token 数量。为向后兼容而添加，但在未来的模型中，应将其设置为处理器的属性。

如果设置为 `'pt'`，则返回堆叠的张量，否则返回张量列表。 --

构建一个 Tipsv2DptImageProcessor 图像处理器。

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

#### preprocess[[transformers.Tipsv2DptImageProcessor.preprocess]]

```python
preprocess(images: typing.Union[ForwardRef('PIL.Image.Image'), numpy.ndarray, ForwardRef('torch.Tensor'), list['PIL.Image.Image'], list[numpy.ndarray], list['torch.Tensor']], *args, image_like_kwargs: dict[str, typing.Any] | None = None, **kwargs: *<class 'transformers.processing_utils.ImagesKwargs'>)
```

[来源](https://github.com/huggingface/transformers/blob/v5.23.0/src/transformers/image_processing_utils.py#L382)

**参数：**

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 为 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*) : 如果调整图像大小，则使用的重采样滤波器。它可以是枚举 `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[[transformers.Tipsv2DptImageProcessor.post_process_depth_estimation]]

```python
post_process_depth_estimation(outputs, target_sizes: transformers.utils.generic.TensorType | list[tuple[int, int]] | None = None)
```

[来源](https://github.com/huggingface/transformers/blob/v5.23.0/src/transformers/models/tipsv2_dpt/image_processing_tipsv2_dpt.py#L40)

**参数：**

outputs (`DepthEstimatorOutput` 或 `Tipsv2DptDensePredictorOutput`)：模型的原始输出。

target_sizes ([TensorType](/docs/transformers/v5.23.0/zh/internal/file_utils#transformers.TensorType) 或 `list[tuple[int, int]]`，*可选*)：形状为 `(batch_size, 2)` 的张量，或包含批处理中每张图片目标尺寸（高度、宽度）的元组列表（`tuple[int, int]`）。如果设为 None，则不会调整预测结果的尺寸。

**返回：** `list[dict[str, torch.Tensor]]`

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

将 [Tipsv2DptForDepthEstimation](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptForDepthEstimation) 或 [Tipsv2DptForDensePrediction](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptForDensePrediction) 的输出转换为最终的深度预测。

#### post_process_normal_estimation[[transformers.Tipsv2DptImageProcessor.post_process_normal_estimation]]

```python
post_process_normal_estimation(outputs, target_sizes: transformers.utils.generic.TensorType | list[tuple[int, int]] | None = None)
```

[来源](https://github.com/huggingface/transformers/blob/v5.23.0/src/transformers/models/tipsv2_dpt/image_processing_tipsv2_dpt.py#L76)

**参数：**

outputs (`Tipsv2DptNormalEstimatorOutput` 或 `Tipsv2DptDensePredictorOutput`)：模型的原始输出。

target_sizes ([TensorType](/docs/transformers/v5.23.0/zh/internal/file_utils#transformers.TensorType) 或 `list[tuple[int, int]]`，*可选*)：形状为 `(batch_size, 2)` 的张量，或包含批处理中每张图片目标尺寸（高度、宽度）的元组列表（`tuple[int, int]`）。如果设为 None，则不会调整预测结果的尺寸。

**返回值：**

长度为 `batch_size` 的 `list[dict[str, torch.Tensor]]`。每个字典包含一个 `"normals"` 键，其值是一个形状为 `(3, height, width)` 的张量，每个通道（XYZ 表面法线）包含 `[-1, 1]` 范围内经过 L2 归一化的单位向量。

将 [Tipsv2DptForNormalEstimation](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptForNormalEstimation) 或 [Tipsv2DptForDensePrediction](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptForDensePrediction) 的输出转换为 L2 归一化的表面法线图。

#### post_process_semantic_segmentation[[transformers.Tipsv2DptImageProcessor.post_process_semantic_segmentation]]

```python
post_process_semantic_segmentation(outputs, target_sizes: transformers.utils.generic.TensorType | list[tuple[int, int]] | None = None, return_segmentation_scores: bool = False)
```

[来源](https://github.com/huggingface/transformers/blob/v5.23.0/src/transformers/models/tipsv2_dpt/image_processing_tipsv2_dpt.py#L113)

**参数：**

outputs （`SemanticSegmenterOutput` 或 `Tipsv2DptDensePredictorOutput`）：模型的原始输出。

target_sizes [([TensorType](/docs/transformers/v5.23.0/zh/internal/file_utils#transformers.TensorType) or `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](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptForSemanticSegmentation) 或 [Tipsv2DptForDensePrediction](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptForDensePrediction) 的输出转换为语义分割图。

## Tipsv2DptForDensePrediction[[transformers.Tipsv2DptForDensePrediction]]

#### transformers.Tipsv2DptForDensePrediction[[transformers.Tipsv2DptForDensePrediction]]

```python
transformers.Tipsv2DptForDensePrediction(config: Tipsv2DptConfig)
```

[来源](https://github.com/huggingface/transformers/blob/v5.23.0/src/transformers/models/tipsv2_dpt/modeling_tipsv2_dpt.py#L390)

**参数：**

config ([Tipsv2DptConfig](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptConfig))：模型配置类，包含模型的所有参数。通过配置文件进行初始化时，不会加载与模型关联的权重，仅加载配置。请查看 [from_pretrained()](/docs/transformers/v5.23.0/zh/main_classes/model#transformers.PreTrainedModel.from_pretrained) 方法以加载模型权重。

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

该模型继承自 [PreTrainedModel](/docs/transformers/v5.23.0/zh/main_classes/model#transformers.PreTrainedModel)。请查阅父类文档，了解该库为所有模型实现的通用方法（例如下载或保存、调整输入嵌入大小、剪枝头等）。

该模型也是 PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) 的子类。请将其作为常规的 PyTorch Module 使用，有关通用用法和行为的所有事项，请参阅 PyTorch 文档。

#### forward[[transformers.Tipsv2DptForDensePrediction.forward]]

```python
forward(pixel_values: Tensor, **kwargs: Unpack)
```

[来源](https://github.com/huggingface/transformers/blob/v5.23.0/src/transformers/models/tipsv2_dpt/modeling_tipsv2_dpt.py#L408)

**参数：**

pixel_values (`torch.Tensor`，形状为 `(batch_size, num_channels, image_size, image_size)`)：与输入图像对应的张量。可以使用 [Tipsv2DptImageProcessor](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptImageProcessor) 获取像素值。有关详细信息，请参阅 [Tipsv2DptImageProcessor.__call__()](/docs/transformers/v5.23.0/zh/model_doc/molmo2#transformers.Molmo2ImageProcessor.__call__)（`processor_class` 使用 [Tipsv2DptImageProcessor](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptImageProcessor) 处理图像）。

**返回：** `Tipsv2DptDensePredictorOutput` 或 `tuple(torch.Tensor)`

`Tipsv2DptDensePredictorOutput` 或 `torch.Tensor` 元组（如果传入 `return_dict=False` 或 `config.return_dict=False`），其包含的元素取决于配置（[Tipsv2DptConfig](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptConfig)）和输入。

[Tipsv2DptForDensePrediction](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.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 后的注意力权重，用于在自注意力头中计算加权平均值。

示例：

```python
>>> 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[[transformers.Tipsv2DptForDepthEstimation]]

#### transformers.Tipsv2DptForDepthEstimation[[transformers.Tipsv2DptForDepthEstimation]]

```python
transformers.Tipsv2DptForDepthEstimation(config: Tipsv2DptConfig)
```

[来源](https://github.com/huggingface/transformers/blob/v5.23.0/src/transformers/models/tipsv2_dpt/modeling_tipsv2_dpt.py#L480)

**参数：**

config ([Tipsv2DptConfig](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptConfig))：模型配置类，包含模型的所有参数。通过配置文件进行初始化时，不会加载与模型关联的权重，仅加载配置。请查看 [from_pretrained()](/docs/transformers/v5.23.0/zh/main_classes/model#transformers.PreTrainedModel.from_pretrained) 方法以加载模型权重。

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

该模型继承自 [PreTrainedModel](/docs/transformers/v5.23.0/zh/main_classes/model#transformers.PreTrainedModel)。请查阅父类文档，了解该库为所有模型实现的通用方法（例如下载或保存、调整输入嵌入大小、剪枝头等）。

该模型也是 PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) 的子类。请将其作为常规的 PyTorch Module 使用，有关通用用法和行为的所有事项，请参阅 PyTorch 文档。

#### forward[[transformers.Tipsv2DptForDepthEstimation.forward]]

```python
forward(pixel_values: Tensor, labels: typing.Optional[torch.Tensor] = None, **kwargs: Unpack)
```

[来源](https://github.com/huggingface/transformers/blob/v5.23.0/src/transformers/models/tipsv2_dpt/modeling_tipsv2_dpt.py#L496)

**参数：**

pixel_values (`torch.Tensor`，形状为 `(batch_size, num_channels, image_size, image_size)`)：与输入图像对应的张量。可以使用 [Tipsv2DptImageProcessor](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptImageProcessor) 获取像素值。有关详细信息，请参阅 [Tipsv2DptImageProcessor.__call__()](/docs/transformers/v5.23.0/zh/model_doc/molmo2#transformers.Molmo2ImageProcessor.__call__)（`processor_class` 使用 [Tipsv2DptImageProcessor](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptImageProcessor) 处理图像）。

labels (`torch.LongTensor`，形状为 `(batch_size, height, width)`，*可选*)：用于计算损失的真实深度估计图。

**返回：** [DepthEstimatorOutput](/docs/transformers/v5.23.0/zh/main_classes/output#transformers.modeling_outputs.DepthEstimatorOutput) 或 `tuple(torch.Tensor)`

一个 [DepthEstimatorOutput](/docs/transformers/v5.23.0/zh/main_classes/output#transformers.modeling_outputs.DepthEstimatorOutput) 或 `torch.Tensor` 元组（如果传入了 `return_dict=False` 或 `config.return_dict=False`），其包含的元素取决于配置（[Tipsv2DptConfig](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptConfig)）和输入。

[Tipsv2DptForDepthEstimation](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.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 后的注意力权重，用于在自注意力头中计算加权平均值。

示例：

```python
>>> 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[[transformers.Tipsv2DptForNormalEstimation]]

#### transformers.Tipsv2DptForNormalEstimation[[transformers.Tipsv2DptForNormalEstimation]]

```python
transformers.Tipsv2DptForNormalEstimation(config: Tipsv2DptConfig)
```

[来源](https://github.com/huggingface/transformers/blob/v5.23.0/src/transformers/models/tipsv2_dpt/modeling_tipsv2_dpt.py#L556)

**参数：**

config ([Tipsv2DptConfig](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptConfig))：模型配置类，包含模型的所有参数。通过配置文件进行初始化时，不会加载与模型关联的权重，仅加载配置。请查看 [from_pretrained()](/docs/transformers/v5.23.0/zh/main_classes/model#transformers.PreTrainedModel.from_pretrained) 方法以加载模型权重。

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

该模型继承自 [PreTrainedModel](/docs/transformers/v5.23.0/zh/main_classes/model#transformers.PreTrainedModel)。请查阅父类文档，了解该库为所有模型实现的通用方法（例如下载或保存、调整输入嵌入大小、剪枝头等）。

该模型也是 PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) 的子类。请将其作为常规的 PyTorch Module 使用，有关通用用法和行为的所有事项，请参阅 PyTorch 文档。

#### forward[[transformers.Tipsv2DptForNormalEstimation.forward]]

```python
forward(pixel_values: Tensor, labels: typing.Optional[torch.Tensor] = None, **kwargs: Unpack)
```

[来源](https://github.com/huggingface/transformers/blob/v5.23.0/src/transformers/models/tipsv2_dpt/modeling_tipsv2_dpt.py#L569)

**参数：**

pixel_values (`torch.Tensor`，形状为 `(batch_size, num_channels, image_size, image_size)`)：与输入图像对应的张量。可以使用 [Tipsv2DptImageProcessor](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptImageProcessor) 获取像素值。有关详细信息，请参阅 [Tipsv2DptImageProcessor.__call__()](/docs/transformers/v5.23.0/zh/model_doc/molmo2#transformers.Molmo2ImageProcessor.__call__)（`processor_class` 使用 [Tipsv2DptImageProcessor](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptImageProcessor) 处理图像）。

labels (`torch.Tensor`，形状为 `(batch_size, sequence_length)`，*可选*) : 用于计算掩码语言建模损失的标签。索引应在 `[0, ..., config.vocab_size]` 范围内，或为 -100（参见 `input_ids` 的文档字符串）。索引设置为 `-100` 的令牌将被忽略（掩码），损失仅针对标签在 `[0, ..., config.vocab_size]` 范围内的令牌进行计算。

**返回：** `Tipsv2DptNormalEstimatorOutput` 或 `tuple(torch.Tensor)`

`Tipsv2DptNormalEstimatorOutput` 或 `torch.Tensor` 元组（如果传入 `return_dict=False` 或 `config.return_dict=False`），其包含的元素取决于配置（[Tipsv2DptConfig](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptConfig)）和输入。

[Tipsv2DptForNormalEstimation](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.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 之后的注意力权重。

示例：

```python
>>> 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[[transformers.Tipsv2DptForSemanticSegmentation]]

#### transformers.Tipsv2DptForSemanticSegmentation[[transformers.Tipsv2DptForSemanticSegmentation]]

```python
transformers.Tipsv2DptForSemanticSegmentation(config: Tipsv2DptConfig)
```

[来源](https://github.com/huggingface/transformers/blob/v5.23.0/src/transformers/models/tipsv2_dpt/modeling_tipsv2_dpt.py#L628)

**参数：**

config ([Tipsv2DptConfig](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptConfig))：模型配置类，包含模型的所有参数。通过配置文件进行初始化时，不会加载与模型关联的权重，仅加载配置。请查看 [from_pretrained()](/docs/transformers/v5.23.0/zh/main_classes/model#transformers.PreTrainedModel.from_pretrained) 方法以加载模型权重。

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

该模型继承自 [PreTrainedModel](/docs/transformers/v5.23.0/zh/main_classes/model#transformers.PreTrainedModel)。请查阅父类文档，了解该库为所有模型实现的通用方法（例如下载或保存、调整输入嵌入大小、剪枝头等）。

该模型也是 PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) 的子类。请将其作为常规的 PyTorch Module 使用，有关通用用法和行为的所有事项，请参阅 PyTorch 文档。

#### forward[[transformers.Tipsv2DptForSemanticSegmentation.forward]]

```python
forward(pixel_values: Tensor, labels: typing.Optional[torch.LongTensor] = None, **kwargs: Unpack)
```

[来源](https://github.com/huggingface/transformers/blob/v5.23.0/src/transformers/models/tipsv2_dpt/modeling_tipsv2_dpt.py#L641)

**参数：**

pixel_values (`torch.Tensor`，形状为 `(batch_size, num_channels, image_size, image_size)`)：与输入图像对应的张量。可以使用 [Tipsv2DptImageProcessor](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptImageProcessor) 获取像素值。有关详细信息，请参阅 [Tipsv2DptImageProcessor.__call__()](/docs/transformers/v5.23.0/zh/model_doc/molmo2#transformers.Molmo2ImageProcessor.__call__)（`processor_class` 使用 [Tipsv2DptImageProcessor](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptImageProcessor) 处理图像）。

labels (`torch.LongTensor`，形状为 `(batch_size, height, width)`，*可选*) : 用于计算损失的真实语义分割图。索引应在 `[0, ..., config.num_labels - 1]` 范围内。如果 `config.num_labels > 1`，则计算分类损失（交叉熵）。

**返回：** [SemanticSegmenterOutput](/docs/transformers/v5.23.0/zh/main_classes/output#transformers.modeling_outputs.SemanticSegmenterOutput) 或 `tuple(torch.Tensor)`

一个 [SemanticSegmenterOutput](/docs/transformers/v5.23.0/zh/main_classes/output#transformers.modeling_outputs.SemanticSegmenterOutput) 或 `torch.Tensor` 元组（如果传入了 `return_dict=False` 或 `config.return_dict=False`），其包含的元素取决于配置（[Tipsv2DptConfig](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.Tipsv2DptConfig)）和输入。

[Tipsv2DptForSemanticSegmentation](/docs/transformers/v5.23.0/zh/model_doc/tipsv2_dpt#transformers.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 后的注意力权重，用于在自注意力头中计算加权平均值。

示例：

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

