Views
No views yet

1from transformers import GLPNImageProcessor, GLPNForDepthEstimation
2import torch
3import numpy as np
4from PIL import Image
5import requests
6
7url = "http://images.cocodataset.org/val2017/000000039769.jpg"
8image = Image.open(requests.get(url, stream=True).raw)
9
10processor = GLPNImageProcessor.from_pretrained("vinvino02/glpn-kitti")
11model = GLPNForDepthEstimation.from_pretrained("vinvino02/glpn-kitti")
12
13# prepare image for the model
14inputs = processor(images=image, return_tensors="pt")
15
16with torch.no_grad():
17 outputs = model(**inputs)
18 predicted_depth = outputs.predicted_depth
19
20# interpolate to original size
21prediction = 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
29output = prediction.squeeze().cpu().numpy()
30formatted = (output * 255 / np.max(output)).astype("uint8")
31depth = Image.fromarray(formatted)1@article{DBLP:journals/corr/abs-2201-07436,
2 author = {Doyeon Kim and
3 Woonghyun Ga and
4 Pyunghwan Ahn and
5 Donggyu Joo and
6 Sehwan Chun and
7 Junmo Kim},
8 title = {Global-Local Path Networks for Monocular Depth Estimation with Vertical
9 CutDepth},
10 journal = {CoRR},
11 volume = {abs/2201.07436},
12 year = {2022},
13 url = {https://arxiv.org/abs/2201.07436},
14 eprinttype = {arXiv},
15 eprint = {2201.07436},
16 timestamp = {Fri, 21 Jan 2022 13:57:15 +0100},
17 biburl = {https://dblp.org/rec/journals/corr/abs-2201-07436.bib},
18 bibsource = {dblp computer science bibliography, https://dblp.org}
19}