Views
No views yet

1from transformers import pipeline
2from PIL import Image
3import requests
4
5# load pipe
6pipe = pipeline(task="depth-estimation", model="LiheYoung/depth-anything-small-hf")
7
8# load image
9url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
10image = Image.open(requests.get(url, stream=True).raw)
11
12# inference
13depth = pipe(image)["depth"]1from transformers import AutoImageProcessor, AutoModelForDepthEstimation
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
10image_processor = AutoImageProcessor.from_pretrained("LiheYoung/depth-anything-small-hf")
11model = AutoModelForDepthEstimation.from_pretrained("LiheYoung/depth-anything-small-hf")
12
13# prepare image for the model
14inputs = image_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)1@misc{yang2024depth,
2 title={Depth Anything: Unleashing the Power of Large-Scale Unlabeled Data},
3 author={Lihe Yang and Bingyi Kang and Zilong Huang and Xiaogang Xu and Jiashi Feng and Hengshuang Zhao},
4 year={2024},
5 eprint={2401.10891},
6 archivePrefix={arXiv},
7 primaryClass={cs.CV}
8}