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

RuntimeError: Expected object of scalar type Long but got scalar type Int for argument #3 'index' #30

Closed
haofengsiji opened this issue Sep 8, 2019 · 2 comments

Comments

@haofengsiji
Copy link

I have already tried my best to solve this problem.
But I failed, can anyone give me some suggestions?

(py36) E:\GitHub\LearningToCompare_FSL>F:/Anaconda3/envs/py36/python.exe e:/GitHub/LearningToCompare_FSL/omniglot/omniglot_train_few_shot.py
init data folders
init neural networks
Training...
F:\Anaconda3\envs\py36\lib\site-packages\torch\nn\functional.py:1386: UserWarning: nn.functional.sigmoid is deprecated. Use torch.sigmoid instead.
  warnings.warn("nn.functional.sigmoid is deprecated. Use torch.sigmoid instead.")
Traceback (most recent call last):
  File "e:/GitHub/LearningToCompare_FSL/omniglot/omniglot_train_few_shot.py", line 264, in <module>
    main()
  File "e:/GitHub/LearningToCompare_FSL/omniglot/omniglot_train_few_shot.py", line 188, in main
    one_hot_labels = Variable(torch.zeros(BATCH_NUM_PER_CLASS*CLASS_NUM, CLASS_NUM).scatter_(1, batch_labels.view(-1,1), 1).cuda(GPU))
RuntimeError: Expected object of scalar type Long but got scalar type Int for argument #3 'index'
@haofengsiji haofengsiji changed the title one_hot_labels = Variable(torch.zeros(BATCH_NUM_PER_CLASS*CLASS_NUM, CLASS_NUM).scatter_(1, batch_labels.view(-1,1), 1).cuda(GPU)) RuntimeError: Expected object of scalar type Long but got scalar type Int for argument #3 'index' RuntimeError: Expected object of scalar type Long but got scalar type Int for argument #3 'index' Sep 8, 2019
@yitianhoulai
Copy link

The 3rd argument index should be batch_labels.view(-1,1) and you just need to change it to

one_hot_labels = Variable(torch.zeros(BATCH_NUM_PER_CLASS*CLASS_NUM, CLASS_NUM).scatter(1, batch_labels.view(-1,1).long(), 1).cuda(GPU))_

@haofengsiji
Copy link
Author

py27 may also solve this problem, but still, thanks

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