Skip to content

unitorch.models.dpt¤

DPTProcessor¤

Bases: HfImageClassificationProcessor

Processor for DPT-based depth estimation models.

Initializes the DPTProcessor.

Parameters:

Name Type Description Default
vision_config_path str

Path to the DPT image processor configuration file.

required
Source code in src/unitorch/models/dpt/processing.py
14
15
16
17
18
19
20
21
22
23
24
25
def __init__(
    self,
    vision_config_path: str,
):
    """
    Initializes the DPTProcessor.

    Args:
        vision_config_path (str): Path to the DPT image processor configuration file.
    """
    vision_processor = DPTImageProcessor.from_json_file(vision_config_path)
    super().__init__(vision_processor=vision_processor)

DPTForDepthEstimation¤

Bases: GenericModel

DPT model for depth estimation tasks.

Initializes the DPTForDepthEstimation model.

Parameters:

Name Type Description Default
config_path str

Path to the DPT configuration file.

required
Source code in src/unitorch/models/dpt/modeling.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def __init__(
    self,
    config_path: str,
):
    """
    Initializes the DPTForDepthEstimation model.

    Args:
        config_path (str): Path to the DPT configuration file.
    """
    super().__init__()
    config = DPTConfig.from_json_file(config_path)
    self._base_model = _DPTForDepthEstimation(config)
    self.init_weights()

prefix_keys_in_state_dict class-attribute instance-attribute ¤

prefix_keys_in_state_dict = {
    "^dpt.": "_base_model.",
    "^backbone.": "_base_model.",
    "^neck.": "_base_model.",
    "^head.": "_base_model.",
}

_base_model instance-attribute ¤

_base_model = DPTForDepthEstimation(config)

forward ¤

forward(pixel_values: Tensor)

Forward pass of the DPTForDepthEstimation model.

Parameters:

Name Type Description Default
pixel_values Tensor

Input image tensor of shape [batch_size, channels, height, width].

required

Returns:

Type Description

torch.Tensor: Upsampled depth prediction tensor.

Source code in src/unitorch/models/dpt/modeling.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def forward(
    self,
    pixel_values: torch.Tensor,
):
    """
    Forward pass of the DPTForDepthEstimation model.

    Args:
        pixel_values (torch.Tensor): Input image tensor of shape [batch_size, channels, height, width].

    Returns:
        torch.Tensor: Upsampled depth prediction tensor.
    """
    predicted_depth = self._base_model(pixel_values=pixel_values).predicted_depth
    prediction = nn.functional.interpolate(
        predicted_depth.unsqueeze(1),
        scale_factor=4,
        mode="bicubic",
        align_corners=False,
    )
    return prediction