babmakkah01
commited on
Commit
•
2a71692
1
Parent(s):
a232af2
Update README.md
Browse files
README.md
CHANGED
@@ -1,23 +1,31 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import DPTImageProcessor, DPTForDepthEstimation
|
2 |
+
import torch
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
+
import requests
|
6 |
+
|
7 |
+
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
8 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
9 |
+
|
10 |
+
processor = DPTImageProcessor.from_pretrained("Intel/dpt-large")
|
11 |
+
model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large")
|
12 |
+
|
13 |
+
# prepare image for the model
|
14 |
+
inputs = processor(images=image, return_tensors="pt")
|
15 |
+
|
16 |
+
with torch.no_grad():
|
17 |
+
outputs = model(**inputs)
|
18 |
+
predicted_depth = outputs.predicted_depth
|
19 |
+
|
20 |
+
# interpolate to original size
|
21 |
+
prediction = torch.nn.functional.interpolate(
|
22 |
+
predicted_depth.unsqueeze(1),
|
23 |
+
size=image.size[::-1],
|
24 |
+
mode="bicubic",
|
25 |
+
align_corners=False,
|
26 |
+
)
|
27 |
+
|
28 |
+
# visualize the prediction
|
29 |
+
output = prediction.squeeze().cpu().numpy()
|
30 |
+
formatted = (output * 255 / np.max(output)).astype("uint8")
|
31 |
+
depth = Image.fromarray(formatted)
|