Spaces:
Runtime error
Runtime error
tokenid
commited on
Commit
•
00059bc
1
Parent(s):
ac99742
disable video rendering
Browse files- app.py +40 -46
- src/models/lrm_mesh.py +5 -2
app.py
CHANGED
@@ -127,6 +127,9 @@ state_dict = {k[14:]: v for k, v in state_dict.items() if k.startswith('lrm_gene
|
|
127 |
model.load_state_dict(state_dict, strict=True)
|
128 |
|
129 |
model = model.to(device)
|
|
|
|
|
|
|
130 |
|
131 |
print('Loading Finished!')
|
132 |
|
@@ -199,11 +202,6 @@ def make3d(input_image, sample_steps, sample_seed):
|
|
199 |
else:
|
200 |
print("CUDA installation not found")
|
201 |
|
202 |
-
global model
|
203 |
-
if IS_FLEXICUBES:
|
204 |
-
model.init_flexicubes_geometry(device)
|
205 |
-
model = model.eval()
|
206 |
-
|
207 |
images, show_images = generate_mvs(input_image, sample_steps, sample_seed)
|
208 |
|
209 |
images = np.asarray(images, dtype=np.float32) / 255.0
|
@@ -226,46 +224,42 @@ def make3d(input_image, sample_steps, sample_seed):
|
|
226 |
# get triplane
|
227 |
planes = model.forward_planes(images, input_cameras)
|
228 |
|
229 |
-
# get video
|
230 |
-
chunk_size = 20 if IS_FLEXICUBES else 1
|
231 |
-
render_size = 384
|
232 |
|
233 |
-
frames = []
|
234 |
-
for i in tqdm(range(0, render_cameras.shape[1], chunk_size)):
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
frames = torch.cat(frames, dim=1)
|
249 |
-
|
250 |
-
images_to_video(
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
)
|
255 |
-
|
256 |
-
print(f"Video saved to {video_fpath}")
|
257 |
|
258 |
mesh_fpath = make_mesh(mesh_fpath, planes)
|
259 |
|
260 |
-
return
|
261 |
|
262 |
|
263 |
_HEADER_ = '''
|
264 |
-
<h2><b>Official 🤗 Gradio
|
265 |
-
<a href='https://github.com/TencentARC/InstantMesh' target='_blank'>
|
266 |
-
<b>InstantMesh: Efficient 3D Mesh Generation from a Single Image with Sparse-view Large Reconstruction Models</b>
|
267 |
-
</a>.
|
268 |
-
</h2>
|
269 |
'''
|
270 |
|
271 |
_LINKS_ = '''
|
@@ -348,13 +342,13 @@ with gr.Blocks() as demo:
|
|
348 |
interactive=False
|
349 |
)
|
350 |
|
351 |
-
with gr.Column():
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
|
359 |
with gr.Row():
|
360 |
output_model_obj = gr.Model3D(
|
@@ -371,7 +365,7 @@ with gr.Blocks() as demo:
|
|
371 |
).success(
|
372 |
fn=make3d,
|
373 |
inputs=[processed_image, sample_steps, sample_seed],
|
374 |
-
outputs=[
|
375 |
)
|
376 |
|
377 |
demo.launch()
|
|
|
127 |
model.load_state_dict(state_dict, strict=True)
|
128 |
|
129 |
model = model.to(device)
|
130 |
+
if IS_FLEXICUBES:
|
131 |
+
model.init_flexicubes_geometry(device, use_renderer=False)
|
132 |
+
model = model.eval()
|
133 |
|
134 |
print('Loading Finished!')
|
135 |
|
|
|
202 |
else:
|
203 |
print("CUDA installation not found")
|
204 |
|
|
|
|
|
|
|
|
|
|
|
205 |
images, show_images = generate_mvs(input_image, sample_steps, sample_seed)
|
206 |
|
207 |
images = np.asarray(images, dtype=np.float32) / 255.0
|
|
|
224 |
# get triplane
|
225 |
planes = model.forward_planes(images, input_cameras)
|
226 |
|
227 |
+
# # get video
|
228 |
+
# chunk_size = 20 if IS_FLEXICUBES else 1
|
229 |
+
# render_size = 384
|
230 |
|
231 |
+
# frames = []
|
232 |
+
# for i in tqdm(range(0, render_cameras.shape[1], chunk_size)):
|
233 |
+
# if IS_FLEXICUBES:
|
234 |
+
# frame = model.forward_geometry(
|
235 |
+
# planes,
|
236 |
+
# render_cameras[:, i:i+chunk_size],
|
237 |
+
# render_size=render_size,
|
238 |
+
# )['img']
|
239 |
+
# else:
|
240 |
+
# frame = model.synthesizer(
|
241 |
+
# planes,
|
242 |
+
# cameras=render_cameras[:, i:i+chunk_size],
|
243 |
+
# render_size=render_size,
|
244 |
+
# )['images_rgb']
|
245 |
+
# frames.append(frame)
|
246 |
+
# frames = torch.cat(frames, dim=1)
|
247 |
+
|
248 |
+
# images_to_video(
|
249 |
+
# frames[0],
|
250 |
+
# video_fpath,
|
251 |
+
# fps=30,
|
252 |
+
# )
|
253 |
+
|
254 |
+
# print(f"Video saved to {video_fpath}")
|
255 |
|
256 |
mesh_fpath = make_mesh(mesh_fpath, planes)
|
257 |
|
258 |
+
return mesh_fpath, show_images
|
259 |
|
260 |
|
261 |
_HEADER_ = '''
|
262 |
+
<h2><b>Official 🤗 Gradio Demo</b></h2><h2><a href='https://github.com/TencentARC/InstantMesh' target='_blank'><b>InstantMesh: Efficient 3D Mesh Generation from a Single Image with Sparse-view Large Reconstruction Models</b></a></h2>
|
|
|
|
|
|
|
|
|
263 |
'''
|
264 |
|
265 |
_LINKS_ = '''
|
|
|
342 |
interactive=False
|
343 |
)
|
344 |
|
345 |
+
# with gr.Column():
|
346 |
+
# output_video = gr.Video(
|
347 |
+
# label="video", format="mp4",
|
348 |
+
# width=379,
|
349 |
+
# autoplay=True,
|
350 |
+
# interactive=False
|
351 |
+
# )
|
352 |
|
353 |
with gr.Row():
|
354 |
output_model_obj = gr.Model3D(
|
|
|
365 |
).success(
|
366 |
fn=make3d,
|
367 |
inputs=[processed_image, sample_steps, sample_seed],
|
368 |
+
outputs=[output_model_obj, mv_show_images]
|
369 |
)
|
370 |
|
371 |
demo.launch()
|
src/models/lrm_mesh.py
CHANGED
@@ -74,9 +74,12 @@ class InstantMesh(nn.Module):
|
|
74 |
samples_per_ray=rendering_samples_per_ray,
|
75 |
)
|
76 |
|
77 |
-
def init_flexicubes_geometry(self, device, fovy=50.0):
|
78 |
camera = PerspectiveCamera(fovy=fovy, device=device)
|
79 |
-
|
|
|
|
|
|
|
80 |
self.geometry = FlexiCubesGeometry(
|
81 |
grid_res=self.grid_res,
|
82 |
scale=self.grid_scale,
|
|
|
74 |
samples_per_ray=rendering_samples_per_ray,
|
75 |
)
|
76 |
|
77 |
+
def init_flexicubes_geometry(self, device, fovy=50.0, use_renderer=True):
|
78 |
camera = PerspectiveCamera(fovy=fovy, device=device)
|
79 |
+
if use_renderer:
|
80 |
+
renderer = NeuralRender(device, camera_model=camera)
|
81 |
+
else:
|
82 |
+
renderer = None
|
83 |
self.geometry = FlexiCubesGeometry(
|
84 |
grid_res=self.grid_res,
|
85 |
scale=self.grid_scale,
|