aiqtech commited on
Commit
9294203
โ€ข
1 Parent(s): b31b828

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -84
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
- try:
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"Error in extract_glb: {str(e)}")
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