a-PyTorch-Tutorial-to-Image-Captioning
a-PyTorch-Tutorial-to-Image-Captioning copied to clipboard
AttributeError: 'PackedSequence' object has no attribute 'size'
Hello, when python train.py was executed I faced an odd error:
Traceback (most recent call last):
File "D:\a-PyTorch-Tutorial-to-Image-Captioning\train.py", line 332, in <module>
main()
File "D:\a-PyTorch-Tutorial-to-Image-Captioning\train.py", line 111, in main
train(train_loader=train_loader,
File "D:\a-PyTorch-Tutorial-to-Image-Captioning\train.py", line 207, in train
top5 = accuracy(scores, targets, 5)
File "D:\a-PyTorch-Tutorial-to-Image-Captioning\utils.py", line 283, in accuracy
batch_size = targets.size(0)
AttributeError: 'PackedSequence' object has no attribute 'size'
So, what can I do? Thank you.
@gzzyyxh Hi, that's absolutely an easy question. Just replace size with batch_sizes.
Is it odd?
Traceback (most recent call last):
File "train.py", line 328, in
Getting this error with the suggested change, can u pls tell me how to make it work
@MCA-eng According to the TypeError message you can know targets.batch_sizes is of Tensor type, it cannot be called through () like functions, you should try [] to index.