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

Caption generation error

Open nattari opened this issue 6 years ago • 1 comments

After training, when I use the model to generate captions. It starts giving me the below error: File "caption.py", line 215, in <module> seq, alphas = caption_image_beam_search(encoder, decoder, args.img, word_map, args.beam_size) File "caption.py", line 44, in caption_image_beam_search image = transform(img) # (3, 256, 256) File "/home/anaconda3/lib/python3.6/site-packages/torchvision/transforms/transforms.py", line 60, in __call__ img = t(img) File "/home/anaconda3/lib/python3.6/site-packages/torchvision/transforms/transforms.py", line 163, in __call__ return F.normalize(tensor, self.mean, self.std, self.inplace) File "/home/anaconda3/lib/python3.6/site-packages/torchvision/transforms/functional.py", line 208, in normalize tensor.sub_(mean[:, None, None]).div_(std[:, None, None]) RuntimeError: expected type torch.cuda.FloatTensor but got torch.FloatTensor

The img variable seems to be of the correct type. I am new to pytorch, would be helpful if you could provide your insights.

nattari avatar Apr 23 '19 12:04 nattari

我知道怎么解决了...你可以这样做:

img = torch.FloatTensor(img)

image = transform(img).to(device)  # (3, 256, 256)

mymuli avatar Apr 23 '19 14:04 mymuli