aiqtech commited on
Commit
c09aad1
Β·
verified Β·
1 Parent(s): e967463

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -14
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 객체의 ν…μ„œλ“€μ— λŒ€ν•΄ requires_grad μ„€μ •
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
- tensor.requires_grad_(False)
 
 
356
 
357
- # Mesh ν…μ„œλ“€μ— λŒ€ν•΄ requires_grad μ„€μ •
358
  if hasattr(mesh, 'vertices') and torch.is_tensor(mesh.vertices):
359
- mesh.vertices.requires_grad_(False)
360
  if hasattr(mesh, 'faces') and torch.is_tensor(mesh.faces):
361
- mesh.faces.requires_grad_(False)
362
 
363
- glb = postprocessing_utils.to_glb(
364
- gs,
365
- mesh,
366
- simplify=mesh_simplify,
367
- texture_size=texture_size,
368
- verbose=True
369
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
370
 
371
- except RuntimeError as e:
372
- print(f"Runtime error during GLB conversion: {str(e)}")
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: