Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -41,23 +41,24 @@ css = """
|
|
| 41 |
|
| 42 |
set_seed(666)
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
def main(share=True):
|
| 45 |
print("Initializing Pixel-Perfect Depth Demo...")
|
| 46 |
-
|
| 47 |
-
# DEVICE = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 48 |
-
DEVICE = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 49 |
-
default_steps = 10
|
| 50 |
-
model = PixelPerfectDepth(sampling_steps=default_steps)
|
| 51 |
-
ckpt_path = hf_hub_download(
|
| 52 |
-
repo_id="gangweix/Pixel-Perfect-Depth",
|
| 53 |
-
filename="ppd.pth",
|
| 54 |
-
repo_type="model"
|
| 55 |
-
)
|
| 56 |
-
state_dict = torch.load(ckpt_path, map_location="cpu")
|
| 57 |
-
model.load_state_dict(state_dict, strict=False)
|
| 58 |
-
model = model.to(DEVICE).eval()
|
| 59 |
-
|
| 60 |
-
moge_model = MoGeModel.from_pretrained("Ruicheng/moge-2-vitl-normal").to(DEVICE).eval()
|
| 61 |
|
| 62 |
cmap = matplotlib.colormaps.get_cmap('Spectral')
|
| 63 |
|
|
@@ -90,7 +91,7 @@ def main(share=True):
|
|
| 90 |
moge_depth, mask, intrinsics = predict_moge_depth(resize_image)
|
| 91 |
|
| 92 |
# relative depth -> metric depth
|
| 93 |
-
metric_depth = recover_metric_depth_ransac(ppd_depth
|
| 94 |
intrinsics[0, 0] *= resize_W
|
| 95 |
intrinsics[1, 1] *= resize_H
|
| 96 |
intrinsics[0, 2] *= resize_W
|
|
@@ -112,7 +113,7 @@ def main(share=True):
|
|
| 112 |
tmp_raw_depth = tempfile.NamedTemporaryFile(suffix='.npy', delete=False)
|
| 113 |
np.save(tmp_raw_depth.name, depth)
|
| 114 |
|
| 115 |
-
depth_vis = (depth - depth.min()) / (depth.max() - depth.min()+1e-5) * 255.0
|
| 116 |
depth_vis = depth_vis.astype(np.uint8)
|
| 117 |
colored_depth = (cmap(depth_vis)[:, :, :3] * 255).astype(np.uint8)
|
| 118 |
|
|
|
|
| 41 |
|
| 42 |
set_seed(666)
|
| 43 |
|
| 44 |
+
DEVICE = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 45 |
+
# DEVICE = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 46 |
+
default_steps = 10
|
| 47 |
+
model = PixelPerfectDepth(sampling_steps=default_steps)
|
| 48 |
+
ckpt_path = hf_hub_download(
|
| 49 |
+
repo_id="gangweix/Pixel-Perfect-Depth",
|
| 50 |
+
filename="ppd.pth",
|
| 51 |
+
repo_type="model"
|
| 52 |
+
)
|
| 53 |
+
state_dict = torch.load(ckpt_path, map_location="cpu")
|
| 54 |
+
model.load_state_dict(state_dict, strict=False)
|
| 55 |
+
model = model.to(DEVICE).eval()
|
| 56 |
+
|
| 57 |
+
moge_model = MoGeModel.from_pretrained("Ruicheng/moge-2-vitl-normal").to(DEVICE).eval()
|
| 58 |
+
|
| 59 |
+
|
| 60 |
def main(share=True):
|
| 61 |
print("Initializing Pixel-Perfect Depth Demo...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
cmap = matplotlib.colormaps.get_cmap('Spectral')
|
| 64 |
|
|
|
|
| 91 |
moge_depth, mask, intrinsics = predict_moge_depth(resize_image)
|
| 92 |
|
| 93 |
# relative depth -> metric depth
|
| 94 |
+
metric_depth = recover_metric_depth_ransac(ppd_depth, moge_depth, mask)
|
| 95 |
intrinsics[0, 0] *= resize_W
|
| 96 |
intrinsics[1, 1] *= resize_H
|
| 97 |
intrinsics[0, 2] *= resize_W
|
|
|
|
| 113 |
tmp_raw_depth = tempfile.NamedTemporaryFile(suffix='.npy', delete=False)
|
| 114 |
np.save(tmp_raw_depth.name, depth)
|
| 115 |
|
| 116 |
+
depth_vis = (depth - depth.min()) / (depth.max() - depth.min() + 1e-5) * 255.0
|
| 117 |
depth_vis = depth_vis.astype(np.uint8)
|
| 118 |
colored_depth = (cmap(depth_vis)[:, :, :3] * 255).astype(np.uint8)
|
| 119 |
|