xelu3banh nielsr HF staff commited on
Commit
cdefa01
0 Parent(s):

Duplicate from nielsr/dpt-depth-estimation

Browse files

Co-authored-by: Niels Rogge <nielsr@users.noreply.huggingface.co>

Files changed (4) hide show
  1. .gitattributes +27 -0
  2. README.md +13 -0
  3. app.py +46 -0
  4. requirements.txt +4 -0
.gitattributes ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bin.* filter=lfs diff=lfs merge=lfs -text
5
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.model filter=lfs diff=lfs merge=lfs -text
12
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
13
+ *.onnx filter=lfs diff=lfs merge=lfs -text
14
+ *.ot filter=lfs diff=lfs merge=lfs -text
15
+ *.parquet filter=lfs diff=lfs merge=lfs -text
16
+ *.pb filter=lfs diff=lfs merge=lfs -text
17
+ *.pt filter=lfs diff=lfs merge=lfs -text
18
+ *.pth filter=lfs diff=lfs merge=lfs -text
19
+ *.rar filter=lfs diff=lfs merge=lfs -text
20
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
21
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
22
+ *.tflite filter=lfs diff=lfs merge=lfs -text
23
+ *.tgz filter=lfs diff=lfs merge=lfs -text
24
+ *.xz filter=lfs diff=lfs merge=lfs -text
25
+ *.zip filter=lfs diff=lfs merge=lfs -text
26
+ *.zstandard filter=lfs diff=lfs merge=lfs -text
27
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Dpt Depth Estimation
3
+ emoji: ⚡
4
+ colorFrom: blue
5
+ colorTo: red
6
+ sdk: gradio
7
+ sdk_version: 2.8.13
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: nielsr/dpt-depth-estimation
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import DPTFeatureExtractor, DPTForDepthEstimation
3
+ import torch
4
+ import numpy as np
5
+ from PIL import Image
6
+
7
+ torch.hub.download_url_to_file('http://images.cocodataset.org/val2017/000000039769.jpg', 'cats.jpg')
8
+
9
+ feature_extractor = DPTFeatureExtractor.from_pretrained("Intel/dpt-large")
10
+ model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large")
11
+
12
+ def process_image(image):
13
+ # prepare image for the model
14
+ encoding = feature_extractor(image, return_tensors="pt")
15
+
16
+ # forward pass
17
+ with torch.no_grad():
18
+ outputs = model(**encoding)
19
+ predicted_depth = outputs.predicted_depth
20
+
21
+ # interpolate to original size
22
+ prediction = torch.nn.functional.interpolate(
23
+ predicted_depth.unsqueeze(1),
24
+ size=image.size[::-1],
25
+ mode="bicubic",
26
+ align_corners=False,
27
+ ).squeeze()
28
+ output = prediction.cpu().numpy()
29
+ formatted = (output * 255 / np.max(output)).astype('uint8')
30
+ img = Image.fromarray(formatted)
31
+ return img
32
+
33
+ return result
34
+
35
+ title = "Demo: zero-shot depth estimation with DPT"
36
+ description = "Demo for Intel's DPT, a Dense Prediction Transformer for state-of-the-art dense prediction tasks such as semantic segmentation and depth estimation."
37
+ examples =[['cats.jpg']]
38
+
39
+ iface = gr.Interface(fn=process_image,
40
+ inputs=gr.inputs.Image(type="pil"),
41
+ outputs=gr.outputs.Image(type="pil", label="predicted depth"),
42
+ title=title,
43
+ description=description,
44
+ examples=examples,
45
+ enable_queue=True)
46
+ iface.launch(debug=True)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ torch
2
+ git+https://github.com/nielsrogge/transformers.git@add_dpt_redesign#egg=transformers
3
+ numpy
4
+ Pillow