Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

seqs = torch.cuda.FloatTensor(torch.cat([seqs[prev_word_inds], next_word_inds.unsqueeze(1)], dim=1))# (s, step+1) IndexError: tensors used as indices must be long, byte or bool tensors #138

Open
KhaaQ opened this issue Dec 9, 2020 · 2 comments

Comments

@KhaaQ
Copy link

KhaaQ commented Dec 9, 2020

While running eval.py, this error occurs. Any help to change the type of tensor. I tried different types of tensor types but still same error occur.

EVALUATING AT BEAM SIZE 1: 0%| | 0/25000 [00:00<?, ?it/s]k previous words tensor([[9488]], device='cuda:0')
seq tensor([[9488]], device='cuda:0')
EVALUATING AT BEAM SIZE 1: 0%| | 0/25000 [00:00<?, ?it/s]
Traceback (most recent call last):
File "/home/Documents/Pytorch_IC_srgv_Nov5/a-PyTorch-Tutorial-to-Image-Captioning-master/eval.py", line 182, in
print("\nBLEU-4 score @ beam size of %d is %.4f." % (beam_size, evaluate(beam_size)))
File "/home/Documents/Pytorch_IC_srgv_Nov5/a-PyTorch-Tutorial-to-Image-Captioning-master/eval.py", line 130, in evaluate

seqs = torch.cuda.FloatTensor(torch.cat([seqs[prev_word_inds], next_word_inds.unsqueeze(1)], dim=1))# (s, step+1)
IndexError: tensors used as indices must be long, byte or bool tensors

@khaxis
Copy link

khaxis commented Dec 11, 2020

Try to add .long() to a couple of tensors to transform them:
seqs = torch.cat([seqs[prev_word_inds.long()], next_word_inds.unsqueeze(1)], dim=1) # (s, step+1)

This line and a few others below.

@BeBeYourLove
Copy link

I have the same problem.I solved it when I saw your suggestion and thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants