Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -33,7 +33,7 @@ processor = DPTImageProcessor.from_pretrained("Intel/dpt-swinv2-tiny-256")
|
|
33 |
|
34 |
color_map = torch.from_numpy(cv2.applyColorMap(np.arange(256, dtype=np.uint8), cv2.COLORMAP_INFERNO)).to(device)
|
35 |
|
36 |
-
input_tensor = torch.zeros((1, 3,
|
37 |
|
38 |
def preprocess_image(image):
|
39 |
return cv2.resize(image, (128, 72), interpolation=cv2.INTER_AREA).transpose(2, 0, 1).astype(np.float32) / 255.0
|
@@ -49,13 +49,10 @@ def process_frame(image):
|
|
49 |
depth_map = predicted_depth.squeeze()
|
50 |
|
51 |
# Discretization on GPU
|
52 |
-
num_bins =
|
53 |
-
|
54 |
-
|
55 |
-
depth_map = torch.bucketize(depth_map, bins)
|
56 |
|
57 |
-
depth_map = (depth_map - depth_map.min()) / (depth_map.max() - depth_map.min())
|
58 |
-
depth_map = (depth_map * 255).byte()
|
59 |
depth_map_colored = color_map[depth_map]
|
60 |
|
61 |
return cv2.cvtColor(depth_map_colored.cpu().numpy(), cv2.COLOR_BGR2RGB)
|
|
|
33 |
|
34 |
color_map = torch.from_numpy(cv2.applyColorMap(np.arange(256, dtype=np.uint8), cv2.COLORMAP_INFERNO)).to(device)
|
35 |
|
36 |
+
input_tensor = torch.zeros((1, 3, 72, 128), dtype=torch.float32, device=device)
|
37 |
|
38 |
def preprocess_image(image):
|
39 |
return cv2.resize(image, (128, 72), interpolation=cv2.INTER_AREA).transpose(2, 0, 1).astype(np.float32) / 255.0
|
|
|
49 |
depth_map = predicted_depth.squeeze()
|
50 |
|
51 |
# Discretization on GPU
|
52 |
+
num_bins = 256 # Match the color_map size
|
53 |
+
depth_map = torch.quantile(depth_map, torch.linspace(0, 1, num_bins, device=device))
|
54 |
+
depth_map = torch.bucketize(depth_map.squeeze(), depth_map)
|
|
|
55 |
|
|
|
|
|
56 |
depth_map_colored = color_map[depth_map]
|
57 |
|
58 |
return cv2.cvtColor(depth_map_colored.cpu().numpy(), cv2.COLOR_BGR2RGB)
|