umaradnaan commited on
Commit
6fdeeb9
·
verified ·
1 Parent(s): abd72f0

Update utils/depth_utils.py

Browse files
Files changed (1) hide show
  1. utils/depth_utils.py +23 -25
utils/depth_utils.py CHANGED
@@ -1,25 +1,23 @@
1
- import torch
2
- import cv2
3
- import numpy as np
4
- from transformers import DPTFeatureExtractor, DPTForDepthEstimation
5
-
6
- feature_extractor = DPTFeatureExtractor.from_pretrained("Intel/dpt-large")
7
- model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large")
8
- model.eval()
9
-
10
- def estimate_depth(frame_paths):
11
- depth_maps = []
12
-
13
- for path in frame_paths:
14
- image = cv2.imread(path)
15
- image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
16
-
17
- inputs = feature_extractor(images=image, return_tensors="pt")
18
- with torch.no_grad():
19
- outputs = model(**inputs)
20
- depth = outputs.predicted_depth[0].cpu().numpy()
21
-
22
- depth = cv2.resize(depth, (image.shape[1], image.shape[0]))
23
- depth_maps.append(depth)
24
-
25
- return depth_maps
 
1
+ import torch
2
+ import cv2
3
+ from transformers import DPTFeatureExtractor, DPTForDepthEstimation
4
+
5
+ extractor = DPTFeatureExtractor.from_pretrained("Intel/dpt-large")
6
+ model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large")
7
+ model.eval()
8
+
9
+ def estimate_depth(frame_paths):
10
+ depth_maps = []
11
+
12
+ for path in frame_paths:
13
+ image = cv2.imread(path)
14
+ image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
15
+
16
+ inputs = extractor(images=image, return_tensors="pt")
17
+ with torch.no_grad():
18
+ outputs = model(**inputs)
19
+ depth = outputs.predicted_depth[0].cpu().numpy()
20
+
21
+ depth_maps.append(depth)
22
+
23
+ return depth_maps