Update app.py
Browse files
app.py
CHANGED
@@ -9,14 +9,13 @@ def dummy_warmup():
|
|
9 |
else:
|
10 |
print("[WARNING] CUDA not available. Skipping warmup.")
|
11 |
|
12 |
-
import os
|
13 |
import numpy as np
|
14 |
import gradio as gr
|
15 |
import rembg
|
16 |
-
|
17 |
from moge.model.v1 import MoGeModel
|
18 |
-
|
19 |
-
# import os, shutil
|
20 |
import cv2
|
21 |
# from huggingface_hub import hf_hub_download
|
22 |
# from PIL import Image
|
@@ -137,31 +136,31 @@ moge_model = MoGeModel.from_pretrained("Ruicheng/moge-vitl").to(device)
|
|
137 |
# return outfile
|
138 |
|
139 |
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
|
158 |
|
159 |
-
|
160 |
-
|
161 |
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
|
166 |
@GPU(duration = 180)
|
167 |
def depth_moge(input_img):
|
@@ -202,7 +201,8 @@ def process_image(input_img):
|
|
202 |
if os.path.exists(outdir):
|
203 |
shutil.rmtree(outdir)
|
204 |
os.makedirs(outdir)
|
205 |
-
|
|
|
206 |
return input_img, input_img
|
207 |
|
208 |
# def process_image(input_img):
|
|
|
9 |
else:
|
10 |
print("[WARNING] CUDA not available. Skipping warmup.")
|
11 |
|
12 |
+
import os, shutil
|
13 |
import numpy as np
|
14 |
import gradio as gr
|
15 |
import rembg
|
16 |
+
import trimesh
|
17 |
from moge.model.v1 import MoGeModel
|
18 |
+
from utils.geometry import compute_pointmap
|
|
|
19 |
import cv2
|
20 |
# from huggingface_hub import hf_hub_download
|
21 |
# from PIL import Image
|
|
|
136 |
# return outfile
|
137 |
|
138 |
|
139 |
+
def input_to_glb(outdir,img,depth_dict,mask,rotated=False):
|
140 |
+
H, W = img.shape[:2]
|
141 |
+
intrinsics = depth_dict["intrinsics"].cpu().numpy()
|
142 |
+
intrinsics[0] *= W
|
143 |
+
intrinsics[1] *= H
|
144 |
|
145 |
+
depth = depth_dict["depth"].cpu().numpy()
|
146 |
+
cam2world = np.eye(4)
|
147 |
+
points_world = compute_pointmap(depth, cam2world, intrinsics)
|
148 |
|
149 |
+
scene = trimesh.Scene()
|
150 |
+
pts = np.concatenate([p[m] for p,m in zip(points_world,mask)])
|
151 |
+
col = np.concatenate([c[m] for c,m in zip(img,mask)])
|
152 |
|
153 |
+
pts = pts.reshape(-1,3)
|
154 |
+
pts[:,1] = -pts[:,1]
|
155 |
+
pts[:,2] = -pts[:,2]
|
156 |
|
157 |
|
158 |
+
pct = trimesh.PointCloud(pts, colors=col.reshape(-1,3))
|
159 |
+
scene.add_geometry(pct)
|
160 |
|
161 |
+
outfile = os.path.join(outdir, "input.glb")
|
162 |
+
scene.export(outfile)
|
163 |
+
return outfile
|
164 |
|
165 |
@GPU(duration = 180)
|
166 |
def depth_moge(input_img):
|
|
|
201 |
if os.path.exists(outdir):
|
202 |
shutil.rmtree(outdir)
|
203 |
os.makedirs(outdir)
|
204 |
+
input_glb = input_to_glb(outdir,input_img,depth_dict,mask,rotated=rotated)
|
205 |
+
print(input_glb)
|
206 |
return input_img, input_img
|
207 |
|
208 |
# def process_image(input_img):
|