Skip to content

Commit e4f78cd

Browse files
Improve PLY loading robustness and error handling (#150)
* Improve PLY loading robustness and error handling - Add support for PLY files with only DC components (no higher-order spherical harmonics) - Initialize higher-order harmonics to zero when only DC components are available - Add better error logging with full traceback in ply_to_usd.py script - Improve error messages for unexpected spherical harmonics data structure * Update threedgrut/model/model.py Co-authored-by: Qi Wu <[email protected]> --------- Co-authored-by: Qi Wu <[email protected]>
1 parent 65c1c5c commit e4f78cd

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

threedgrut/export/scripts/ply_to_usd.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ def main():
9898
logger.info(f"Successfully exported to {output_path}")
9999
except Exception as e:
100100
logger.error(f"Error processing PLY file: {e}")
101+
import traceback
102+
logger.error(f"Full traceback: {traceback.format_exc()}")
101103
sys.exit(1)
102104

103105

104106
if __name__ == "__main__":
105-
main()
107+
main()

threedgrut/model/model.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -685,12 +685,21 @@ def init_from_ply(self, mogt_path:str, init_model=True):
685685
extra_f_names = [p.name for p in plydata.elements[0].properties if p.name.startswith("f_rest_")]
686686
extra_f_names = sorted(extra_f_names, key = lambda x: int(x.split('_')[-1]))
687687
num_speculars = (self.max_n_features + 1) ** 2 - 1
688-
assert len(extra_f_names)==3*num_speculars
689-
mogt_specular = np.zeros((num_gaussians, len(extra_f_names)))
690-
for idx, attr_name in enumerate(extra_f_names):
691-
mogt_specular[:, idx] = np.asarray(plydata.elements[0][attr_name])
692-
mogt_specular = mogt_specular.reshape((num_gaussians,3,num_speculars))
693-
mogt_specular = mogt_specular.transpose(0, 2, 1).reshape((num_gaussians,num_speculars*3))
688+
expected_extra_f_count = 3 * num_speculars
689+
690+
mogt_specular = np.zeros((num_gaussians, expected_extra_f_count))
691+
if len(extra_f_names) == expected_extra_f_count:
692+
# Full spherical harmonics data available
693+
for idx, attr_name in enumerate(extra_f_names):
694+
mogt_specular[:, idx] = np.asarray(plydata.elements[0][attr_name])
695+
mogt_specular = mogt_specular.reshape((num_gaussians,3,num_speculars))
696+
mogt_specular = mogt_specular.transpose(0, 2, 1).reshape((num_gaussians,num_speculars*3))
697+
elif len(extra_f_names) == 0:
698+
# Only DC components available, create zero-filled higher-order harmonics
699+
logger.info(f"PLY file only contains DC components, initializing higher-order spherical harmonics to zero")
700+
else:
701+
# Partial data - this is unexpected
702+
raise ValueError(f"Unexpected number of f_rest_ properties: found {len(extra_f_names)}, expected {expected_extra_f_count} or 0")
694703

695704
scale_names = [p.name for p in plydata.elements[0].properties if p.name.startswith("scale_")]
696705
scale_names = sorted(scale_names, key = lambda x: int(x.split('_')[-1]))

0 commit comments

Comments
 (0)