rpg_e2vid icon indicating copy to clipboard operation
rpg_e2vid copied to clipboard

RuntimeError: Expected object of scalar type Long but got scalar type Float for argument #3 'index' in call to _th_index_add_

Open gethubwy opened this issue 5 years ago • 7 comments

When I run the code on GPU,I got the error blew: Traceback (most recent call last): File "run_reconstruction.py", line 107, in device=device) File "/home/wy/rpg_e2vid-master/utils/inference_utils.py", line 533, in events_to_voxel_grid_pytorch source=vals_left[valid_indices]) RuntimeError: Expected object of scalar type Long but got scalar type Float for argument #3 'index' in call to th_index_add

I find that the code is : voxel_grid.index_add_(dim=0, index=xs[valid_indices] + ys[valid_indices] * width + tis_long[valid_indices] * width * height, source=vals_left[valid_indices])

thanks in advance.

gethubwy avatar Dec 30 '19 13:12 gethubwy

Hello, Which version of PyTorch are you using? I seem to remember there was a slight API change in PyTorch that caused this issue in older versions.

supitalp avatar Jan 23 '20 07:01 supitalp

facing the same error with torch==1.3.1

shiba24 avatar Feb 09 '20 01:02 shiba24

I am also facing with the same error with torch==1.4.0

vikinglee16 avatar Feb 14 '20 12:02 vikinglee16

Thanks for the feedback. I don't have access to a machine with a GPU to reproduce this now. Does the following change fix the error?

voxel_grid.index_add_(
                      dim=0,
                      index=(xs[valid_indices] + ys[valid_indices] * width + tis_long[valid_indices] * width * height).long(),
                      source=vals_left[valid_indices]
)

supitalp avatar Feb 14 '20 12:02 supitalp

It runs on jetson tx2 with the change (torch version 1.3.0).

On Fri, Feb 14, 2020 at 1:28 PM supitalp [email protected] wrote:

Thanks for the feedback. I don't have access to a machine with a GPU to reproduce this now. Does the following change fix the error?

voxel_grid.index_add_( dim=0, index=(xs[valid_indices] + ys[valid_indices] * width + tis_long[valid_indices] * width * height).long(), source=vals_left[valid_indices] )

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/uzh-rpg/rpg_e2vid/issues/5?email_source=notifications&email_token=ADAJM2BDK2FG6HKON6ERNYDRC2E5RA5CNFSM4KBMOFQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELY3ZII#issuecomment-586267809, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADAJM2FNTY6SBGIOHVB5CRLRC2E5RANCNFSM4KBMOFQQ .

saiyaswanth97 avatar Feb 14 '20 12:02 saiyaswanth97

For GPU environment,

            voxel_grid.index_add_(dim=0,
                                  index=(xs[valid_indices] + ys[valid_indices]
                                  * width + tis_long[valid_indices] * width * height).type(torch.cuda.LongTensor),
                                  source=vals_left[valid_indices])

should fix this.

shiba24 avatar Feb 16 '20 08:02 shiba24

Also fixed in https://github.com/uzh-rpg/rpg_e2vid/pull/11

Tobias-Fischer avatar Apr 15 '20 03:04 Tobias-Fischer