Update app.py
Browse files
app.py
CHANGED
@@ -15,9 +15,12 @@ midas_transform = torch.hub.load("intel-isl/MiDaS", "transforms").default_transf
|
|
15 |
|
16 |
def estimate_depth(image):
|
17 |
image = image.convert("RGB")
|
18 |
-
|
|
|
|
|
19 |
with torch.no_grad():
|
20 |
-
depth = midas_model(
|
|
|
21 |
depth = cv2.resize(depth, (image.size[0], image.size[1]))
|
22 |
depth = (depth - depth.min()) / (depth.max() - depth.min()) * 255
|
23 |
return depth.astype(np.uint8)
|
|
|
15 |
|
16 |
def estimate_depth(image):
|
17 |
image = image.convert("RGB")
|
18 |
+
image_np = np.array(image) / 255.0 # Convert PIL image to NumPy and normalize
|
19 |
+
image_tensor = torch.tensor(image_np, dtype=torch.float32).permute(2, 0, 1).unsqueeze(0).to(device)
|
20 |
+
|
21 |
with torch.no_grad():
|
22 |
+
depth = midas_model(image_tensor).squeeze().cpu().numpy()
|
23 |
+
|
24 |
depth = cv2.resize(depth, (image.size[0], image.size[1]))
|
25 |
depth = (depth - depth.min()) / (depth.max() - depth.min()) * 255
|
26 |
return depth.astype(np.uint8)
|