bp
Browse files- app.py +8 -8
- eval_wrapper/eval.py +3 -0
app.py
CHANGED
@@ -17,17 +17,10 @@ from spaces import GPU
|
|
17 |
outdir = "/tmp/rayst3r"
|
18 |
|
19 |
# loading all necessary models
|
20 |
-
print("Loading DINOv2 model")
|
21 |
-
dino_model = torch.hub.load('facebookresearch/dinov2', "dinov2_vitl14_reg")
|
22 |
-
dino_model.eval()
|
23 |
|
24 |
print("Loading MoGe model")
|
25 |
# Load the model from huggingface hub (or load from local).
|
26 |
-
moge_model = MoGeModel.from_pretrained("Ruicheng/moge-vitl")
|
27 |
|
28 |
-
print("Loading RaySt3R model")
|
29 |
-
rayst3r_checkpoint = hf_hub_download("bartduis/rayst3r", "rayst3r.pth")
|
30 |
-
rayst3r_model = EvalWrapper(rayst3r_checkpoint,device='cpu')
|
31 |
|
32 |
def depth2uint16(depth):
|
33 |
return depth * torch.iinfo(torch.uint16).max / 10.0 # threshold is in m, convert to uint16 value
|
@@ -98,8 +91,14 @@ def prep_for_rayst3r(img,depth_dict,mask):
|
|
98 |
def rayst3r_to_glb(img,depth_dict,mask,max_total_points=10e6,rotated=False):
|
99 |
prep_for_rayst3r(img,depth_dict,mask)
|
100 |
|
|
|
|
|
101 |
dino_model.to("cuda")
|
102 |
-
|
|
|
|
|
|
|
|
|
103 |
|
104 |
rayst3r_points = eval_scene(rayst3r_model,os.path.join(outdir, "input"),do_filter_all_masks=True,dino_model=dino_model).cpu()
|
105 |
|
@@ -151,6 +150,7 @@ def input_to_glb(outdir,img,depth_dict,mask,rotated=False):
|
|
151 |
|
152 |
@GPU
|
153 |
def depth_moge(input_img):
|
|
|
154 |
moge_model.to("cuda")
|
155 |
input_img_torch = torch.tensor(input_img / 255, dtype=torch.float32, device='cuda').permute(2, 0, 1)
|
156 |
output = moge_model.infer(input_img_torch).cpu()
|
|
|
17 |
outdir = "/tmp/rayst3r"
|
18 |
|
19 |
# loading all necessary models
|
|
|
|
|
|
|
20 |
|
21 |
print("Loading MoGe model")
|
22 |
# Load the model from huggingface hub (or load from local).
|
|
|
23 |
|
|
|
|
|
|
|
24 |
|
25 |
def depth2uint16(depth):
|
26 |
return depth * torch.iinfo(torch.uint16).max / 10.0 # threshold is in m, convert to uint16 value
|
|
|
91 |
def rayst3r_to_glb(img,depth_dict,mask,max_total_points=10e6,rotated=False):
|
92 |
prep_for_rayst3r(img,depth_dict,mask)
|
93 |
|
94 |
+
dino_model = torch.hub.load('facebookresearch/dinov2', "dinov2_vitl14_reg")
|
95 |
+
dino_model.eval()
|
96 |
dino_model.to("cuda")
|
97 |
+
|
98 |
+
print("Loading RaySt3R model")
|
99 |
+
rayst3r_checkpoint = hf_hub_download("bartduis/rayst3r", "rayst3r.pth")
|
100 |
+
rayst3r_model = EvalWrapper(rayst3r_checkpoint,device='cpu')
|
101 |
+
rayst3r_model = rayst3r_model.to("cuda")
|
102 |
|
103 |
rayst3r_points = eval_scene(rayst3r_model,os.path.join(outdir, "input"),do_filter_all_masks=True,dino_model=dino_model).cpu()
|
104 |
|
|
|
150 |
|
151 |
@GPU
|
152 |
def depth_moge(input_img):
|
153 |
+
moge_model = MoGeModel.from_pretrained("Ruicheng/moge-vitl")
|
154 |
moge_model.to("cuda")
|
155 |
input_img_torch = torch.tensor(input_img / 255, dtype=torch.float32, device='cuda').permute(2, 0, 1)
|
156 |
output = moge_model.infer(input_img_torch).cpu()
|
eval_wrapper/eval.py
CHANGED
@@ -38,6 +38,9 @@ class EvalWrapper(torch.nn.Module):
|
|
38 |
self.model.load_state_dict(checkpoint['model'])
|
39 |
self.model.eval()
|
40 |
|
|
|
|
|
|
|
41 |
def forward(self,x,dino_model=None):
|
42 |
pred, gt, loss, scale = eval_model(self.model,x,mode='viz',dino_model=dino_model,return_scale=True)
|
43 |
return pred, gt, loss, scale
|
|
|
38 |
self.model.load_state_dict(checkpoint['model'])
|
39 |
self.model.eval()
|
40 |
|
41 |
+
def to(self,device):
|
42 |
+
self.model.to(device)
|
43 |
+
|
44 |
def forward(self,x,dino_model=None):
|
45 |
pred, gt, loss, scale = eval_model(self.model,x,mode='viz',dino_model=dino_model,return_scale=True)
|
46 |
return pred, gt, loss, scale
|