Spaces:
Running
on
L40S
Running
on
L40S
Update app.py
Browse files
app.py
CHANGED
@@ -332,96 +332,18 @@ def move_to_device(model, device):
|
|
332 |
|
333 |
@spaces.GPU
|
334 |
def extract_glb(state: dict, mesh_simplify: float, texture_size: int) -> Tuple[str, str]:
|
|
|
|
|
|
|
335 |
try:
|
336 |
-
# GPU ๋ฉ๋ชจ๋ฆฌ ์ ๋ฆฌ
|
337 |
-
clear_gpu_memory()
|
338 |
-
|
339 |
-
# ์ํ ์ธํจํน
|
340 |
gs, mesh, trial_id = unpack_state(state)
|
341 |
-
|
342 |
-
# GLB ๋ณํ ์ ์ ํจ์ฑ ๊ฒ์ฌ
|
343 |
-
if gs is None or mesh is None:
|
344 |
-
print("Error: Invalid gaussian or mesh data")
|
345 |
-
return None, None
|
346 |
-
|
347 |
-
# GLB ๋ณํ
|
348 |
-
with torch.inference_mode():
|
349 |
-
try:
|
350 |
-
# ๋ชจ๋ ํ
์๋ฅผ CUDA๋ก ์ด๋ (gradient ๋ถํ์)
|
351 |
-
device = torch.device('cuda:0')
|
352 |
-
|
353 |
-
# Gaussian ํ
์๋ค์ ๋ณํ
|
354 |
-
for attr_name in ['_xyz', '_features_dc', '_scaling', '_rotation', '_opacity']:
|
355 |
-
if hasattr(gs, attr_name):
|
356 |
-
tensor = getattr(gs, attr_name)
|
357 |
-
if torch.is_tensor(tensor):
|
358 |
-
new_tensor = tensor.detach().clone().float().to(device)
|
359 |
-
setattr(gs, attr_name, new_tensor)
|
360 |
-
|
361 |
-
# Mesh ํ
์๋ค์ ๋ณํ
|
362 |
-
if hasattr(mesh, 'vertices') and torch.is_tensor(mesh.vertices):
|
363 |
-
mesh.vertices = mesh.vertices.detach().clone().float().to(device)
|
364 |
-
if hasattr(mesh, 'faces') and torch.is_tensor(mesh.faces):
|
365 |
-
mesh.faces = mesh.faces.detach().clone().long().to(device)
|
366 |
-
|
367 |
-
# ์ถ๊ฐ ์์ฑ ํ์ธ ๋ฐ ๋ณํ (gradient ๋ถํ์)
|
368 |
-
for attr_name in dir(mesh):
|
369 |
-
if attr_name.startswith('_'):
|
370 |
-
continue
|
371 |
-
attr = getattr(mesh, attr_name)
|
372 |
-
if torch.is_tensor(attr):
|
373 |
-
if attr.dtype in [torch.float32, torch.float64]:
|
374 |
-
setattr(mesh, attr_name, attr.to(device))
|
375 |
-
else:
|
376 |
-
setattr(mesh, attr_name, attr.to(device))
|
377 |
-
|
378 |
-
print("Device and gradient check before GLB conversion:")
|
379 |
-
print(f"Gaussian xyz device: {gs._xyz.device}, requires_grad: {gs._xyz.requires_grad}")
|
380 |
-
print(f"Mesh vertices device: {mesh.vertices.device}, requires_grad: {mesh.vertices.requires_grad}")
|
381 |
-
|
382 |
-
# GLB ๋ณํ
|
383 |
-
glb = postprocessing_utils.to_glb(
|
384 |
-
gs,
|
385 |
-
mesh,
|
386 |
-
simplify=mesh_simplify,
|
387 |
-
texture_size=texture_size,
|
388 |
-
verbose=True
|
389 |
-
)
|
390 |
-
|
391 |
-
except Exception as e:
|
392 |
-
print(f"Error during GLB conversion: {str(e)}")
|
393 |
-
# ๋๋ฐ์ด์ค์ gradient ์ ๋ณด ์ถ๋ ฅ
|
394 |
-
if hasattr(gs, '_xyz'):
|
395 |
-
print(f"Gaussian xyz device: {gs._xyz.device}, requires_grad: {gs._xyz.requires_grad}")
|
396 |
-
if hasattr(mesh, 'vertices'):
|
397 |
-
print(f"Mesh vertices device: {mesh.vertices.device}, requires_grad: {mesh.vertices.requires_grad}")
|
398 |
-
return None, None
|
399 |
-
|
400 |
-
if glb is None:
|
401 |
-
print("Error: GLB conversion failed")
|
402 |
-
return None, None
|
403 |
-
|
404 |
-
# ํ์ผ ์ ์ฅ
|
405 |
glb_path = f"{TMP_DIR}/{trial_id}.glb"
|
406 |
-
|
407 |
-
glb.export(glb_path)
|
408 |
-
if not os.path.exists(glb_path):
|
409 |
-
print(f"Error: GLB file was not created at {glb_path}")
|
410 |
-
return None, None
|
411 |
-
except Exception as e:
|
412 |
-
print(f"Error saving GLB file: {str(e)}")
|
413 |
-
return None, None
|
414 |
-
|
415 |
-
print(f"Successfully created GLB file at: {glb_path}")
|
416 |
return glb_path, glb_path
|
417 |
-
|
418 |
except Exception as e:
|
419 |
-
print(f"
|
420 |
return None, None
|
421 |
-
|
422 |
-
finally:
|
423 |
-
# ์ ๋ฆฌ ์์
|
424 |
-
clear_gpu_memory()
|
425 |
|
426 |
|
427 |
|
|
|
332 |
|
333 |
@spaces.GPU
|
334 |
def extract_glb(state: dict, mesh_simplify: float, texture_size: int) -> Tuple[str, str]:
|
335 |
+
"""
|
336 |
+
3D ๋ชจ๋ธ์์ GLB ํ์ผ ์ถ์ถ
|
337 |
+
"""
|
338 |
try:
|
|
|
|
|
|
|
|
|
339 |
gs, mesh, trial_id = unpack_state(state)
|
340 |
+
glb = postprocessing_utils.to_glb(gs, mesh, simplify=mesh_simplify, texture_size=texture_size, verbose=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
341 |
glb_path = f"{TMP_DIR}/{trial_id}.glb"
|
342 |
+
glb.export(glb_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
343 |
return glb_path, glb_path
|
|
|
344 |
except Exception as e:
|
345 |
+
print(f"GLB ์ถ์ถ ์ค ์ค๋ฅ ๋ฐ์: {e}")
|
346 |
return None, None
|
|
|
|
|
|
|
|
|
347 |
|
348 |
|
349 |
|