Spaces:
Running
on
L40S
Running
on
L40S
Update app.py
Browse files
app.py
CHANGED
@@ -347,29 +347,46 @@ def extract_glb(state: dict, mesh_simplify: float, texture_size: int) -> Tuple[s
|
|
347 |
# GLB λ³ν
|
348 |
with torch.inference_mode():
|
349 |
try:
|
350 |
-
# Gaussian
|
351 |
for attr_name in ['_xyz', '_features_dc', '_scaling', '_rotation', '_opacity']:
|
352 |
if hasattr(gs, attr_name):
|
353 |
tensor = getattr(gs, attr_name)
|
354 |
if torch.is_tensor(tensor):
|
355 |
-
|
|
|
|
|
356 |
|
357 |
-
# Mesh
|
358 |
if hasattr(mesh, 'vertices') and torch.is_tensor(mesh.vertices):
|
359 |
-
mesh.vertices.requires_grad_(
|
360 |
if hasattr(mesh, 'faces') and torch.is_tensor(mesh.faces):
|
361 |
-
mesh.faces.requires_grad_(
|
362 |
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
370 |
|
371 |
-
except
|
372 |
-
print(f"
|
373 |
return None, None
|
374 |
|
375 |
if glb is None:
|
|
|
347 |
# GLB λ³ν
|
348 |
with torch.inference_mode():
|
349 |
try:
|
350 |
+
# Gaussian ν
μλ€μ requires_grad=Trueλ‘ μ€μ
|
351 |
for attr_name in ['_xyz', '_features_dc', '_scaling', '_rotation', '_opacity']:
|
352 |
if hasattr(gs, attr_name):
|
353 |
tensor = getattr(gs, attr_name)
|
354 |
if torch.is_tensor(tensor):
|
355 |
+
# ν
μλ₯Ό 볡μ νκ³ requires_grad μ€μ
|
356 |
+
new_tensor = tensor.clone().detach().requires_grad_(True)
|
357 |
+
setattr(gs, attr_name, new_tensor)
|
358 |
|
359 |
+
# Mesh ν
μλ€μ requires_grad=Trueλ‘ μ€μ
|
360 |
if hasattr(mesh, 'vertices') and torch.is_tensor(mesh.vertices):
|
361 |
+
mesh.vertices = mesh.vertices.clone().detach().requires_grad_(True)
|
362 |
if hasattr(mesh, 'faces') and torch.is_tensor(mesh.faces):
|
363 |
+
mesh.faces = mesh.faces.clone().detach().requires_grad_(True)
|
364 |
|
365 |
+
# GLB λ³ν μλ
|
366 |
+
try:
|
367 |
+
glb = postprocessing_utils.to_glb(
|
368 |
+
gs,
|
369 |
+
mesh,
|
370 |
+
simplify=mesh_simplify,
|
371 |
+
texture_size=texture_size,
|
372 |
+
verbose=True,
|
373 |
+
optimize_uv=True, # UV μ΅μ ν νμ±ν
|
374 |
+
optimize_steps=2500 # μ΅μ ν μ€ν
μ μ€μ
|
375 |
+
)
|
376 |
+
except RuntimeError as e:
|
377 |
+
print(f"GLB conversion failed with RuntimeError: {str(e)}")
|
378 |
+
# μ΅μ ν μμ΄ λ€μ μλ
|
379 |
+
glb = postprocessing_utils.to_glb(
|
380 |
+
gs,
|
381 |
+
mesh,
|
382 |
+
simplify=mesh_simplify,
|
383 |
+
texture_size=texture_size,
|
384 |
+
verbose=True,
|
385 |
+
optimize_uv=False # UV μ΅μ ν λΉνμ±ν
|
386 |
+
)
|
387 |
|
388 |
+
except Exception as e:
|
389 |
+
print(f"Error during GLB conversion: {str(e)}")
|
390 |
return None, None
|
391 |
|
392 |
if glb is None:
|