ybelkada commited on
Commit
0bf3738
1 Parent(s): d52ef03

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +94 -0
README.md ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ tags:
4
+ - vision
5
+ - depth-estimation
6
+ widget:
7
+ - src: https://huggingface.co/datasets/mishig/sample_images/resolve/main/tiger.jpg
8
+ example_title: Tiger
9
+ - src: https://huggingface.co/datasets/mishig/sample_images/resolve/main/teapot.jpg
10
+ example_title: Teapot
11
+ - src: https://huggingface.co/datasets/mishig/sample_images/resolve/main/palace.jpg
12
+ example_title: Palace
13
+ ---
14
+
15
+ # DPT-Hybrid
16
+
17
+ 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](https://arxiv.org/abs/2103.13413) by Ranftl et al. and first released in [this repository](https://github.com/isl-org/DPT). This repository hosts the "hybrid" version of the model as stated in the paper.
18
+
19
+ Disclaimer: The team releasing DPT did not write a model card for this model so this model card has been written by the Hugging Face team.
20
+
21
+ ## Model description
22
+
23
+ DPT uses the Vision Transformer (ViT) as backbone and adds a neck + head on top for monocular depth estimation.
24
+
25
+ ![model image](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/dpt_architecture.jpg)
26
+
27
+ DPT-Hybrid diverges from DPT by using [ViT-hybrid](https://huggingface.co/google/vit-hybrid-base-bit-384) as a backbone and taking some activations from the backbone.
28
+
29
+ ## Intended uses & limitations
30
+
31
+ You can use the raw model for zero-shot monocular depth estimation. See the [model hub](https://huggingface.co/models?search=dpt) to look for
32
+ fine-tuned versions on a task that interests you.
33
+
34
+ ### How to use
35
+
36
+ Here is how to use this model for zero-shot depth estimation on an image:
37
+
38
+ ```python
39
+ from PIL import Image
40
+ import numpy as np
41
+ import requests
42
+ import torch
43
+
44
+
45
+ from transformers import DPTForDepthEstimation, DPTFeatureExtractor
46
+
47
+ model = DPTForDepthEstimation.from_pretrained("Intel/dpt-hybrid-midas", low_cpu_mem_usage=True)
48
+ feature_extractor = DPTFeatureExtractor.from_pretrained("Intel/dpt-hybrid-midas")
49
+
50
+ url = "http://images.cocodataset.org/val2017/000000039769.jpg"
51
+ image = Image.open(requests.get(url, stream=True).raw)
52
+
53
+ # prepare image for the model
54
+ inputs = feature_extractor(images=image, return_tensors="pt")
55
+
56
+ with torch.no_grad():
57
+ outputs = model(**inputs)
58
+ predicted_depth = outputs.predicted_depth
59
+
60
+ # interpolate to original size
61
+ prediction = torch.nn.functional.interpolate(
62
+ predicted_depth.unsqueeze(1),
63
+ size=image.size[::-1],
64
+ mode="bicubic",
65
+ align_corners=False,
66
+ )
67
+
68
+ # visualize the prediction
69
+ output = prediction.squeeze().cpu().numpy()
70
+ formatted = (output * 255 / np.max(output)).astype("uint8")
71
+ depth = Image.fromarray(formatted)
72
+ depth.show()
73
+
74
+ For more code examples, we refer to the [documentation](https://huggingface.co/docs/transformers/master/en/model_doc/dpt).
75
+
76
+ ### BibTeX entry and citation info
77
+
78
+ ```bibtex
79
+ @article{DBLP:journals/corr/abs-2103-13413,
80
+ author = {Ren{\'{e}} Ranftl and
81
+ Alexey Bochkovskiy and
82
+ Vladlen Koltun},
83
+ title = {Vision Transformers for Dense Prediction},
84
+ journal = {CoRR},
85
+ volume = {abs/2103.13413},
86
+ year = {2021},
87
+ url = {https://arxiv.org/abs/2103.13413},
88
+ eprinttype = {arXiv},
89
+ eprint = {2103.13413},
90
+ timestamp = {Wed, 07 Apr 2021 15:31:46 +0200},
91
+ biburl = {https://dblp.org/rec/journals/corr/abs-2103-13413.bib},
92
+ bibsource = {dblp computer science bibliography, https://dblp.org}
93
+ }
94
+ ```