Views
No views yet
git clone https://github.com/LiheYoung/Depth-Anything
cd Depth-Anything
pip install -r requirements.txt1import numpy as np
2from PIL import Image
3import cv2
4import torch
5
6from depth_anything.dpt import DepthAnything
7from depth_anything.util.transform import Resize, NormalizeImage, PrepareForNet
8from torchvision.transforms import Compose
9
10model = DepthAnything.from_pretrained("LiheYoung/depth_anything_vitb14")
11
12transform = Compose([
13 Resize(
14 width=518,
15 height=518,
16 resize_target=False,
17 keep_aspect_ratio=True,
18 ensure_multiple_of=14,
19 resize_method='lower_bound',
20 image_interpolation_method=cv2.INTER_CUBIC,
21 ),
22 NormalizeImage(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
23 PrepareForNet(),
24 ])
25
26image = Image.open("...")
27image = np.array(image) / 255.0
28image = transform({'image': image})['image']
29image = torch.from_numpy(image).unsqueeze(0)
30
31depth = model(image)