@@ -568,33 +568,28 @@ def main(self) -> None:
568
568
map_to_tensors ["ny" ] = np .zeros (n , dtype = np .float32 )
569
569
map_to_tensors ["nz" ] = np .zeros (n , dtype = np .float32 )
570
570
571
- if model .config .sh_degree > 0 :
571
+ if self .ply_color_mode == "rgb" :
572
+ colors = torch .clamp (model .colors .clone (), 0.0 , 1.0 ).data .cpu ().numpy ()
573
+ colors = (colors * 255 ).astype (np .uint8 )
574
+ map_to_tensors ["red" ] = colors [:, 0 ]
575
+ map_to_tensors ["green" ] = colors [:, 1 ]
576
+ map_to_tensors ["blue" ] = colors [:, 2 ]
577
+ elif self .ply_color_mode == "sh_coeffs" :
572
578
shs_0 = model .shs_0 .contiguous ().cpu ().numpy ()
573
579
for i in range (shs_0 .shape [1 ]):
574
580
map_to_tensors [f"f_dc_{ i } " ] = shs_0 [:, i , None ]
575
581
582
+ if model .config .sh_degree > 0 :
576
583
if self .ply_color_mode == "rgb" :
577
584
CONSOLE .print (
578
- "Warning: model has higher level of spherical harmonics, option ply_color_mode is ignored ."
585
+ "Warning: model has higher level of spherical harmonics, ignoring them and only export rgb ."
579
586
)
580
- # transpose(1, 2) was needed to match the sh order in Inria version
581
- shs_rest = model .shs_rest .transpose (1 , 2 ).contiguous ().cpu ().numpy ()
582
- shs_rest = shs_rest .reshape ((n , - 1 ))
583
- for i in range (shs_rest .shape [- 1 ]):
584
- map_to_tensors [f"f_rest_{ i } " ] = shs_rest [:, i , None ]
585
- else :
586
- if self .ply_color_mode == "sh_coeffs" :
587
- shs_0 = model .shs_0 .contiguous ().cpu ().numpy ()
588
- for i in range (shs_0 .shape [1 ]):
589
- map_to_tensors [f"f_dc_{ i } " ] = RGB2SH (
590
- torch .clamp (model .colors .clone (), 0.0 , 1.0 ).data .cpu ().numpy ()
591
- )[:, i ]
592
- elif self .ply_color_mode == "rgb" :
593
- colors = torch .clamp (model .colors .clone (), 0.0 , 1.0 ).data .cpu ().numpy ()
594
- colors = (colors * 255 ).astype (np .uint8 )
595
- map_to_tensors ["red" ] = colors [:, 0 ]
596
- map_to_tensors ["green" ] = colors [:, 1 ]
597
- map_to_tensors ["blue" ] = colors [:, 2 ]
587
+ elif self .ply_color_mode == "sh_coeffs" :
588
+ # transpose(1, 2) was needed to match the sh order in Inria version
589
+ shs_rest = model .shs_rest .transpose (1 , 2 ).contiguous ().cpu ().numpy ()
590
+ shs_rest = shs_rest .reshape ((n , - 1 ))
591
+ for i in range (shs_rest .shape [- 1 ]):
592
+ map_to_tensors [f"f_rest_{ i } " ] = shs_rest [:, i , None ]
598
593
599
594
map_to_tensors ["opacity" ] = model .opacities .data .cpu ().numpy ()
600
595
0 commit comments