tphung commited on
Commit
8511d74
1 Parent(s): b652aa3

Use dpt-large

Browse files
Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -4,7 +4,7 @@ from PIL import ImageDraw
4
  import torch
5
 
6
  detector = pipeline("zero-shot-object-detection", model="google/owlvit-base-patch32")
7
- depth_estimator = pipeline("depth-estimation", model="vinvino02/glpn-nyu")
8
 
9
  def visualize_preds(image, predictions):
10
  new_image = image.copy()
@@ -23,21 +23,18 @@ def visualize_preds(image, predictions):
23
  def compute_depth(image, preds):
24
 
25
  output = depth_estimator(image)
26
- print(output)
27
  prediction = torch.nn.functional.interpolate(
28
  output["predicted_depth"].unsqueeze(1),
29
  size=image.size[::-1],
30
  mode="bicubic",
31
  align_corners=False,
32
- ).squeeze().numpy()
33
-
34
- print(prediction.shape)
35
-
36
  output = []
37
 
38
  for pred in preds:
39
- x = (pred["box"]["xmax"] - pred["box"]["xmin"]) // 2
40
- y = (pred["box"]["ymax"] - pred["box"]["ymin"]) // 2
41
  output.append({
42
  "class": pred["label"],
43
  "distance": float(prediction[y][x])
 
4
  import torch
5
 
6
  detector = pipeline("zero-shot-object-detection", model="google/owlvit-base-patch32")
7
+ depth_estimator = pipeline("depth-estimation", model="Intel/dpt-large")
8
 
9
  def visualize_preds(image, predictions):
10
  new_image = image.copy()
 
23
  def compute_depth(image, preds):
24
 
25
  output = depth_estimator(image)
 
26
  prediction = torch.nn.functional.interpolate(
27
  output["predicted_depth"].unsqueeze(1),
28
  size=image.size[::-1],
29
  mode="bicubic",
30
  align_corners=False,
31
+ ).squeeze().cpu().numpy()
32
+
 
 
33
  output = []
34
 
35
  for pred in preds:
36
+ x = (pred["box"]["xmax"] + pred["box"]["xmin"]) // 2
37
+ y = (pred["box"]["ymax"] + pred["box"]["ymin"]) // 2
38
  output.append({
39
  "class": pred["label"],
40
  "distance": float(prediction[y][x])