Spaces:
Runtime error
Runtime error
Add explicit error logging + last-resort MC fallback in flash_extract_geometry
Browse files
patches/triposg/triposg/inference_utils.py
CHANGED
|
@@ -481,6 +481,7 @@ def flash_extract_geometry(
|
|
| 481 |
try:
|
| 482 |
print("final grids shape = ", grid_logits.shape)
|
| 483 |
if DiffDMC is not None:
|
|
|
|
| 484 |
dmc = DiffDMC(dtype=torch.float32).to(grid_logits.device)
|
| 485 |
sdf = -grid_logits / octree_resolution
|
| 486 |
sdf = sdf.to(torch.float32).contiguous()
|
|
@@ -489,6 +490,7 @@ def flash_extract_geometry(
|
|
| 489 |
faces = faces.detach().cpu().numpy()[:, ::-1]
|
| 490 |
vertices = vertices / (2 ** octree_depth) * bbox_size + bbox_min
|
| 491 |
mesh_v_f = (vertices.astype(np.float32), np.ascontiguousarray(faces))
|
|
|
|
| 492 |
else:
|
| 493 |
# DiffDMC unavailable — fall back to marching cubes
|
| 494 |
print("[TripoSG] DiffDMC unavailable, falling back to marching cubes")
|
|
@@ -497,9 +499,21 @@ def flash_extract_geometry(
|
|
| 497 |
vertices, faces, normals, _ = measure.marching_cubes(gl_clean, 0, method="lewiner")
|
| 498 |
vertices = vertices / (2 ** octree_depth) * bbox_size + bbox_min
|
| 499 |
mesh_v_f = (vertices.astype(np.float32), np.ascontiguousarray(faces))
|
|
|
|
| 500 |
except Exception as e:
|
| 501 |
-
|
|
|
|
|
|
|
| 502 |
torch.cuda.empty_cache()
|
| 503 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 504 |
|
| 505 |
return [mesh_v_f]
|
|
|
|
| 481 |
try:
|
| 482 |
print("final grids shape = ", grid_logits.shape)
|
| 483 |
if DiffDMC is not None:
|
| 484 |
+
print("[TripoSG] Attempting DiffDMC extraction...")
|
| 485 |
dmc = DiffDMC(dtype=torch.float32).to(grid_logits.device)
|
| 486 |
sdf = -grid_logits / octree_resolution
|
| 487 |
sdf = sdf.to(torch.float32).contiguous()
|
|
|
|
| 490 |
faces = faces.detach().cpu().numpy()[:, ::-1]
|
| 491 |
vertices = vertices / (2 ** octree_depth) * bbox_size + bbox_min
|
| 492 |
mesh_v_f = (vertices.astype(np.float32), np.ascontiguousarray(faces))
|
| 493 |
+
print(f"[TripoSG] DiffDMC succeeded: {len(vertices)} vertices, {len(faces)} faces")
|
| 494 |
else:
|
| 495 |
# DiffDMC unavailable — fall back to marching cubes
|
| 496 |
print("[TripoSG] DiffDMC unavailable, falling back to marching cubes")
|
|
|
|
| 499 |
vertices, faces, normals, _ = measure.marching_cubes(gl_clean, 0, method="lewiner")
|
| 500 |
vertices = vertices / (2 ** octree_depth) * bbox_size + bbox_min
|
| 501 |
mesh_v_f = (vertices.astype(np.float32), np.ascontiguousarray(faces))
|
| 502 |
+
print(f"[TripoSG] marching cubes succeeded: {len(vertices)} vertices")
|
| 503 |
except Exception as e:
|
| 504 |
+
import traceback as _tb
|
| 505 |
+
print(f"[TripoSG] mesh extraction failed: {e}")
|
| 506 |
+
print(_tb.format_exc())
|
| 507 |
torch.cuda.empty_cache()
|
| 508 |
+
# Last-resort: marching cubes on nan-cleaned grid
|
| 509 |
+
try:
|
| 510 |
+
gl_np = np.nan_to_num(grid_logits.float().cpu().numpy(), nan=0.0)
|
| 511 |
+
vertices, faces, normals, _ = measure.marching_cubes(gl_np, 0, method="lewiner")
|
| 512 |
+
vertices = vertices / max(gl_np.shape) * bbox_size + bbox_min
|
| 513 |
+
mesh_v_f = (vertices.astype(np.float32), np.ascontiguousarray(faces))
|
| 514 |
+
print(f"[TripoSG] last-resort MC succeeded: {len(vertices)} vertices")
|
| 515 |
+
except Exception as e2:
|
| 516 |
+
print(f"[TripoSG] last-resort MC also failed: {e2}")
|
| 517 |
+
mesh_v_f = (None, None)
|
| 518 |
|
| 519 |
return [mesh_v_f]
|