a-PyTorch-Tutorial-to-Image-Captioning icon indicating copy to clipboard operation
a-PyTorch-Tutorial-to-Image-Captioning copied to clipboard

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

Open AndreSun98 opened this issue 3 years ago • 5 comments

When I run caption.py,I got the following error: Traceback (most recent call last): File "D:/2021/sjt/code/a-PyTorch-Tutorial-to-Image-Captioning-master/caption.py", line 217, in seq, alphas = caption_image_beam_search(encoder, decoder, args.img, word_map, args.beam_size) File "D:/2021/sjt/code/a-PyTorch-Tutorial-to-Image-Captioning-master/caption.py", line 113, in caption_image_beam_search seqs_alpha = torch.cat([seqs_alpha[prev_word_inds.long()], alpha[prev_word_inds].unsqueeze(1)], IndexError: tensors used as indices must be long, byte or bool tensors

AndreSun98 avatar Jun 05 '22 17:06 AndreSun98

I had the same problem

zhongchaotie avatar Jun 16 '22 09:06 zhongchaotie

I have the same problem. Have you solved it?

vernal0 avatar Jul 10 '22 05:07 vernal0

    prev_word_inds = top_k_words / vocab_size

You can try changing the "/" in the above code to "//".

HackInSouth avatar Jul 19 '22 02:07 HackInSouth

你好,解决了没

wenshihao1 avatar Jul 28 '23 05:07 wenshihao1

我也遇到了同样的问题,请问怎么解决

01620syf avatar Nov 27 '23 00:11 01620syf