Views
No views yet

1from transformers import pipeline
2from PIL import Image
3import requests
4
5# load pipe
6pipe = pipeline(task="depth-estimation", model="depth-anything/Depth-Anything-V2-Base-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("depth-anything/Depth-Anything-V2-Base-hf")
11model = AutoModelForDepthEstimation.from_pretrained("depth-anything/Depth-Anything-V2-Base-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 V2},
3 author={Lihe Yang and Bingyi Kang and Zilong Huang and Zhen Zhao and Xiaogang Xu and Jiashi Feng and Hengshuang Zhao},
4 year={2024},
5 eprint={2406.09414},
6 archivePrefix={arXiv},
7 primaryClass={id='cs.CV' full_name='Computer Vision and Pattern Recognition' is_active=True alt_name=None in_archive='cs' is_general=False description='Covers image processing, computer vision, pattern recognition, and scene understanding. Roughly includes material in ACM Subject Classes I.2.10, I.4, and I.5.'}
8}