README.md
1.4 KB · 58 lines · markdown Raw
1 ---
2 tags:
3 - depth_anything
4 - depth-estimation
5 ---
6
7 # Depth Anything model, base
8
9 The model card for our paper [Depth Anything: Unleashing the Power of Large-Scale Unlabeled Data](https://arxiv.org/abs/2401.10891).
10
11 You may also try our [demo](https://huggingface.co/spaces/LiheYoung/Depth-Anything) and visit our [project page](https://depth-anything.github.io/).
12
13 ## Installation
14
15 First, install the Depth Anything package:
16 ```
17 git clone https://github.com/LiheYoung/Depth-Anything
18 cd Depth-Anything
19 pip install -r requirements.txt
20 ```
21
22 ## Usage
23
24 Here's how to run the model:
25
26 ```python
27 import numpy as np
28 from PIL import Image
29 import cv2
30 import torch
31
32 from depth_anything.dpt import DepthAnything
33 from depth_anything.util.transform import Resize, NormalizeImage, PrepareForNet
34 from torchvision.transforms import Compose
35
36 model = DepthAnything.from_pretrained("LiheYoung/depth_anything_vitb14")
37
38 transform = Compose([
39 Resize(
40 width=518,
41 height=518,
42 resize_target=False,
43 keep_aspect_ratio=True,
44 ensure_multiple_of=14,
45 resize_method='lower_bound',
46 image_interpolation_method=cv2.INTER_CUBIC,
47 ),
48 NormalizeImage(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
49 PrepareForNet(),
50 ])
51
52 image = Image.open("...")
53 image = np.array(image) / 255.0
54 image = transform({'image': image})['image']
55 image = torch.from_numpy(image).unsqueeze(0)
56
57 depth = model(image)
58 ```