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

AttributeError: 'PackedSequence' object has no attribute 'size' #176

Open
gzzyyxh opened this issue Jun 7, 2022 · 3 comments
Open

AttributeError: 'PackedSequence' object has no attribute 'size' #176

gzzyyxh opened this issue Jun 7, 2022 · 3 comments

Comments

@gzzyyxh
Copy link

gzzyyxh commented Jun 7, 2022

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.

@OrangeSodahub
Copy link

OrangeSodahub commented Jul 24, 2022

@gzzyyxh Hi, that's absolutely an easy question. Just replace size with batch_sizes.
Is it odd?

@MCA-eng
Copy link

MCA-eng commented Oct 15, 2022

Traceback (most recent call last):
File "train.py", line 328, in
main()
File "train.py", line 116, in main
epoch=epoch)
File "train.py", line 204, in train
top5 = accuracy(scores, targets, 5)
File "/workspace/data/a-PyTorch-Tutorial-to-Image-Captioning/utils.py", line 286, in accuracy
batch_size = targets.batch_sizes(0)
TypeError: 'Tensor' object is not callable

Getting this error with the suggested change, can u pls tell me how to make it work

@OrangeSodahub
Copy link

OrangeSodahub commented Jan 2, 2023

@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.

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