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

Runtime Error: Expected object of scalar type Long but got scalar type Byte for argument #2 'target' #8

Open
immkapoor opened this issue Oct 22, 2019 · 3 comments

Comments

@immkapoor
Copy link

Loading Dataset
Start training
Traceback (most recent call last):
File "train_cnn_single_frame.py", line 59, in
validate=True, resume=resume, use_cuda=cuda)
File "D:\Action Recognition\KTH Program\KTH-Action-Recognition-master\KTH-Action-Recognition-master\main\train_helper.py", line 109, in train
loss = criterion(outputs, labels)
File "C:\Users\Meghna\Anaconda\envs\tensorflow_env\lib\site-packages\torch\nn\modules\module.py", line 489, in call
result = self.forward(*input, **kwargs)
File "C:\Users\Meghna\Anaconda\envs\tensorflow_env\lib\site-packages\torch\nn\modules\loss.py", line 904, in forward
ignore_index=self.ignore_index, reduction=self.reduction)
File "C:\Users\Meghna\Anaconda\envs\tensorflow_env\lib\site-packages\torch\nn\functional.py", line 1970, in cross_entropy
return nll_loss(log_softmax(input, 1), target, weight, None, ignore_index, None, reduction)
File "C:\Users\Meghna\Anaconda\envs\tensorflow_env\lib\site-packages\torch\nn\functional.py", line 1790, in nll_loss
ret = torch._C._nn.nll_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index)
RuntimeError: Expected object of scalar type Long but got scalar type Byte for argument #2 'target'

@ashuezy
Copy link

ashuezy commented Nov 10, 2019

Add this line

labels = labels.long()

in the train method before calling criterion(....

@immkapoor
Copy link
Author

@ashuezy Hi, I tried adding this line yet I am getting same error.

@jaycelol10
Copy link

@ashuezy @vkhoi @immkapoor can you please tell me how u solved it guys ?

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