SuGaR icon indicating copy to clipboard operation
SuGaR copied to clipboard

IndexError: tensors used as indices must be long, byte or bool tensors

Open kuaiqushangzixiba opened this issue 2 years ago • 2 comments

Number of gaussians left: 185091 Opacities min/max/mean: tensor(0.5000, device='cuda:0') tensor(1., device='cuda:0') tensor(0.9852, device='cuda:0') Quantile 0.0: 0.5000418424606323 Quantile 0.1: 0.989769458770752 Quantile 0.2: 0.9993429780006409 Quantile 0.3: 0.99977046251297 Quantile 0.4: 0.9998769760131836 Quantile 0.5: 0.99992835521698 Quantile 0.6: 0.9999568462371826 Quantile 0.7: 0.9999749660491943 Quantile 0.8: 0.9999866485595703 Quantile 0.9: 0.9999943971633911 Traceback (most recent call last): File "/data/SuGaR-main/train.py", line 141, in coarse_mesh_path = extract_mesh_from_coarse_sugar(coarse_mesh_args)[0] File "/data/SuGaR-main/sugar_extractors/coarse_mesh.py", line 209, in extract_mesh_from_coarse_sugar mesh = sugar.mesh File "/data/SuGaR-main/sugar_scene/sugar_model.py", line 497, in mesh maps=SH2RGB(self.texture_features[..., 0, :][None]), #texture_img[None]), File "/data/SuGaR-main/sugar_scene/sugar_model.py", line 492, in texture_features return self.sh_coordinates[self.point_idx_per_pixel] IndexError: tensors used as indices must be long, byte or bool tensors

kuaiqushangzixiba avatar Jan 08 '24 04:01 kuaiqushangzixiba

Hello @kuaiqushangzixiba,

May I ask more details about your error, and the commands you used?

Looking at your error, self.point_idx_per_pixel may be empty (maybe because of a None somewhere), which could produce your IndexError. Maybe the foreground of your scene is empty, or something like that.

May I ask, what does your scene look like?

Anttwo avatar Jan 12 '24 05:01 Anttwo

@kuaiqushangzixiba

I encountered the same issue. However, in my case, self.point_idx_per_pixel was not empty. The problem was resolved by changing self.sh_coordinates[self.point_idx_per_pixel] to self.sh_coordinates[self.point_idx_per_pixel.long()].

In sugar_model.py, self._surface_mesh_faces is also used as indices in 4 lines, for instance in:

faces_verts = self._points[self._surface_mesh_faces]  # n_faces, 3, n_coords

You should replace these with self._surface_mesh_faces.long().

@Anttwo Thank you for your excellent work. The issue may be related to the version of PyTorch being used. In my case, I'm using PyTorch version 1.13.1+cu117.

sanosano avatar Jan 15 '24 19:01 sanosano