Dense Prediction Transformer (DPT) model trained on 1.4 million images for monocular depth estimation.
It was introduced in the paper
Vision Transformers for Dense Prediction by Ranftl et al. (2021) and first released in
this repository.
DPT uses the Vision Transformer (ViT) as backbone and adds a neck + head on top for monocular depth estimation.
This repository hosts the "hybrid" version of the model as stated in the paper. DPT-Hybrid diverges from DPT by using
ViT-hybrid as a backbone and taking some activations from the backbone.
The model card has been written in combination by the Hugging Face team and Intel.
1from PIL import Image
2import numpy as np
3import requests
4import torch
5
6from transformers import DPTImageProcessor, DPTForDepthEstimation
7
8image_processor = DPTImageProcessor.from_pretrained("Intel/dpt-hybrid-midas")
9model = DPTForDepthEstimation.from_pretrained("Intel/dpt-hybrid-midas", low_cpu_mem_usage=True)
10
11url = "http://images.cocodataset.org/val2017/000000039769.jpg"
12image = Image.open(requests.get(url, stream=True).raw)
13
14# prepare image for the model
15inputs = image_processor(images=image, return_tensors="pt")
16
17with torch.no_grad():
18 outputs = model(**inputs)
19 predicted_depth = outputs.predicted_depth
20
21# interpolate to original size
22prediction = torch.nn.functional.interpolate(
23 predicted_depth.unsqueeze(1),
24 size=image.size[::-1],
25 mode="bicubic",
26 align_corners=False,
27)
28
29# visualize the prediction
30output = prediction.squeeze().cpu().numpy()
31formatted = (output * 255 / np.max(output)).astype("uint8")
32depth = Image.fromarray(formatted)
33depth.show()
Table 1. Comparison to the state of the art on monocular depth estimation. We evaluate zero-shot cross-dataset transfer according to the
protocol defined in [30]. Relative performance is computed with respect to the original MiDaS model [30]. Lower is better for all metrics. (
Ranftl et al., 2021)
1@article{DBLP:journals/corr/abs-2103-13413,
2 author = {Ren{\'{e}} Ranftl and
3 Alexey Bochkovskiy and
4 Vladlen Koltun},
5 title = {Vision Transformers for Dense Prediction},
6 journal = {CoRR},
7 volume = {abs/2103.13413},
8 year = {2021},
9 url = {https://arxiv.org/abs/2103.13413},
10 eprinttype = {arXiv},
11 eprint = {2103.13413},
12 timestamp = {Wed, 07 Apr 2021 15:31:46 +0200},
13 biburl = {https://dblp.org/rec/journals/corr/abs-2103-13413.bib},
14 bibsource = {dblp computer science bibliography, https://dblp.org}
15}