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

Jupyter Notebook (python version 3.9.0) PyTorch > RuntimeError: expected scalar type Long but found Int #2

Open
RamseyThomson opened this issue Mar 26, 2022 · 1 comment

Comments

@RamseyThomson
Copy link

In investigating CNNs, I have copied an online script into Jupyter Notebook (setup works fine) but:

defining the number of epochs

n_epochs = 25

empty list to store training losses

train_losses = []

empty list to store validation losses

val_losses = []

training the model

for epoch in range(n_epochs):
print('train for epoch:', epoch)
train(epoch)

At the first call to train(epoch) a runtime error is caused:

Line 2846 of ~\anaconda3\lib\site-packages\torch\nn\functional.py in cross_entropy(input, target, weight, size_average, ignore_index, reduce, reduction, label_smoothing)
results in > RuntimeError: expected scalar type Long but found Int
The above is called from line 1150 of ~\anaconda3\lib\site-packages\torch\nn\modules\loss.py in forward(self, input, target) which in turn is called from line 1102 of ~\anaconda3\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)

Should I report this to the supplier of the online CNN example or have I discovered a bug?

@RamseyThomson RamseyThomson changed the title Jupyter Notebook (python version 3.9.0) > RuntimeError: expected scalar type Long but found Int Jupyter Notebook (python version 3.9.0) PyTorch > RuntimeError: expected scalar type Long but found Int Mar 26, 2022
@7ENG1Z
Copy link

7ENG1Z commented Sep 19, 2023

HI,did you solve the problem?

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