gangweix commited on
Commit
30639d6
·
verified ·
1 Parent(s): ebeb031

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -4,7 +4,6 @@ import matplotlib
4
  import numpy as np
5
  import os
6
  from PIL import Image
7
- import spaces
8
  import torch
9
  import torch.nn.functional as F
10
  import open3d as o3d
@@ -18,6 +17,12 @@ from ppd.utils.depth2pcd import depth2pcd
18
  from moge.model.v2 import MoGeModel
19
  from ppd.models.ppd import PixelPerfectDepth
20
 
 
 
 
 
 
 
21
  css = """
22
  #img-display-container {
23
  max-height: 100vh;
@@ -66,16 +71,18 @@ def main(share=True):
66
  description = """Official demo for **Pixel-Perfect Depth**.
67
  Please refer to our [paper](), [project page](https://pixel-perfect-depth.github.io), and [github](https://github.com/gangweix/pixel-perfect-depth) for more details."""
68
 
69
- @spaces.GPU
70
  def predict_depth(image, denoise_steps):
 
71
  model = model.to(DEVICE)
72
  depth, resize_image = model.infer_image(image, sampling_steps=denoise_steps)
73
  return depth, resize_image
74
 
75
- @spaces.GPU
76
  def predict_moge_depth(image):
77
  image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
78
  image = torch.tensor(image / 255, dtype=torch.float32, device=DEVICE).permute(2, 0, 1)
 
79
  moge_model = moge_model.to(DEVICE)
80
  metric_depth, mask, intrinsics = moge_model.infer(image)
81
  metric_depth[~mask] = metric_depth[mask].max()
 
4
  import numpy as np
5
  import os
6
  from PIL import Image
 
7
  import torch
8
  import torch.nn.functional as F
9
  import open3d as o3d
 
17
  from moge.model.v2 import MoGeModel
18
  from ppd.models.ppd import PixelPerfectDepth
19
 
20
+ try:
21
+ import spaces
22
+ HUGGINFACE_SPACES_INSTALLED = True
23
+ except ImportError:
24
+ HUGGINFACE_SPACES_INSTALLED = False
25
+
26
  css = """
27
  #img-display-container {
28
  max-height: 100vh;
 
71
  description = """Official demo for **Pixel-Perfect Depth**.
72
  Please refer to our [paper](), [project page](https://pixel-perfect-depth.github.io), and [github](https://github.com/gangweix/pixel-perfect-depth) for more details."""
73
 
74
+ @(spaces.GPU if HUGGINFACE_SPACES_INSTALLED else (lambda x: x))
75
  def predict_depth(image, denoise_steps):
76
+ global model
77
  model = model.to(DEVICE)
78
  depth, resize_image = model.infer_image(image, sampling_steps=denoise_steps)
79
  return depth, resize_image
80
 
81
+ @(spaces.GPU if HUGGINFACE_SPACES_INSTALLED else (lambda x: x))
82
  def predict_moge_depth(image):
83
  image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
84
  image = torch.tensor(image / 255, dtype=torch.float32, device=DEVICE).permute(2, 0, 1)
85
+ global moge_model
86
  moge_model = moge_model.to(DEVICE)
87
  metric_depth, mask, intrinsics = moge_model.infer(image)
88
  metric_depth[~mask] = metric_depth[mask].max()