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

Please help me with the error:RuntimeError: Expected target size [32, 9490], got [32, 51] #195

Open
2068439567 opened this issue May 22, 2023 · 1 comment

Comments

@2068439567
Copy link

Traceback (most recent call last):
File "D:\majority_design\image_caption\ic_train.py", line 322, in
main()
File "D:\majority_design\image_caption\ic_train.py", line 116, in main
train(train_loader=train_loader,
File "D:\majority_design\image_caption\ic_train.py", line 180, in train
loss = criterion(scores, targets)
File "D:\anaconda3\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "D:\anaconda3\envs\pytorch\lib\site-packages\torch\nn\modules\loss.py", line 1164, in forward
return F.cross_entropy(input, target, weight=self.weight,
File "D:\anaconda3\envs\pytorch\lib\site-packages\torch\nn\functional.py", line 3014, in cross_entropy
return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index, label_smoothing)
RuntimeError: Expected target size [32, 9490], got [32, 51]

When i debug the code, i found scores's size is (32, 16, 9490), but targets's size is (32, 51)

i am just a rookie of DL, please help me!!! Thank you very much!!!

@Le-up
Copy link

Le-up commented Mar 3, 2024

I also encountered the same problem. Have you solved it?

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

2 participants