File size: 962 Bytes
77d68aa
 
 
6b488bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
---

license: apache-2.0
---


This is the Offical weights of ConFiDeNet

```python

from PIL import Image

import torch

from transformers import ConFiDeNetForDepthEstimation, ConFiDeNetImageProcessor



device = torch.device("cuda" if torch.cuda.is_available() else "cpu")



image = Image.open("<Image Path>").convert("RGB")

print(image.size)

# image.save("image.jpg")



image_processor = ConFiDeNetImageProcessor.from_pretrained("<Weight-Path>")

model = ConFiDeNetForDepthEstimation.from_pretrained("<Weigh-Path>").to(device)



inputs = image_processor(images=image, return_tensors="pt").to(device)



with torch.no_grad():

    outputs = model(**inputs)



post_processed_output = image_processor.post_process_depth_estimation(

    outputs, target_sizes=[(image.height, image.width)],

)



depth = post_processed_output[0]["predicted_depth_uint16"].detach().cpu().numpy()

depth = Image.fromarray(depth, mode="I;16")

depth.save("depth.png")

```