junaid-simamdigital commited on
Commit
54e2555
·
verified ·
1 Parent(s): 9a916a2

fix: optimize bounded direct Gaussian export

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -55,7 +55,7 @@ MAX_VIEWS = int(os.getenv("SIMAM3D_MAX_VIEWS", "8"))
55
  MAX_INPUT_SIDE = int(os.getenv("SIMAM3D_MAX_INPUT_SIDE", "1536"))
56
  FUSION_VOXEL_SIZE = float(os.getenv("SIMAM3D_FUSION_VOXEL_SIZE", "0.02"))
57
  FUSION_MAX_POINTS = int(os.getenv("SIMAM3D_FUSION_MAX_POINTS", "150000"))
58
- GAUSSIAN_MAX_POINTS = int(os.getenv("SIMAM3D_GAUSSIAN_MAX_POINTS", "100000"))
59
  DEPTH_PIPELINE = None
60
  DA3_MODEL = None
61
  PIPELINE_LOCK = threading.Lock()
@@ -427,10 +427,12 @@ def direct_da3_gaussian_ply(prediction, run_id: str) -> tuple[str, int, int] | N
427
  gaussians = getattr(prediction, "gaussians", None)
428
  if gaussians is None:
429
  return None
 
430
  means = _prediction_array(getattr(gaussians, "means", None))
431
  scales = _prediction_array(getattr(gaussians, "scales", None))
432
  rotations = _prediction_array(getattr(gaussians, "rotations", None))
433
  opacities = _prediction_array(getattr(gaussians, "opacities", None)).reshape(-1)
 
434
  if means.ndim == 3 and means.shape[0] == 1:
435
  means = means[0]
436
  if scales.ndim == 3 and scales.shape[0] == 1:
@@ -451,14 +453,19 @@ def direct_da3_gaussian_ply(prediction, run_id: str) -> tuple[str, int, int] | N
451
  means, scales, rotations, opacities = means[keep], scales[keep], rotations[keep], opacities[keep]
452
  harmonics = getattr(gaussians, "harmonics", None)
453
  if harmonics is not None:
 
 
 
 
454
  harmonics = _prediction_array(harmonics)
455
  if harmonics.ndim == 4 and harmonics.shape[0] == 1:
456
  harmonics = harmonics[0]
 
 
457
  if keep is not None and harmonics.shape[0] == original_count:
458
  harmonics = harmonics[keep]
459
- if harmonics.ndim == 3 and harmonics.shape[0] == len(means):
460
- dc = harmonics[..., 0]
461
- colors = np.clip((dc * 0.2820947918 + 0.5) * 255.0, 0, 255).astype(np.uint8)
462
  else:
463
  colors = np.full((len(means), 3), 180, dtype=np.uint8)
464
  else:
 
55
  MAX_INPUT_SIDE = int(os.getenv("SIMAM3D_MAX_INPUT_SIDE", "1536"))
56
  FUSION_VOXEL_SIZE = float(os.getenv("SIMAM3D_FUSION_VOXEL_SIZE", "0.02"))
57
  FUSION_MAX_POINTS = int(os.getenv("SIMAM3D_FUSION_MAX_POINTS", "150000"))
58
+ GAUSSIAN_MAX_POINTS = int(os.getenv("SIMAM3D_GAUSSIAN_MAX_POINTS", "20000"))
59
  DEPTH_PIPELINE = None
60
  DA3_MODEL = None
61
  PIPELINE_LOCK = threading.Lock()
 
427
  gaussians = getattr(prediction, "gaussians", None)
428
  if gaussians is None:
429
  return None
430
+ print("Simam3D direct Gaussian export: reading parameters", flush=True)
431
  means = _prediction_array(getattr(gaussians, "means", None))
432
  scales = _prediction_array(getattr(gaussians, "scales", None))
433
  rotations = _prediction_array(getattr(gaussians, "rotations", None))
434
  opacities = _prediction_array(getattr(gaussians, "opacities", None)).reshape(-1)
435
+ print(f"Simam3D direct Gaussian export: means={means.shape} scales={scales.shape}", flush=True)
436
  if means.ndim == 3 and means.shape[0] == 1:
437
  means = means[0]
438
  if scales.ndim == 3 and scales.shape[0] == 1:
 
453
  means, scales, rotations, opacities = means[keep], scales[keep], rotations[keep], opacities[keep]
454
  harmonics = getattr(gaussians, "harmonics", None)
455
  if harmonics is not None:
456
+ # Only the DC coefficient is needed for the portable PLY color field;
457
+ # avoid transferring the complete SH basis from GPU memory.
458
+ if hasattr(harmonics, "detach") and harmonics.ndim >= 3:
459
+ harmonics = harmonics[..., 0]
460
  harmonics = _prediction_array(harmonics)
461
  if harmonics.ndim == 4 and harmonics.shape[0] == 1:
462
  harmonics = harmonics[0]
463
+ if harmonics.ndim == 3 and harmonics.shape[0] == 1:
464
+ harmonics = harmonics[0]
465
  if keep is not None and harmonics.shape[0] == original_count:
466
  harmonics = harmonics[keep]
467
+ if harmonics.ndim == 2 and harmonics.shape[0] == len(means):
468
+ colors = np.clip((harmonics * 0.2820947918 + 0.5) * 255.0, 0, 255).astype(np.uint8)
 
469
  else:
470
  colors = np.full((len(means), 3), 180, dtype=np.uint8)
471
  else: