Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,7 @@
|
|
1 |
from spaces import GPU
|
2 |
-
|
3 |
-
def dummy_warmup():
|
4 |
-
import torch
|
5 |
-
if torch.cuda.is_available():
|
6 |
-
print("Warmup: GPU is available!")
|
7 |
-
_ = torch.tensor([0.0]).to("cuda")
|
8 |
-
dummy_warmup()
|
9 |
-
|
10 |
import numpy as np
|
11 |
import gradio as gr
|
12 |
-
import torch
|
13 |
import rembg
|
14 |
import trimesh
|
15 |
from moge.model.v1 import MoGeModel
|
@@ -22,6 +14,17 @@ import matplotlib.pyplot as plt
|
|
22 |
from eval_wrapper.eval import EvalWrapper, eval_scene
|
23 |
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
outdir = "/tmp/rayst3r"
|
26 |
|
27 |
# loading all necessary models
|
@@ -101,12 +104,12 @@ def rayst3r_to_glb(img,depth_dict,mask,max_total_points=10e6,rotated=False):
|
|
101 |
|
102 |
dino_model = torch.hub.load('facebookresearch/dinov2', "dinov2_vitl14_reg")
|
103 |
dino_model.eval()
|
104 |
-
dino_model.to(
|
105 |
|
106 |
print("Loading RaySt3R model")
|
107 |
rayst3r_checkpoint = hf_hub_download("bartduis/rayst3r", "rayst3r.pth")
|
108 |
rayst3r_model = EvalWrapper(rayst3r_checkpoint,device='cpu')
|
109 |
-
rayst3r_model = rayst3r_model.to(
|
110 |
|
111 |
rayst3r_points = eval_scene(rayst3r_model,os.path.join(outdir, "input"),do_filter_all_masks=True,dino_model=dino_model).cpu()
|
112 |
|
@@ -159,7 +162,7 @@ def input_to_glb(outdir,img,depth_dict,mask,rotated=False):
|
|
159 |
@GPU
|
160 |
def depth_moge(input_img):
|
161 |
moge_model = MoGeModel.from_pretrained("Ruicheng/moge-vitl")
|
162 |
-
moge_model.to(
|
163 |
input_img_torch = torch.tensor(input_img / 255, dtype=torch.float32, device='cuda').permute(2, 0, 1)
|
164 |
output = moge_model.infer(input_img_torch).cpu()
|
165 |
return output
|
|
|
1 |
from spaces import GPU
|
2 |
+
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import numpy as np
|
4 |
import gradio as gr
|
|
|
5 |
import rembg
|
6 |
import trimesh
|
7 |
from moge.model.v1 import MoGeModel
|
|
|
14 |
from eval_wrapper.eval import EvalWrapper, eval_scene
|
15 |
|
16 |
|
17 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
18 |
+
|
19 |
+
@GPU
|
20 |
+
def dummy_warmup():
|
21 |
+
import torch
|
22 |
+
if torch.cuda.is_available():
|
23 |
+
print("Warmup: GPU is available!")
|
24 |
+
_ = torch.tensor([0.0]).to(device)
|
25 |
+
dummy_warmup()
|
26 |
+
|
27 |
+
|
28 |
outdir = "/tmp/rayst3r"
|
29 |
|
30 |
# loading all necessary models
|
|
|
104 |
|
105 |
dino_model = torch.hub.load('facebookresearch/dinov2', "dinov2_vitl14_reg")
|
106 |
dino_model.eval()
|
107 |
+
dino_model.to(device)
|
108 |
|
109 |
print("Loading RaySt3R model")
|
110 |
rayst3r_checkpoint = hf_hub_download("bartduis/rayst3r", "rayst3r.pth")
|
111 |
rayst3r_model = EvalWrapper(rayst3r_checkpoint,device='cpu')
|
112 |
+
rayst3r_model = rayst3r_model.to(device)
|
113 |
|
114 |
rayst3r_points = eval_scene(rayst3r_model,os.path.join(outdir, "input"),do_filter_all_masks=True,dino_model=dino_model).cpu()
|
115 |
|
|
|
162 |
@GPU
|
163 |
def depth_moge(input_img):
|
164 |
moge_model = MoGeModel.from_pretrained("Ruicheng/moge-vitl")
|
165 |
+
moge_model.to(device)
|
166 |
input_img_torch = torch.tensor(input_img / 255, dtype=torch.float32, device='cuda').permute(2, 0, 1)
|
167 |
output = moge_model.infer(input_img_torch).cpu()
|
168 |
return output
|