Depth Estimation
Transformers
Safetensors
tipsv2_dpt
feature-extraction
vision
surface-normals
semantic-segmentation
dense-prediction
custom_code
Instructions to use google/tipsv2-b14-dpt with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use google/tipsv2-b14-dpt with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("depth-estimation", model="google/tipsv2-b14-dpt", trust_remote_code=True)# Load model directly from transformers import AutoImageProcessor, AutoModel processor = AutoImageProcessor.from_pretrained("google/tipsv2-b14-dpt", trust_remote_code=True) model = AutoModel.from_pretrained("google/tipsv2-b14-dpt", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update files
Browse files- modeling_dpt.py +6 -11
modeling_dpt.py
CHANGED
|
@@ -8,7 +8,7 @@ from typing import Optional
|
|
| 8 |
|
| 9 |
import torch
|
| 10 |
from huggingface_hub import hf_hub_download
|
| 11 |
-
from transformers import AutoModel, PreTrainedModel
|
| 12 |
|
| 13 |
from .configuration_dpt import TIPSv2DPTConfig
|
| 14 |
|
|
@@ -61,7 +61,6 @@ class TIPSv2DPTModel(PreTrainedModel):
|
|
| 61 |
_no_split_modules = []
|
| 62 |
_supports_cache_class = False
|
| 63 |
_tied_weights_keys = []
|
| 64 |
-
_keys_to_ignore_on_load_unexpected = {"backbone"}
|
| 65 |
|
| 66 |
@property
|
| 67 |
def all_tied_weights_keys(self):
|
|
@@ -75,6 +74,10 @@ class TIPSv2DPTModel(PreTrainedModel):
|
|
| 75 |
|
| 76 |
ppc = tuple(config.post_process_channels)
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
self.depth_head = dpt_mod.DPTDepthHead(
|
| 79 |
input_embed_dim=config.embed_dim, channels=config.channels,
|
| 80 |
post_process_channels=ppc, readout_type=config.readout_type,
|
|
@@ -90,17 +93,9 @@ class TIPSv2DPTModel(PreTrainedModel):
|
|
| 90 |
post_process_channels=ppc, readout_type=config.readout_type,
|
| 91 |
num_classes=config.num_seg_classes,
|
| 92 |
)
|
| 93 |
-
self._backbone = None
|
| 94 |
-
|
| 95 |
-
def _get_backbone(self):
|
| 96 |
-
if self._backbone is None:
|
| 97 |
-
self._backbone = AutoModel.from_pretrained(self.config.backbone_repo, trust_remote_code=True)
|
| 98 |
-
self._backbone.to(self.device).eval()
|
| 99 |
-
return self._backbone.vision_encoder
|
| 100 |
|
| 101 |
def _extract_intermediate(self, pixel_values):
|
| 102 |
-
|
| 103 |
-
intermediate = backbone.get_intermediate_layers(
|
| 104 |
pixel_values, n=self.config.block_indices,
|
| 105 |
reshape=True, return_class_token=True, norm=True,
|
| 106 |
)
|
|
|
|
| 8 |
|
| 9 |
import torch
|
| 10 |
from huggingface_hub import hf_hub_download
|
| 11 |
+
from transformers import AutoConfig, AutoModel, PreTrainedModel
|
| 12 |
|
| 13 |
from .configuration_dpt import TIPSv2DPTConfig
|
| 14 |
|
|
|
|
| 61 |
_no_split_modules = []
|
| 62 |
_supports_cache_class = False
|
| 63 |
_tied_weights_keys = []
|
|
|
|
| 64 |
|
| 65 |
@property
|
| 66 |
def all_tied_weights_keys(self):
|
|
|
|
| 74 |
|
| 75 |
ppc = tuple(config.post_process_channels)
|
| 76 |
|
| 77 |
+
backbone_config = AutoConfig.from_pretrained(config.backbone_repo, trust_remote_code=True)
|
| 78 |
+
backbone = AutoModel.from_config(backbone_config, trust_remote_code=True)
|
| 79 |
+
self.vision_encoder = backbone.vision_encoder
|
| 80 |
+
|
| 81 |
self.depth_head = dpt_mod.DPTDepthHead(
|
| 82 |
input_embed_dim=config.embed_dim, channels=config.channels,
|
| 83 |
post_process_channels=ppc, readout_type=config.readout_type,
|
|
|
|
| 93 |
post_process_channels=ppc, readout_type=config.readout_type,
|
| 94 |
num_classes=config.num_seg_classes,
|
| 95 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
def _extract_intermediate(self, pixel_values):
|
| 98 |
+
intermediate = self.vision_encoder.get_intermediate_layers(
|
|
|
|
| 99 |
pixel_values, n=self.config.block_indices,
|
| 100 |
reshape=True, return_class_token=True, norm=True,
|
| 101 |
)
|