gaur3009 commited on
Commit
d55d4b0
·
verified ·
1 Parent(s): 4212bd7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
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
- img_tensor = midas_transform(image).to(device)
 
 
19
  with torch.no_grad():
20
- depth = midas_model(img_tensor).squeeze().cpu().numpy()
 
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)